"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatUnit = exports.format = void 0;
const locale_1 = require("./locale");
const size_js_1 = require("./size.js");
function format(size, options) {
    const chunks = size_js_1.SizeChunks.slice().reverse();
    let chunkPow = 6;
    let str;
    const bytes = size_js_1.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;
}
exports.format = format;
function formatUnit(a, long = false, localeId = 'fr-FR') {
    const i = long ? 1 : 0;
    return (0, locale_1.getLocale)(localeId)[a][i];
}
exports.formatUnit = formatUnit;
