{
  "version": 3,
  "sources": ["../src/index.ts"],
  "sourcesContent": ["export interface Options {\n    /**\n     * Include plus sign for positive numbers. If the difference is exactly\n     * zero a space character will be prepended instead for better alignment.\n     * @default false\n     */\n    signed?:boolean\n\n    /**\n     * Format the number as bits instead of bytes. This can be useful when,\n     * for example, referring to bit rate.\n     * @default false\n     */\n    bits?:boolean\n\n    /**\n     * Format the number using the Binary Prefix instead of the SI Prefix.\n     * This can be useful for presenting memory amounts.\n     * However, this should not be used for presenting file sizes.\n     * @default false\n     */\n    binary?:boolean\n\n    /**\n     * The minimum number of fraction digits to display.\n     * If neither `minimumFractionDigits` or `maximumFractionDigits` are set,\n     * the default behavior is to round to 3 significant digits.\n     */\n    minimumFractionDigits?:number\n\n    /**\n     * The maximum number of fraction digits to display.\n     * If neither `minimumFractionDigits` or `maximumFractionDigits` are set,\n     * the default behavior is to round to 3 significant digits.\n     */\n    maximumFractionDigits?:number\n\n    /**\n     * Put a space between the number and unit.\n     * @default true\n     */\n    space?:boolean\n\n    /**\n     * Use a non-breaking space between the number and unit.\n     * @default false\n     */\n    nonBreakingSpace?:boolean\n\n    /**\n     * The locale to use for number formatting.\n     * - If `true`, the system default locale is used.\n     * - If a string, the value is expected to be a locale-key\n     *   (for example: `de`).\n     * - If an array of strings, the first supported locale will be used.\n     * @default false\n     */\n    locale?:string|string[]|boolean\n\n    /**\n     * Fixed width for the result string. The string will be padded with spaces\n     * on the left if needed.\n     */\n    fixedWidth?:number\n}\n\nconst BYTE_UNITS = [\n    'B',\n    'kB',\n    'MB',\n    'GB',\n    'TB',\n    'PB',\n    'EB',\n    'ZB',\n    'YB',\n] as const\n\nconst BIBYTE_UNITS = [\n    'B',\n    'KiB',\n    'MiB',\n    'GiB',\n    'TiB',\n    'PiB',\n    'EiB',\n    'ZiB',\n    'YiB',\n] as const\n\nconst BIT_UNITS = [\n    'b',\n    'kbit',\n    'Mbit',\n    'Gbit',\n    'Tbit',\n    'Pbit',\n    'Ebit',\n    'Zbit',\n    'Ybit',\n] as const\n\nconst BIBIT_UNITS = [\n    'b',\n    'kibit',\n    'Mibit',\n    'Gibit',\n    'Tibit',\n    'Pibit',\n    'Eibit',\n    'Zibit',\n    'Yibit',\n] as const\n\n/**\n * Formats the given number using `Number#toLocaleString`.\n *   - If locale is a string, the value is expected to be a locale-key\n *     (for example: `de`).\n *   - If locale is true, the system default locale is used for translation.\n *   - If no value for locale is specified, the number is returned unmodified.\n */\nconst toLocaleString = (\n    number:number|bigint,\n    locale?:string|string[]|boolean,\n    options?:Intl.NumberFormatOptions\n):string => {\n    let result = number.toString()\n    if (typeof number === 'bigint') {\n        // bigint.toLocaleString doesn't accept options in TypeScript's\n        // type definitions\n        if (typeof locale === 'string' || Array.isArray(locale)) {\n            result = number.toLocaleString(locale)\n        } else if (locale === true) {\n            result = number.toLocaleString()\n        }\n    } else {\n        // number type supports full locale string options\n        if (typeof locale === 'string' || Array.isArray(locale)) {\n            result = number.toLocaleString(locale, options)\n        } else if (locale === true || options !== undefined) {\n            result = number.toLocaleString(undefined, options)\n        }\n    }\n\n    return result\n}\n\nconst log10 = (numberOrBigInt:number|bigint):number => {\n    if (typeof numberOrBigInt === 'number') {\n        return Math.log10(numberOrBigInt)\n    }\n\n    const string = numberOrBigInt.toString(10)\n\n    return string.length + Math.log10(Number(`0.${string.slice(0, 15)}`))\n}\n\nconst log = (numberOrBigInt:number|bigint):number => {\n    if (typeof numberOrBigInt === 'number') {\n        return Math.log(numberOrBigInt)\n    }\n\n    return log10(numberOrBigInt) * Math.log(10)\n}\n\nconst divide = (numberOrBigInt:number|bigint, divisor:number):number => {\n    if (typeof numberOrBigInt === 'number') {\n        return numberOrBigInt / divisor\n    }\n\n    const integerPart = numberOrBigInt / BigInt(divisor)\n    const remainder = numberOrBigInt % BigInt(divisor)\n    return Number(integerPart) + (Number(remainder) / divisor)\n}\n\nconst applyFixedWidth = (result:string, fixedWidth?:number):string => {\n    if (fixedWidth === undefined) {\n        return result\n    }\n\n    if (\n        typeof fixedWidth !== 'number' ||\n        !Number.isSafeInteger(fixedWidth) ||\n        fixedWidth < 0\n    ) {\n        throw new TypeError('Expected fixedWidth to be a non-negative ' +\n            `integer, got ${typeof fixedWidth}: ${fixedWidth}`)\n    }\n\n    if (fixedWidth === 0) {\n        return result\n    }\n\n    return result.length < fixedWidth ? result.padStart(fixedWidth, ' ') : result\n}\n\nfunction buildLocaleOptions (\n    options:Options\n):Intl.NumberFormatOptions|undefined {\n    const { minimumFractionDigits, maximumFractionDigits } = options\n\n    if (\n        minimumFractionDigits === undefined &&\n        maximumFractionDigits === undefined\n    ) {\n        return undefined\n    }\n\n    return {\n        ...(minimumFractionDigits !== undefined && { minimumFractionDigits }),\n        ...(maximumFractionDigits !== undefined && { maximumFractionDigits }),\n        roundingMode: 'trunc',\n    } as Intl.NumberFormatOptions\n}\n\nexport function humanBytes (\n    num:number|bigint,\n    options?:Options\n):string {\n    if (typeof num !== 'bigint' && !Number.isFinite(num)) {\n        throw new TypeError(\n            `Expected a finite number, got ${typeof num}: ${num}`\n        )\n    }\n\n    const mergedOptions:Required<Pick<\n        Options, 'bits'|'binary'|'space'|'nonBreakingSpace'\n    >> & Options = {\n        bits: false,\n        binary: false,\n        space: true,\n        nonBreakingSpace: false,\n        ...options,\n    }\n\n    const UNITS = mergedOptions.bits ?\n        (mergedOptions.binary ? BIBIT_UNITS : BIT_UNITS) :\n        (mergedOptions.binary ? BIBYTE_UNITS : BYTE_UNITS)\n\n    const separator = mergedOptions.space ?\n        (mergedOptions.nonBreakingSpace ? '\\u00A0' : ' ') :\n        ''\n\n    // Handle signed zero case\n    const isZero = typeof num === 'number' ? num === 0 : num === 0n\n    if (mergedOptions.signed && isZero) {\n        const result = ` 0${separator}${UNITS[0]}`\n        return applyFixedWidth(result, mergedOptions.fixedWidth)\n    }\n\n    const isNegative = num < 0\n    const prefix = isNegative ? '-' : (mergedOptions.signed ? '+' : '')\n\n    if (isNegative) {\n        num = -num\n    }\n\n    const localeOptions = buildLocaleOptions(mergedOptions)\n    let result: string\n\n    if (num < 1) {\n        const numberString = toLocaleString(\n            num,\n            mergedOptions.locale,\n            localeOptions\n        )\n        result = prefix + numberString + separator + UNITS[0]\n    } else {\n        const n = (mergedOptions.binary ?\n            log(num) / Math.log(1024) :\n            log10(num) / 3)\n        const exponent = Math.min(Math.floor(n), UNITS.length - 1)\n        let dividedNumber:number|string = divide(\n            num,\n            (mergedOptions.binary ? 1024 : 1000) ** exponent\n        )\n\n        if (!localeOptions) {\n            const minPrecision = Math.max(\n                3,\n                Math.floor(dividedNumber).toString().length\n            )\n            dividedNumber = dividedNumber.toPrecision(minPrecision)\n        }\n\n        const numberString = toLocaleString(\n            Number(dividedNumber),\n            mergedOptions.locale,\n            localeOptions\n        )\n        const unit = UNITS[exponent]\n        result = prefix + numberString + separator + unit\n    }\n\n    return applyFixedWidth(result, mergedOptions.fixedWidth)\n}\n\nexport default humanBytes\n"],
  "mappings": "4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,eAAAC,IAAA,eAAAC,EAAAJ,GAkEA,MAAMK,EAAa,CACf,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,IACJ,EAEMC,EAAe,CACjB,IACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,KACJ,EAEMC,EAAY,CACd,IACA,OACA,OACA,OACA,OACA,OACA,OACA,OACA,MACJ,EAEMC,EAAc,CAChB,IACA,QACA,QACA,QACA,QACA,QACA,QACA,QACA,OACJ,EASMC,EAAiBC,EAAA,CACnBC,EACAC,EACAC,IACQ,CACR,IAAIC,EAASH,EAAO,SAAS,EAC7B,OAAI,OAAOA,GAAW,SAGd,OAAOC,GAAW,UAAY,MAAM,QAAQA,CAAM,EAClDE,EAASH,EAAO,eAAeC,CAAM,EAC9BA,IAAW,KAClBE,EAASH,EAAO,eAAe,GAI/B,OAAOC,GAAW,UAAY,MAAM,QAAQA,CAAM,EAClDE,EAASH,EAAO,eAAeC,EAAQC,CAAO,GACvCD,IAAW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C,CAAY,CAC1D,CAEA,MAAMJ,EAAe5B,EACjB,OAAO+B,CAAa,EACpBV,EAAc,OACdM,CACJ,EACMM,EAAOX,EAAMQ,CAAQ,EAC3BzB,EAASqB,EAASE,EAAeL,EAAYU,CACjD,CAEA,OAAOnB,EAAgBT,EAAQgB,EAAc,UAAU,CAC3D,CAhFgBpB,EAAAkB,EAAA,cAkFhB,IAAOe,EAAQf",
  "names": ["index_exports", "__export", "index_default", "humanBytes", "__toCommonJS", "BYTE_UNITS", "BIBYTE_UNITS", "BIT_UNITS", "BIBIT_UNITS", "toLocaleString", "__name", "number", "locale", "options", "result", "log10", "numberOrBigInt", "string", "log", "divide", "divisor", "integerPart", "remainder", "applyFixedWidth", "fixedWidth", "buildLocaleOptions", "minimumFractionDigits", "maximumFractionDigits", "humanBytes", "num", "mergedOptions", "UNITS", "separator", "isZero", "isNegative", "prefix", "localeOptions", "numberString", "n", "exponent", "dividedNumber", "minPrecision", "unit", "index_default"]
}
