import { getLocale } from './locale';
import { Size, SizeChunks } from './size.js';
export function format(size, options) {
    const chunks = SizeChunks.slice().reverse();
    let chunkPow = 6;
    let str;
    const bytes = Size.from(size).bytes;
    let pow;
    let factor;
    if (!options) {
        options = {};
    }
    chunks.every((u, i) => {
        pow = Math.pow(1024, chunkPow - i);
        factor = bytes / pow;
        if (factor >= 1) {
            str = Math.round(factor) + (options.space ? ' ' : '') + formatUnit(u);
            return false;
        }
        return true;
    });
    return str;
}
export function formatUnit(a, long = false, localeId = 'fr-FR') {
    const i = long ? 1 : 0;
    return getLocale(localeId)[a][i];
}
