From 4229ca720d52522f78d218f59f739eec62b18a0a Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 19:47:47 -0400 Subject: [PATCH 01/11] refactor: extract delegate functions from filesize for better SRP --- dist/filesize.cjs | 247 +++++++++++++++++++++++++---------- dist/filesize.js | 247 +++++++++++++++++++++++++---------- dist/filesize.min.js | 2 +- dist/filesize.min.js.map | 2 +- dist/filesize.umd.js | 247 +++++++++++++++++++++++++---------- dist/filesize.umd.min.js | 2 +- dist/filesize.umd.min.js.map | 2 +- src/filesize.js | 123 ++++++----------- src/helpers.js | 150 +++++++++++++++++++++ types/helpers.d.ts | 113 ++++++++++++++++ 10 files changed, 838 insertions(+), 297 deletions(-) diff --git a/dist/filesize.cjs b/dist/filesize.cjs index b28dce9..f10c602 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -283,6 +283,148 @@ function applyNumberFormatting(value, locale, localeOptions, separator, pad, rou return result; } +/** + * Calculates exponent from the input value using pre-computed log values and clamps to supported range + * Also adjusts precision when exponent exceeds the lookup table bounds + * @param {number} num - Input file size in bytes + * @param {number} e - Current exponent value + * @param {number} exponent - Original user-provided exponent option (-1 for auto) + * @param {boolean} isDecimal - Whether to use decimal (SI) base + * @param {number} precision - Current precision value (modified when e > 8) + * @returns {Object} Object with computed e value and possibly adjusted precision + */ +function calculateExponent(num, e, exponent, isDecimal, precision) { + if (e === -1 || isNaN(exponent)) { + e = isDecimal + ? Math.floor(Math.log(num) / LOG_10_1000) + : Math.floor(Math.log(num) / LOG_2_1024); + if (e < 0) { + e = 0; + } + } + + if (e > 8) { + if (precision > 0) { + precision += 8 - e; + } + e = 8; + } + + return { e, precision }; +} + +/** + * Applies rounding to the raw calculated value and handles auto-increment ceiling + * @param {number} val - Raw value before rounding + * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC) + * @param {number} e - Current exponent value + * @param {number} round - Number of decimal places + * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil) + * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN) + * @returns {Object} Object with rounded value and possibly incremented exponent + */ +function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { + const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; + let r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; + + if (r === ceil && e < 8 && autoExponent) { + r = 1; + e++; + } + + return { value: r, e }; +} + +/** + * Resolves the unit symbol for the given standard, bits mode, and exponent + * Handles SI standard special case where exponent 1 always uses "kB" or "kbit" + * @param {string} actualStandard - The resolved standard (iec, jedec) + * @param {boolean} bits - Whether formatting bit values + * @param {number} e - Current exponent index + * @param {boolean} isDecimal - Whether using decimal (SI) base + * @returns {string} The resolved unit symbol string + */ +function resolveSymbol(actualStandard, bits, e, isDecimal) { + const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; + return isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; +} + +/** + * Decorates the result: applies negation, custom symbols, number formatting, and full form names + * Mutates the result array in-place for both value (index 0) and symbol (index 1) + * @param {Array} result - Result array with numeric value at [0] and string symbol at [1] + * @param {boolean} neg - Whether the original input was negative + * @param {Object} symbols - Custom symbol override map + * @param {string|boolean} locale - Locale string for formatting + * @param {Object} localeOptions - Additional locale formatting options + * @param {string} separator - Custom decimal separator + * @param {boolean} pad - Whether zero-pad decimals + * @param {number} round - Target decimal count for padding + * @param {boolean} full - Whether to use full unit names + * @param {Array} fullforms - Custom full unit name overrides + * @param {string} actualStandard - Unit standard for full form lookup + * @param {number} e - Current exponent index + * @param {boolean} bits - Whether formatting bit values + * @returns {void} Mutates result array in place + */ +function decorateResult( + result, + neg, + symbols, + locale, + localeOptions, + separator, + pad, + round, + full, + fullforms, + actualStandard, + e, + bits, +) { + if (neg) { + result[0] = -result[0]; + } + + if (symbols[result[1]]) { + result[1] = symbols[result[1]]; + } + + result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); + + if (full) { + result[1] = + fullforms[e] || + STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); + } +} + +/** + * Formats the computed result array into the requested output type + * @param {Array} result - Result array with formatted value at [0] and symbol at [1] + * @param {number} e - Current exponent + * @param {string} u - Original resolved symbol (before custom override) + * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO) + * @param {string} spacer - String separator between value and unit + * @returns {string|Array|Object|number} Formatted result in requested type + */ +function formatOutput(result, e, u, output, spacer) { + if (output === ARRAY) { + return result; + } + + if (output === OBJECT) { + return { + value: result[0], + symbol: result[1], + exponent: e, + unit: u, + }; + } + + return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); +} + /** * Converts a file size in bytes to a human-readable string with appropriate units * @param {number|string|bigint} arg - The file size in bytes to convert @@ -337,7 +479,6 @@ function filesize( val = 0, u = EMPTY; - // Optimized base & standard configuration lookup const { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base); const full = fullform === true, @@ -352,12 +493,10 @@ function filesize( throw new TypeError(INVALID_ROUND); } - // Flipping a negative number to determine the size if (neg) { num = -num; } - // Fast path for zero if (num === 0) { return handleZeroValue( precision, @@ -371,31 +510,21 @@ function filesize( ); } - // Optimized exponent calculation using pre-computed log values - if (e === -1 || isNaN(e)) { - e = isDecimal - ? Math.floor(Math.log(num) / LOG_10_1000) - : Math.floor(Math.log(num) / LOG_2_1024); - if (e < 0) { - e = 0; - } - } - - // Exceeding supported length, time to reduce & multiply - if (e > 8) { - if (precision > 0) { - precision += 8 - e; - } - e = 8; - } - + // Exponent calculation + clamp + precision adjustment + const { e: calculatedE, precision: precisionAdjusted } = calculateExponent( + num, + e, + exponent, + isDecimal, + precision, + ); + e = calculatedE; const autoExponent = exponent === -1 || isNaN(exponent); if (output === EXPONENT) { return e; } - // Calculate value with optimized lookup and bits handling const { result: valueResult, e: valueExponent } = calculateOptimizedValue( num, e, @@ -407,20 +536,16 @@ function filesize( val = valueResult; e = valueExponent; - // Optimize rounding calculation - const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; - result[0] = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; - - if (result[0] === ceil && e < 8 && autoExponent) { - result[0] = 1; - e++; - } + // Rounding + auto-increment ceiling + const rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent); + result[0] = rounded.value; + e = rounded.e; - // Apply precision handling - if (precision > 0) { + // Precision handling + if (precisionAdjusted > 0) { const precisionResult = applyPrecisionHandling( result[0], - precision, + precisionAdjusted, e, num, isDecimal, @@ -434,44 +559,26 @@ function filesize( e = precisionResult.e; } - // Cache symbol lookup - const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; - u = result[1] = isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; - - // Decorating a 'diff' - if (neg) { - result[0] = -result[0]; - } - - // Applying custom symbol - if (symbols[result[1]]) { - result[1] = symbols[result[1]]; - } - - // Apply locale, separator, and padding formatting - result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); - - if (full) { - result[1] = - fullforms[e] || - STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); - } - - // Optimized return logic - if (output === ARRAY) { - return result; - } - - if (output === OBJECT) { - return { - value: result[0], - symbol: result[1], - exponent: e, - unit: u, - }; - } + u = resolveSymbol(actualStandard, bits, e, isDecimal); + result[1] = u; + + decorateResult( + result, + neg, + symbols, + locale, + localeOptions, + separator, + pad, + round, + full, + fullforms, + actualStandard, + e, + bits, + ); - return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); + return formatOutput(result, e, u, output, spacer); } /** diff --git a/dist/filesize.js b/dist/filesize.js index 4ccd262..e75ba37 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -277,6 +277,148 @@ function applyNumberFormatting(value, locale, localeOptions, separator, pad, rou } return result; +} + +/** + * Calculates exponent from the input value using pre-computed log values and clamps to supported range + * Also adjusts precision when exponent exceeds the lookup table bounds + * @param {number} num - Input file size in bytes + * @param {number} e - Current exponent value + * @param {number} exponent - Original user-provided exponent option (-1 for auto) + * @param {boolean} isDecimal - Whether to use decimal (SI) base + * @param {number} precision - Current precision value (modified when e > 8) + * @returns {Object} Object with computed e value and possibly adjusted precision + */ +function calculateExponent(num, e, exponent, isDecimal, precision) { + if (e === -1 || isNaN(exponent)) { + e = isDecimal + ? Math.floor(Math.log(num) / LOG_10_1000) + : Math.floor(Math.log(num) / LOG_2_1024); + if (e < 0) { + e = 0; + } + } + + if (e > 8) { + if (precision > 0) { + precision += 8 - e; + } + e = 8; + } + + return { e, precision }; +} + +/** + * Applies rounding to the raw calculated value and handles auto-increment ceiling + * @param {number} val - Raw value before rounding + * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC) + * @param {number} e - Current exponent value + * @param {number} round - Number of decimal places + * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil) + * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN) + * @returns {Object} Object with rounded value and possibly incremented exponent + */ +function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { + const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; + let r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; + + if (r === ceil && e < 8 && autoExponent) { + r = 1; + e++; + } + + return { value: r, e }; +} + +/** + * Resolves the unit symbol for the given standard, bits mode, and exponent + * Handles SI standard special case where exponent 1 always uses "kB" or "kbit" + * @param {string} actualStandard - The resolved standard (iec, jedec) + * @param {boolean} bits - Whether formatting bit values + * @param {number} e - Current exponent index + * @param {boolean} isDecimal - Whether using decimal (SI) base + * @returns {string} The resolved unit symbol string + */ +function resolveSymbol(actualStandard, bits, e, isDecimal) { + const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; + return isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; +} + +/** + * Decorates the result: applies negation, custom symbols, number formatting, and full form names + * Mutates the result array in-place for both value (index 0) and symbol (index 1) + * @param {Array} result - Result array with numeric value at [0] and string symbol at [1] + * @param {boolean} neg - Whether the original input was negative + * @param {Object} symbols - Custom symbol override map + * @param {string|boolean} locale - Locale string for formatting + * @param {Object} localeOptions - Additional locale formatting options + * @param {string} separator - Custom decimal separator + * @param {boolean} pad - Whether zero-pad decimals + * @param {number} round - Target decimal count for padding + * @param {boolean} full - Whether to use full unit names + * @param {Array} fullforms - Custom full unit name overrides + * @param {string} actualStandard - Unit standard for full form lookup + * @param {number} e - Current exponent index + * @param {boolean} bits - Whether formatting bit values + * @returns {void} Mutates result array in place + */ +function decorateResult( + result, + neg, + symbols, + locale, + localeOptions, + separator, + pad, + round, + full, + fullforms, + actualStandard, + e, + bits, +) { + if (neg) { + result[0] = -result[0]; + } + + if (symbols[result[1]]) { + result[1] = symbols[result[1]]; + } + + result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); + + if (full) { + result[1] = + fullforms[e] || + STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); + } +} + +/** + * Formats the computed result array into the requested output type + * @param {Array} result - Result array with formatted value at [0] and symbol at [1] + * @param {number} e - Current exponent + * @param {string} u - Original resolved symbol (before custom override) + * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO) + * @param {string} spacer - String separator between value and unit + * @returns {string|Array|Object|number} Formatted result in requested type + */ +function formatOutput(result, e, u, output, spacer) { + if (output === ARRAY) { + return result; + } + + if (output === OBJECT) { + return { + value: result[0], + symbol: result[1], + exponent: e, + unit: u, + }; + } + + return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); }/** * Converts a file size in bytes to a human-readable string with appropriate units * @param {number|string|bigint} arg - The file size in bytes to convert @@ -331,7 +473,6 @@ function filesize( val = 0, u = EMPTY; - // Optimized base & standard configuration lookup const { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base); const full = fullform === true, @@ -346,12 +487,10 @@ function filesize( throw new TypeError(INVALID_ROUND); } - // Flipping a negative number to determine the size if (neg) { num = -num; } - // Fast path for zero if (num === 0) { return handleZeroValue( precision, @@ -365,31 +504,21 @@ function filesize( ); } - // Optimized exponent calculation using pre-computed log values - if (e === -1 || isNaN(e)) { - e = isDecimal - ? Math.floor(Math.log(num) / LOG_10_1000) - : Math.floor(Math.log(num) / LOG_2_1024); - if (e < 0) { - e = 0; - } - } - - // Exceeding supported length, time to reduce & multiply - if (e > 8) { - if (precision > 0) { - precision += 8 - e; - } - e = 8; - } - + // Exponent calculation + clamp + precision adjustment + const { e: calculatedE, precision: precisionAdjusted } = calculateExponent( + num, + e, + exponent, + isDecimal, + precision, + ); + e = calculatedE; const autoExponent = exponent === -1 || isNaN(exponent); if (output === EXPONENT) { return e; } - // Calculate value with optimized lookup and bits handling const { result: valueResult, e: valueExponent } = calculateOptimizedValue( num, e, @@ -401,20 +530,16 @@ function filesize( val = valueResult; e = valueExponent; - // Optimize rounding calculation - const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; - result[0] = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; - - if (result[0] === ceil && e < 8 && autoExponent) { - result[0] = 1; - e++; - } + // Rounding + auto-increment ceiling + const rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent); + result[0] = rounded.value; + e = rounded.e; - // Apply precision handling - if (precision > 0) { + // Precision handling + if (precisionAdjusted > 0) { const precisionResult = applyPrecisionHandling( result[0], - precision, + precisionAdjusted, e, num, isDecimal, @@ -428,44 +553,26 @@ function filesize( e = precisionResult.e; } - // Cache symbol lookup - const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; - u = result[1] = isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; - - // Decorating a 'diff' - if (neg) { - result[0] = -result[0]; - } - - // Applying custom symbol - if (symbols[result[1]]) { - result[1] = symbols[result[1]]; - } - - // Apply locale, separator, and padding formatting - result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); - - if (full) { - result[1] = - fullforms[e] || - STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); - } - - // Optimized return logic - if (output === ARRAY) { - return result; - } - - if (output === OBJECT) { - return { - value: result[0], - symbol: result[1], - exponent: e, - unit: u, - }; - } + u = resolveSymbol(actualStandard, bits, e, isDecimal); + result[1] = u; + + decorateResult( + result, + neg, + symbols, + locale, + localeOptions, + separator, + pad, + round, + full, + fullforms, + actualStandard, + e, + bits, + ); - return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); + return formatOutput(result, e, u, output, spacer); } /** diff --git a/dist/filesize.min.js b/dist/filesize.min.js index ac28db5..dc1de79 100644 --- a/dist/filesize.min.js +++ b/dist/filesize.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.15 */ -const t="iec",i="jedec",e="si",a="byte",n="array",o="object",r="string",s="exponent",l="round",c={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},u=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],b=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),f=Math.log(1e3),p={[e]:{isDecimal:!0,ceil:1e3,actualStandard:i},[t]:{isDecimal:!1,ceil:1024,actualStandard:t},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function m(t,i,e,a,n,o=!0){let r=t/(e?b[i]:u[i]);return a&&(r*=8,o&&r>=n&&i<8&&(r/=n,i++)),{result:r,e:i}}function B(e,{bits:u=!1,pad:b=!1,base:B=-1,round:y=2,locale:M="",localeOptions:h={},separator:g="",spacer:x=" ",symbols:N={},standard:D="",output:E=r,fullform:S=!1,fullforms:T=[],exponent:v=-1,roundingMethod:$=l,precision:j=0}={}){let k=v,w=Number(e),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(e,a){return p[e]?p[e]:2===a?{isDecimal:!1,ceil:1024,actualStandard:t}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(D,B),z=!0===S,I=w<0,q=Math[$];if("bigint"!=typeof e&&isNaN(e))throw new TypeError("Invalid number");if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,i,e,r,l,u,b,d,f){const p=t>0?(0).toPrecision(t):0;return b===s?0:(f||(f=e?c.symbol[i].bits[0]:c.symbol[i].bytes[0]),r[f]&&(f=r[f]),l&&(f=u[0]||c.fullform[i][0]+(e?"bit":a)),b===n?[p,f]:b===o?{value:p,symbol:f,exponent:0,unit:f}:p+d+f)}(j,O,u,N,z,T,E,x);(-1===k||isNaN(k))&&(k=Y?Math.floor(Math.log(w)/f):Math.floor(Math.log(w)/d),k<0&&(k=0)),k>8&&(j>0&&(j+=8-k),k=8);const A=-1===v||isNaN(v);if(E===s)return k;const{result:C,e:F}=m(w,k,Y,u,Z,A);K=C,k=F;const H=k>0&&y>0?Math.pow(10,y):1;if(G[0]=1===H?q(K):q(K*H)/H,G[0]===Z&&k<8&&A&&(G[0]=1,k++),j>0){const t=function(t,i,e,a,n,o,r,s,l,c){let u=t.toPrecision(i);const b=-1===c||isNaN(c);if(u.includes("e")&&e<8&&b){e++;const{result:t}=m(a,e,n,o,r),c=l>0?Math.pow(10,l):1;u=(1===c?s(t):s(t*c)/c).toPrecision(i)}return{value:u,e:e}}(G[0],j,k,w,Y,u,Z,q,y,v);G[0]=t.value,k=t.e}const J=c.symbol[O][u?"bits":"bytes"];return P=G[1]=Y&&1===k?u?"kbit":"kB":J[k],I&&(G[0]=-G[0]),N[G[1]]&&(G[1]=N[G[1]]),G[0]=function(t,i,e,a,n,o){let r=t;if(!0===i?r=r.toLocaleString():i.length>0?r=r.toLocaleString(i,e):a.length>0&&(r=r.toString().replace(".",a)),n&&o>0){const t=r.toString(),i=a||(t.slice(1).match(/[.,]/g)||[]).pop()||".",e=t.split(i),n=e[1]||"",s=n.length,l=o-s;r=`${e[0]}${i}${n.padEnd(s+l,"0")}`}return r}(G[0],M,h,g,b,y),z&&(G[1]=T[k]||c.fullform[O][k]+(u?"bit":a)+(1===G[0]?"":"s")),E===n?G:E===o?{value:G[0],symbol:G[1],exponent:k,unit:P}:" "===x?`${G[0]} ${G[1]}`:G.join(x)}function y({bits:t=!1,pad:i=!1,base:e=-1,round:a=2,locale:n="",localeOptions:o={},separator:s="",spacer:c=" ",symbols:u={},standard:b="",output:d=r,fullform:f=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=l,precision:M=0}={}){return r=>B(r,{bits:t,pad:i,base:e,round:a,locale:n,localeOptions:o,separator:s,spacer:c,symbols:u,standard:b,output:d,fullform:f,fullforms:p,exponent:m,roundingMethod:y,precision:M})}export{B as filesize,y as partial};//# sourceMappingURL=filesize.min.js.map +const t="iec",e="jedec",i="si",n="byte",o="array",a="object",r="string",s="exponent",c="round",l={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},u=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],b=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),f=Math.log(1e3),p={[i]:{isDecimal:!0,ceil:1e3,actualStandard:e},[t]:{isDecimal:!1,ceil:1024,actualStandard:t},[e]:{isDecimal:!1,ceil:1024,actualStandard:e}};function m(t,e,i,n,o,a=!0){let r=t/(i?b[e]:u[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(i,{bits:u=!1,pad:b=!1,base:B=-1,round:y=2,locale:M="",localeOptions:h={},separator:g="",spacer:x=" ",symbols:N={},standard:v="",output:D=r,fullform:E=!1,fullforms:S=[],exponent:T=-1,roundingMethod:$=c,precision:j=0}={}){let k=T,w=Number(i),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(i,n){return p[i]?p[i]:2===n?{isDecimal:!1,ceil:1024,actualStandard:t}:{isDecimal:!0,ceil:1e3,actualStandard:e}}(v,B),z=!0===E,I=w<0,q=Math[$];if("bigint"!=typeof i&&isNaN(i))throw new TypeError("Invalid number");if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,r,c,u,b,d,f){const p=t>0?(0).toPrecision(t):0;return b===s?0:(f||(f=i?l.symbol[e].bits[0]:l.symbol[e].bytes[0]),r[f]&&(f=r[f]),c&&(f=u[0]||l.fullform[e][0]+(i?"bit":n)),b===o?[p,f]:b===a?{value:p,symbol:f,exponent:0,unit:f}:p+d+f)}(j,O,u,N,z,S,D,x);const{e:A,precision:C}=function(t,e,i,n,o){return(-1===e||isNaN(i))&&(e=n?Math.floor(Math.log(t)/f):Math.floor(Math.log(t)/d))<0&&(e=0),e>8&&(o>0&&(o+=8-e),e=8),{e:e,precision:o}}(w,k,T,Y,j);k=A;const F=-1===T||isNaN(T);if(D===s)return k;const{result:H,e:J}=m(w,k,Y,u,Z,F);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,y,q,F);if(G[0]=L.value,k=L.e,C>0){const t=function(t,e,i,n,o,a,r,s,c,l){let u=t.toPrecision(e);const b=-1===l||isNaN(l);if(u.includes("e")&&i<8&&b){i++;const{result:t}=m(n,i,o,a,r),l=c>0?Math.pow(10,c):1;u=(1===l?s(t):s(t*l)/l).toPrecision(e)}return{value:u,e:i}}(G[0],C,k,w,Y,u,Z,q,y,T);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=l.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,u,k,Y),G[1]=P,function(t,e,i,o,a,r,s,c,u,b,d,f,p){e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,c=a-s;r=`${i[0]}${e}${o.padEnd(s+c,"0")}`}return r}(t[0],o,a,r,s,c),u&&(t[1]=b[f]||l.fullform[d][f]+(p?"bit":n)+(1===t[0]?"":"s"))}(G,I,N,M,h,g,b,y,z,S,O,k,u),function(t,e,i,n,r){return n===o?t:n===a?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===r?`${t[0]} ${t[1]}`:t.join(r)}(G,k,P,D,x)}function y({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:s="",spacer:l=" ",symbols:u={},standard:b="",output:d=r,fullform:f=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=c,precision:M=0}={}){return r=>B(r,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:s,spacer:l,symbols:u,standard:b,output:d,fullform:f,fullforms:p,exponent:m,roundingMethod:y,precision:M})}export{B as filesize,y as partial};//# sourceMappingURL=filesize.min.js.map diff --git a/dist/filesize.min.js.map b/dist/filesize.min.js.map index af2641a..6f13d9d 100644 --- a/dist/filesize.min.js.map +++ b/dist/filesize.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBYTE,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tOBJECT,\n\tPERIOD,\n\tSI,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n","import {\n\tARRAY,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tROUND,\n\tS,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRING,\n\tSTRINGS,\n} from \"./constants.js\";\nimport {\n\tapplyNumberFormatting,\n\tapplyPrecisionHandling,\n\tcalculateOptimizedValue,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\t// Optimized base & standard configuration lookup\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\t// Flipping a negative number to determine the size\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\t// Fast path for zero\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Optimized exponent calculation using pre-computed log values\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\t// Exceeding supported length, time to reduce & multiply\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\te = 8;\n\t}\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\t// Calculate value with optimized lookup and bits handling\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Optimize rounding calculation\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tresult[0] = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (result[0] === ceil && e < 8 && autoExponent) {\n\t\tresult[0] = 1;\n\t\te++;\n\t}\n\n\t// Apply precision handling\n\tif (precision > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecision,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\t// Cache symbol lookup\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\tu = result[1] = isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n\n\t// Decorating a 'diff'\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\t// Applying custom symbol\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\t// Apply locale, separator, and padding formatting\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n\n\t// Optimized return logic\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","floor","valueResult","valueExponent","p","pow","precisionResult","includes","applyPrecisionHandling","symbolTable","toLocaleString","length","toString","replace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ED7KpB,MC8KnB,CAEA,OAAOrD,CACR,CCdauD,CAAsBvD,EAAO,GAAIM,EAAQE,EAAeC,EAAWN,EAAKE,GAEhFiB,IACHtB,EAAO,GACNc,EAAUhB,IACVnB,EAAQM,SAASU,GAAgBG,IAAMhB,EF/LvB,ME+LoCT,IAAuB,IAAd2B,EAAO,GF5KlD,GAEJ,ME8KZa,IAAWvC,EACP0B,EAGJa,IAAWtC,EACP,CACNoD,MAAO3B,EAAO,GACdpB,OAAQoB,EAAO,GACfe,SAAUjB,EACV+B,KAAMT,GFtLY,ME0LbV,EAAmB,GAAGV,EAAO,MAAMA,EAAO,KAAOA,EAAOwD,KAAK9C,EACrE,CA4BO,SAAS+C,GAAQ3E,KACvBA,GAAO,EAAKqB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EF/NoB,IE+NNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAwD"} +{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(exponent)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\te = 8;\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;AACO,MAIMA,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,CAC5B,EACA,KACA,QACA,WACA,cACA,gBACA,mBACA,oBACA,qBAGYC,EAAiB,CAC7B,EACA,IACA,IACA,IACA,KACA,KACA,KACA,KACA,M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EJ,KC+SjB,CC/KC+D,CACC/D,EACAuB,EACAZ,EACAL,EACAE,EACAC,EACAN,EACAE,EACAiB,EACAR,EACAnB,EACAG,EACAhB,GD6KK,SAAsBkB,EAAQF,EAAGsB,EAAGP,EAAQH,GAClD,OAAIG,IAAWvC,EACP0B,EAGJa,IAAWtC,EACP,CACNoD,MAAO3B,EAAO,GACdpB,OAAQoB,EAAO,GACfe,SAAUjB,EACV+B,KAAMT,GDnUY,MCuUbV,EAAmB,GAAGV,EAAO,MAAMA,EAAO,KAAOA,EAAOgE,KAAKtD,EACrE,CCzLQuD,CAAajE,EAAQF,EAAGsB,EAAGP,EAAQH,EAC3C,CA4BO,SAASwD,GAAQpF,KACvBA,GAAO,EAAKqB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAiE"} diff --git a/dist/filesize.umd.js b/dist/filesize.umd.js index fa9fa9b..0ed62ee 100644 --- a/dist/filesize.umd.js +++ b/dist/filesize.umd.js @@ -277,6 +277,148 @@ function applyNumberFormatting(value, locale, localeOptions, separator, pad, rou } return result; +} + +/** + * Calculates exponent from the input value using pre-computed log values and clamps to supported range + * Also adjusts precision when exponent exceeds the lookup table bounds + * @param {number} num - Input file size in bytes + * @param {number} e - Current exponent value + * @param {number} exponent - Original user-provided exponent option (-1 for auto) + * @param {boolean} isDecimal - Whether to use decimal (SI) base + * @param {number} precision - Current precision value (modified when e > 8) + * @returns {Object} Object with computed e value and possibly adjusted precision + */ +function calculateExponent(num, e, exponent, isDecimal, precision) { + if (e === -1 || isNaN(exponent)) { + e = isDecimal + ? Math.floor(Math.log(num) / LOG_10_1000) + : Math.floor(Math.log(num) / LOG_2_1024); + if (e < 0) { + e = 0; + } + } + + if (e > 8) { + if (precision > 0) { + precision += 8 - e; + } + e = 8; + } + + return { e, precision }; +} + +/** + * Applies rounding to the raw calculated value and handles auto-increment ceiling + * @param {number} val - Raw value before rounding + * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC) + * @param {number} e - Current exponent value + * @param {number} round - Number of decimal places + * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil) + * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN) + * @returns {Object} Object with rounded value and possibly incremented exponent + */ +function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { + const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; + let r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; + + if (r === ceil && e < 8 && autoExponent) { + r = 1; + e++; + } + + return { value: r, e }; +} + +/** + * Resolves the unit symbol for the given standard, bits mode, and exponent + * Handles SI standard special case where exponent 1 always uses "kB" or "kbit" + * @param {string} actualStandard - The resolved standard (iec, jedec) + * @param {boolean} bits - Whether formatting bit values + * @param {number} e - Current exponent index + * @param {boolean} isDecimal - Whether using decimal (SI) base + * @returns {string} The resolved unit symbol string + */ +function resolveSymbol(actualStandard, bits, e, isDecimal) { + const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; + return isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; +} + +/** + * Decorates the result: applies negation, custom symbols, number formatting, and full form names + * Mutates the result array in-place for both value (index 0) and symbol (index 1) + * @param {Array} result - Result array with numeric value at [0] and string symbol at [1] + * @param {boolean} neg - Whether the original input was negative + * @param {Object} symbols - Custom symbol override map + * @param {string|boolean} locale - Locale string for formatting + * @param {Object} localeOptions - Additional locale formatting options + * @param {string} separator - Custom decimal separator + * @param {boolean} pad - Whether zero-pad decimals + * @param {number} round - Target decimal count for padding + * @param {boolean} full - Whether to use full unit names + * @param {Array} fullforms - Custom full unit name overrides + * @param {string} actualStandard - Unit standard for full form lookup + * @param {number} e - Current exponent index + * @param {boolean} bits - Whether formatting bit values + * @returns {void} Mutates result array in place + */ +function decorateResult( + result, + neg, + symbols, + locale, + localeOptions, + separator, + pad, + round, + full, + fullforms, + actualStandard, + e, + bits, +) { + if (neg) { + result[0] = -result[0]; + } + + if (symbols[result[1]]) { + result[1] = symbols[result[1]]; + } + + result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); + + if (full) { + result[1] = + fullforms[e] || + STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); + } +} + +/** + * Formats the computed result array into the requested output type + * @param {Array} result - Result array with formatted value at [0] and symbol at [1] + * @param {number} e - Current exponent + * @param {string} u - Original resolved symbol (before custom override) + * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO) + * @param {string} spacer - String separator between value and unit + * @returns {string|Array|Object|number} Formatted result in requested type + */ +function formatOutput(result, e, u, output, spacer) { + if (output === ARRAY) { + return result; + } + + if (output === OBJECT) { + return { + value: result[0], + symbol: result[1], + exponent: e, + unit: u, + }; + } + + return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); }/** * Converts a file size in bytes to a human-readable string with appropriate units * @param {number|string|bigint} arg - The file size in bytes to convert @@ -331,7 +473,6 @@ function filesize( val = 0, u = EMPTY; - // Optimized base & standard configuration lookup const { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base); const full = fullform === true, @@ -346,12 +487,10 @@ function filesize( throw new TypeError(INVALID_ROUND); } - // Flipping a negative number to determine the size if (neg) { num = -num; } - // Fast path for zero if (num === 0) { return handleZeroValue( precision, @@ -365,31 +504,21 @@ function filesize( ); } - // Optimized exponent calculation using pre-computed log values - if (e === -1 || isNaN(e)) { - e = isDecimal - ? Math.floor(Math.log(num) / LOG_10_1000) - : Math.floor(Math.log(num) / LOG_2_1024); - if (e < 0) { - e = 0; - } - } - - // Exceeding supported length, time to reduce & multiply - if (e > 8) { - if (precision > 0) { - precision += 8 - e; - } - e = 8; - } - + // Exponent calculation + clamp + precision adjustment + const { e: calculatedE, precision: precisionAdjusted } = calculateExponent( + num, + e, + exponent, + isDecimal, + precision, + ); + e = calculatedE; const autoExponent = exponent === -1 || isNaN(exponent); if (output === EXPONENT) { return e; } - // Calculate value with optimized lookup and bits handling const { result: valueResult, e: valueExponent } = calculateOptimizedValue( num, e, @@ -401,20 +530,16 @@ function filesize( val = valueResult; e = valueExponent; - // Optimize rounding calculation - const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; - result[0] = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; - - if (result[0] === ceil && e < 8 && autoExponent) { - result[0] = 1; - e++; - } + // Rounding + auto-increment ceiling + const rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent); + result[0] = rounded.value; + e = rounded.e; - // Apply precision handling - if (precision > 0) { + // Precision handling + if (precisionAdjusted > 0) { const precisionResult = applyPrecisionHandling( result[0], - precision, + precisionAdjusted, e, num, isDecimal, @@ -428,44 +553,26 @@ function filesize( e = precisionResult.e; } - // Cache symbol lookup - const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; - u = result[1] = isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; - - // Decorating a 'diff' - if (neg) { - result[0] = -result[0]; - } - - // Applying custom symbol - if (symbols[result[1]]) { - result[1] = symbols[result[1]]; - } - - // Apply locale, separator, and padding formatting - result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); - - if (full) { - result[1] = - fullforms[e] || - STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); - } - - // Optimized return logic - if (output === ARRAY) { - return result; - } - - if (output === OBJECT) { - return { - value: result[0], - symbol: result[1], - exponent: e, - unit: u, - }; - } + u = resolveSymbol(actualStandard, bits, e, isDecimal); + result[1] = u; + + decorateResult( + result, + neg, + symbols, + locale, + localeOptions, + separator, + pad, + round, + full, + fullforms, + actualStandard, + e, + bits, + ); - return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); + return formatOutput(result, e, u, output, spacer); } /** diff --git a/dist/filesize.umd.min.js b/dist/filesize.umd.min.js index d47d9e2..ac0421e 100644 --- a/dist/filesize.umd.min.js +++ b/dist/filesize.umd.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.15 */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,function(t){"use strict";const e="iec",i="jedec",n="si",o="byte",a="array",r="object",s="string",l="exponent",c="round",u={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],d=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],f=Math.log(1024),p=Math.log(1e3),m={[n]:{isDecimal:!0,ceil:1e3,actualStandard:i},[e]:{isDecimal:!1,ceil:1024,actualStandard:e},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function y(t,e,i,n,o,a=!0){let r=t/(i?d[e]:b[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(t,{bits:n=!1,pad:b=!1,base:d=-1,round:B=2,locale:h="",localeOptions:M={},separator:g="",spacer:x=" ",symbols:N={},standard:T="",output:D=s,fullform:E=!1,fullforms:S=[],exponent:j=-1,roundingMethod:v=c,precision:$=0}={}){let k=j,w=Number(t),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(t,n){return m[t]?m[t]:2===n?{isDecimal:!1,ceil:1024,actualStandard:e}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(T,d),z=!0===E,I=w<0,q=Math[v];if("bigint"!=typeof t&&isNaN(t))throw new TypeError("Invalid number");if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,n,s,c,b,d,f){const p=t>0?(0).toPrecision(t):0;return b===l?0:(f||(f=i?u.symbol[e].bits[0]:u.symbol[e].bytes[0]),n[f]&&(f=n[f]),s&&(f=c[0]||u.fullform[e][0]+(i?"bit":o)),b===a?[p,f]:b===r?{value:p,symbol:f,exponent:0,unit:f}:p+d+f)}($,O,n,N,z,S,D,x);(-1===k||isNaN(k))&&(k=Y?Math.floor(Math.log(w)/p):Math.floor(Math.log(w)/f),k<0&&(k=0)),k>8&&($>0&&($+=8-k),k=8);const A=-1===j||isNaN(j);if(D===l)return k;const{result:C,e:F}=y(w,k,Y,n,Z,A);K=C,k=F;const H=k>0&&B>0?Math.pow(10,B):1;if(G[0]=1===H?q(K):q(K*H)/H,G[0]===Z&&k<8&&A&&(G[0]=1,k++),$>0){const t=function(t,e,i,n,o,a,r,s,l,c){let u=t.toPrecision(e);const b=-1===c||isNaN(c);if(u.includes("e")&&i<8&&b){i++;const{result:t}=y(n,i,o,a,r),c=l>0?Math.pow(10,l):1;u=(1===c?s(t):s(t*c)/c).toPrecision(e)}return{value:u,e:i}}(G[0],$,k,w,Y,n,Z,q,B,j);G[0]=t.value,k=t.e}const J=u.symbol[O][n?"bits":"bytes"];return P=G[1]=Y&&1===k?n?"kbit":"kB":J[k],I&&(G[0]=-G[0]),N[G[1]]&&(G[1]=N[G[1]]),G[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,l=a-s;r=`${i[0]}${e}${o.padEnd(s+l,"0")}`}return r}(G[0],h,M,g,b,B),z&&(G[1]=S[k]||u.fullform[O][k]+(n?"bit":o)+(1===G[0]?"":"s")),D===a?G:D===r?{value:G[0],symbol:G[1],exponent:k,unit:P}:" "===x?`${G[0]} ${G[1]}`:G.join(x)}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:r="",spacer:l=" ",symbols:u={},standard:b="",output:d=s,fullform:f=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=c,precision:h=0}={}){return s=>B(s,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:r,spacer:l,symbols:u,standard:b,output:d,fullform:f,fullforms:p,exponent:m,roundingMethod:y,precision:h})}});//# sourceMappingURL=filesize.umd.min.js.map +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,function(t){"use strict";const e="iec",i="jedec",n="si",o="byte",a="array",r="object",s="string",l="exponent",u="round",c={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],f=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),p=Math.log(1e3),m={[n]:{isDecimal:!0,ceil:1e3,actualStandard:i},[e]:{isDecimal:!1,ceil:1024,actualStandard:e},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function y(t,e,i,n,o,a=!0){let r=t/(i?f[e]:b[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(t,{bits:n=!1,pad:b=!1,base:f=-1,round:B=2,locale:h="",localeOptions:M={},separator:g="",spacer:x=" ",symbols:N={},standard:T="",output:v=s,fullform:D=!1,fullforms:E=[],exponent:S=-1,roundingMethod:j=u,precision:$=0}={}){let k=S,w=Number(t),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(t,n){return m[t]?m[t]:2===n?{isDecimal:!1,ceil:1024,actualStandard:e}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(T,f),z=!0===D,I=w<0,q=Math[j];if("bigint"!=typeof t&&isNaN(t))throw new TypeError("Invalid number");if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,n,s,u,b,f,d){const p=t>0?(0).toPrecision(t):0;return b===l?0:(d||(d=i?c.symbol[e].bits[0]:c.symbol[e].bytes[0]),n[d]&&(d=n[d]),s&&(d=u[0]||c.fullform[e][0]+(i?"bit":o)),b===a?[p,d]:b===r?{value:p,symbol:d,exponent:0,unit:d}:p+f+d)}($,O,n,N,z,E,v,x);const{e:A,precision:C}=function(t,e,i,n,o){return(-1===e||isNaN(i))&&(e=n?Math.floor(Math.log(t)/p):Math.floor(Math.log(t)/d))<0&&(e=0),e>8&&(o>0&&(o+=8-e),e=8),{e:e,precision:o}}(w,k,S,Y,$);k=A;const F=-1===S||isNaN(S);if(v===l)return k;const{result:H,e:J}=y(w,k,Y,n,Z,F);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,B,q,F);if(G[0]=L.value,k=L.e,C>0){const t=function(t,e,i,n,o,a,r,s,l,u){let c=t.toPrecision(e);const b=-1===u||isNaN(u);if(c.includes("e")&&i<8&&b){i++;const{result:t}=y(n,i,o,a,r),u=l>0?Math.pow(10,l):1;c=(1===u?s(t):s(t*u)/u).toPrecision(e)}return{value:c,e:i}}(G[0],C,k,w,Y,n,Z,q,B,S);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=c.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,n,k,Y),G[1]=P,function(t,e,i,n,a,r,s,l,u,b,f,d,p){e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,l=a-s;r=`${i[0]}${e}${o.padEnd(s+l,"0")}`}return r}(t[0],n,a,r,s,l),u&&(t[1]=b[d]||c.fullform[f][d]+(p?"bit":o)+(1===t[0]?"":"s"))}(G,I,N,h,M,g,b,B,z,E,O,k,n),function(t,e,i,n,o){return n===a?t:n===r?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===o?`${t[0]} ${t[1]}`:t.join(o)}(G,k,P,v,x)}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:r="",spacer:l=" ",symbols:c={},standard:b="",output:f=s,fullform:d=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=u,precision:h=0}={}){return s=>B(s,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:r,spacer:l,symbols:c,standard:b,output:f,fullform:d,fullforms:p,exponent:m,roundingMethod:y,precision:h})}});//# sourceMappingURL=filesize.umd.min.js.map diff --git a/dist/filesize.umd.min.js.map b/dist/filesize.umd.min.js.map index c3c37ef..20c7f97 100644 --- a/dist/filesize.umd.min.js.map +++ b/dist/filesize.umd.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBYTE,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tOBJECT,\n\tPERIOD,\n\tSI,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n","import {\n\tARRAY,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tROUND,\n\tS,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRING,\n\tSTRINGS,\n} from \"./constants.js\";\nimport {\n\tapplyNumberFormatting,\n\tapplyPrecisionHandling,\n\tcalculateOptimizedValue,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\t// Optimized base & standard configuration lookup\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\t// Flipping a negative number to determine the size\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\t// Fast path for zero\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Optimized exponent calculation using pre-computed log values\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\t// Exceeding supported length, time to reduce & multiply\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\te = 8;\n\t}\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\t// Calculate value with optimized lookup and bits handling\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Optimize rounding calculation\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tresult[0] = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (result[0] === ceil && e < 8 && autoExponent) {\n\t\tresult[0] = 1;\n\t\te++;\n\t}\n\n\t// Apply precision handling\n\tif (precision > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecision,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\t// Cache symbol lookup\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\tu = result[1] = isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n\n\t// Decorating a 'diff'\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\t// Applying custom symbol\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\t// Apply locale, separator, and padding formatting\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n\n\t// Optimized return logic\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","floor","valueResult","valueExponent","p","pow","precisionResult","includes","applyPrecisionHandling","symbolTable","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","join","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,SAAA,CAAA,EAAA,CAAA,CAAAC,KAAA,SAAAP,GAAA,aACO,MAIMQ,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,CAC5B,EACA,KACA,QACA,WACA,cACA,gBACA,mBACA,oBACA,qBAGYC,EAAiB,CAC7B,EACA,IACA,IAC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BrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} +{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(exponent)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\te = 8;\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,SAAA,CAAA,EAAA,CAAA,CAAAC,KAAA,SAAAP,GAAA,aACO,MAIMQ,EAA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KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASpC,EAAMS,SACfA,GAAW,EAAK4B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} diff --git a/src/filesize.js b/src/filesize.js index ae3645a..3d79a9b 100644 --- a/src/filesize.js +++ b/src/filesize.js @@ -1,31 +1,23 @@ import { - ARRAY, - BIT, - BITS, - BYTE, - BYTES, EMPTY, EXPONENT, FUNCTION, INVALID_NUMBER, INVALID_ROUND, - LOG_10_1000, - LOG_2_1024, - OBJECT, ROUND, - S, - SI_KBIT, - SI_KBYTE, SPACE, STRING, - STRINGS, } from "./constants.js"; import { - applyNumberFormatting, applyPrecisionHandling, + applyRounding, + calculateExponent, calculateOptimizedValue, + decorateResult, + formatOutput, getBaseConfiguration, handleZeroValue, + resolveSymbol, } from "./helpers.js"; /** @@ -82,7 +74,6 @@ export function filesize( val = 0, u = EMPTY; - // Optimized base & standard configuration lookup const { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base); const full = fullform === true, @@ -97,12 +88,10 @@ export function filesize( throw new TypeError(INVALID_ROUND); } - // Flipping a negative number to determine the size if (neg) { num = -num; } - // Fast path for zero if (num === 0) { return handleZeroValue( precision, @@ -116,31 +105,21 @@ export function filesize( ); } - // Optimized exponent calculation using pre-computed log values - if (e === -1 || isNaN(e)) { - e = isDecimal - ? Math.floor(Math.log(num) / LOG_10_1000) - : Math.floor(Math.log(num) / LOG_2_1024); - if (e < 0) { - e = 0; - } - } - - // Exceeding supported length, time to reduce & multiply - if (e > 8) { - if (precision > 0) { - precision += 8 - e; - } - e = 8; - } - + // Exponent calculation + clamp + precision adjustment + const { e: calculatedE, precision: precisionAdjusted } = calculateExponent( + num, + e, + exponent, + isDecimal, + precision, + ); + e = calculatedE; const autoExponent = exponent === -1 || isNaN(exponent); if (output === EXPONENT) { return e; } - // Calculate value with optimized lookup and bits handling const { result: valueResult, e: valueExponent } = calculateOptimizedValue( num, e, @@ -152,20 +131,16 @@ export function filesize( val = valueResult; e = valueExponent; - // Optimize rounding calculation - const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; - result[0] = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; - - if (result[0] === ceil && e < 8 && autoExponent) { - result[0] = 1; - e++; - } + // Rounding + auto-increment ceiling + const rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent); + result[0] = rounded.value; + e = rounded.e; - // Apply precision handling - if (precision > 0) { + // Precision handling + if (precisionAdjusted > 0) { const precisionResult = applyPrecisionHandling( result[0], - precision, + precisionAdjusted, e, num, isDecimal, @@ -179,44 +154,26 @@ export function filesize( e = precisionResult.e; } - // Cache symbol lookup - const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; - u = result[1] = isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; - - // Decorating a 'diff' - if (neg) { - result[0] = -result[0]; - } - - // Applying custom symbol - if (symbols[result[1]]) { - result[1] = symbols[result[1]]; - } - - // Apply locale, separator, and padding formatting - result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); - - if (full) { - result[1] = - fullforms[e] || - STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); - } - - // Optimized return logic - if (output === ARRAY) { - return result; - } - - if (output === OBJECT) { - return { - value: result[0], - symbol: result[1], - exponent: e, - unit: u, - }; - } + u = resolveSymbol(actualStandard, bits, e, isDecimal); + result[1] = u; + + decorateResult( + result, + neg, + symbols, + locale, + localeOptions, + separator, + pad, + round, + full, + fullforms, + actualStandard, + e, + bits, + ); - return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); + return formatOutput(result, e, u, output, spacer); } /** diff --git a/src/helpers.js b/src/helpers.js index 9556a90..272c9c8 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -2,16 +2,24 @@ import { ARRAY, BINARY_POWERS, BIT, + BITS, BYTE, + BYTES, DECIMAL_POWERS, E, EMPTY, EXPONENT, IEC, JEDEC, + LOG_10_1000, + LOG_2_1024, OBJECT, PERIOD, + S, SI, + SI_KBIT, + SI_KBYTE, + SPACE, STRINGS, ZERO, } from "./constants.js"; @@ -209,3 +217,145 @@ export function applyNumberFormatting(value, locale, localeOptions, separator, p return result; } + +/** + * Calculates exponent from the input value using pre-computed log values and clamps to supported range + * Also adjusts precision when exponent exceeds the lookup table bounds + * @param {number} num - Input file size in bytes + * @param {number} e - Current exponent value + * @param {number} exponent - Original user-provided exponent option (-1 for auto) + * @param {boolean} isDecimal - Whether to use decimal (SI) base + * @param {number} precision - Current precision value (modified when e > 8) + * @returns {Object} Object with computed e value and possibly adjusted precision + */ +export function calculateExponent(num, e, exponent, isDecimal, precision) { + if (e === -1 || isNaN(exponent)) { + e = isDecimal + ? Math.floor(Math.log(num) / LOG_10_1000) + : Math.floor(Math.log(num) / LOG_2_1024); + if (e < 0) { + e = 0; + } + } + + if (e > 8) { + if (precision > 0) { + precision += 8 - e; + } + e = 8; + } + + return { e, precision }; +} + +/** + * Applies rounding to the raw calculated value and handles auto-increment ceiling + * @param {number} val - Raw value before rounding + * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC) + * @param {number} e - Current exponent value + * @param {number} round - Number of decimal places + * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil) + * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN) + * @returns {Object} Object with rounded value and possibly incremented exponent + */ +export function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { + const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; + let r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; + + if (r === ceil && e < 8 && autoExponent) { + r = 1; + e++; + } + + return { value: r, e }; +} + +/** + * Resolves the unit symbol for the given standard, bits mode, and exponent + * Handles SI standard special case where exponent 1 always uses "kB" or "kbit" + * @param {string} actualStandard - The resolved standard (iec, jedec) + * @param {boolean} bits - Whether formatting bit values + * @param {number} e - Current exponent index + * @param {boolean} isDecimal - Whether using decimal (SI) base + * @returns {string} The resolved unit symbol string + */ +export function resolveSymbol(actualStandard, bits, e, isDecimal) { + const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; + return isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; +} + +/** + * Decorates the result: applies negation, custom symbols, number formatting, and full form names + * Mutates the result array in-place for both value (index 0) and symbol (index 1) + * @param {Array} result - Result array with numeric value at [0] and string symbol at [1] + * @param {boolean} neg - Whether the original input was negative + * @param {Object} symbols - Custom symbol override map + * @param {string|boolean} locale - Locale string for formatting + * @param {Object} localeOptions - Additional locale formatting options + * @param {string} separator - Custom decimal separator + * @param {boolean} pad - Whether zero-pad decimals + * @param {number} round - Target decimal count for padding + * @param {boolean} full - Whether to use full unit names + * @param {Array} fullforms - Custom full unit name overrides + * @param {string} actualStandard - Unit standard for full form lookup + * @param {number} e - Current exponent index + * @param {boolean} bits - Whether formatting bit values + * @returns {void} Mutates result array in place + */ +export function decorateResult( + result, + neg, + symbols, + locale, + localeOptions, + separator, + pad, + round, + full, + fullforms, + actualStandard, + e, + bits, +) { + if (neg) { + result[0] = -result[0]; + } + + if (symbols[result[1]]) { + result[1] = symbols[result[1]]; + } + + result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); + + if (full) { + result[1] = + fullforms[e] || + STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); + } +} + +/** + * Formats the computed result array into the requested output type + * @param {Array} result - Result array with formatted value at [0] and symbol at [1] + * @param {number} e - Current exponent + * @param {string} u - Original resolved symbol (before custom override) + * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO) + * @param {string} spacer - String separator between value and unit + * @returns {string|Array|Object|number} Formatted result in requested type + */ +export function formatOutput(result, e, u, output, spacer) { + if (output === ARRAY) { + return result; + } + + if (output === OBJECT) { + return { + value: result[0], + symbol: result[1], + exponent: e, + unit: u, + }; + } + + return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); +} diff --git a/types/helpers.d.ts b/types/helpers.d.ts index fdafbd5..088e4a3 100644 --- a/types/helpers.d.ts +++ b/types/helpers.d.ts @@ -127,3 +127,116 @@ export function applyNumberFormatting( pad: boolean, round: number ): string | number; + +/** + * Result of exponent calculation and precision adjustment + */ +export interface ExponentCalculationResult { + /** The computed exponent value */ + e: number; + /** The possibly adjusted precision value */ + precision: number; +} + +/** + * Calculates exponent from the input value using pre-computed log values and clamps to supported range + * Also adjusts precision when exponent exceeds the lookup table bounds + * @param num - Input file size in bytes + * @param e - Current exponent value + * @param exponent - Original user-provided exponent option (-1 for auto) + * @param isDecimal - Whether to use decimal (SI) base + * @param precision - Current precision value (modified when e > 8) + * @returns Object with computed e value and possibly adjusted precision + */ +export function calculateExponent( + num: number, + e: number, + exponent: number, + isDecimal: boolean, + precision: number +): ExponentCalculationResult; + +/** + * Applies rounding to the raw calculated value and handles auto-increment ceiling + * @param val - Raw value before rounding + * @param ceil - Ceiling threshold (1000 for SI, 1024 for IEC) + * @param e - Current exponent value + * @param round - Number of decimal places + * @param roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil) + * @param autoExponent - Whether exponent is auto-calculated (-1 or NaN) + * @returns Object with rounded value and possibly incremented exponent + */ +export function applyRounding( + val: number, + ceil: number, + e: number, + round: number, + roundingFunc: (x: number) => number, + autoExponent: boolean +): { value: number; e: number }; + +/** + * Resolves the unit symbol for the given standard, bits mode, and exponent + * Handles SI standard special case where exponent 1 always uses "kB" or "kbit" + * @param actualStandard - The resolved standard (iec, jedec) + * @param bits - Whether formatting bit values + * @param e - Current exponent index + * @param isDecimal - Whether using decimal (SI) base + * @returns The resolved unit symbol string + */ +export function resolveSymbol( + actualStandard: string, + bits: boolean, + e: number, + isDecimal: boolean +): string; + +/** + * Decorates the result: applies negation, custom symbols, number formatting, and full form names + * Mutates the result array in-place for both value (index 0) and symbol (index 1) + * @param result - Result array with numeric value at [0] and string symbol at [1] + * @param neg - Whether the original input was negative + * @param symbols - Custom symbol override map + * @param locale - Locale string for formatting + * @param localeOptions - Additional locale formatting options + * @param separator - Custom decimal separator + * @param pad - Whether zero-pad decimals + * @param round - Target decimal count for padding + * @param full - Whether to use full unit names + * @param fullforms - Custom full unit name overrides + * @param actualStandard - Unit standard for full form lookup + * @param e - Current exponent index + * @param bits - Whether formatting bit values + */ +export function decorateResult( + result: number[], + neg: boolean, + symbols: Record, + locale: string | boolean, + localeOptions: Record, + separator: string, + pad: boolean, + round: number, + full: boolean, + fullforms: string[], + actualStandard: string, + e: number, + bits: boolean +): void; + +/** + * Formats the computed result array into the requested output type + * @param result - Result array with formatted value at [0] and symbol at [1] + * @param e - Current exponent + * @param u - Original resolved symbol (before custom override) + * @param output - Output type (ARRAY, OBJECT, STRING, EXPONENT) + * @param spacer - String separator between value and unit + * @returns Formatted result in requested type + */ +export function formatOutput( + result: number[], + e: number, + u: string, + output: string, + spacer: string +): string | number[] | { value: number | string; symbol: string; exponent: number; unit: string } | number; From d3a66669be37768c1a08694b6207b7f9e421be8d Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 19:57:29 -0400 Subject: [PATCH 02/11] docs: improve package.json description --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 493a838..8a272e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "filesize", - "description": "JavaScript library to generate a human readable String describing the file size", + "description": "Lightweight, zero-dependency JavaScript utility to convert bytes to human-readable strings with localization support", "version": "11.0.15", "homepage": "https://filesizejs.com", "author": "Jason Mulligan ", From e35887413db20e528a44b3905736addbd59d59ef Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 20:09:37 -0400 Subject: [PATCH 03/11] fix: use isNaN(e) instead of isNaN(exponent) in calculateExponent --- src/helpers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 272c9c8..4909869 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -229,7 +229,7 @@ export function applyNumberFormatting(value, locale, localeOptions, separator, p * @returns {Object} Object with computed e value and possibly adjusted precision */ export function calculateExponent(num, e, exponent, isDecimal, precision) { - if (e === -1 || isNaN(exponent)) { + if (e === -1 || isNaN(e)) { e = isDecimal ? Math.floor(Math.log(num) / LOG_10_1000) : Math.floor(Math.log(num) / LOG_2_1024); @@ -242,7 +242,7 @@ export function calculateExponent(num, e, exponent, isDecimal, precision) { if (precision > 0) { precision += 8 - e; } - e = 8; + return { e: 8, precision }; } return { e, precision }; From c3427852da2f3046a60cfce884452970187b7fb0 Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 20:13:16 -0400 Subject: [PATCH 04/11] docs: remove misleading EXPO reference from formatOutput JSDoc --- dist/filesize.cjs | 4 ++-- dist/filesize.js | 4 ++-- dist/filesize.min.js | 2 +- dist/filesize.min.js.map | 2 +- dist/filesize.umd.js | 4 ++-- dist/filesize.umd.min.js | 2 +- dist/filesize.umd.min.js.map | 2 +- src/helpers.js | 2 +- types/helpers.d.ts | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dist/filesize.cjs b/dist/filesize.cjs index f10c602..d6ba28c 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -294,7 +294,7 @@ function applyNumberFormatting(value, locale, localeOptions, separator, pad, rou * @returns {Object} Object with computed e value and possibly adjusted precision */ function calculateExponent(num, e, exponent, isDecimal, precision) { - if (e === -1 || isNaN(exponent)) { + if (e === -1 || isNaN(e)) { e = isDecimal ? Math.floor(Math.log(num) / LOG_10_1000) : Math.floor(Math.log(num) / LOG_2_1024); @@ -307,7 +307,7 @@ function calculateExponent(num, e, exponent, isDecimal, precision) { if (precision > 0) { precision += 8 - e; } - e = 8; + return { e: 8, precision }; } return { e, precision }; diff --git a/dist/filesize.js b/dist/filesize.js index e75ba37..54780c8 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -290,7 +290,7 @@ function applyNumberFormatting(value, locale, localeOptions, separator, pad, rou * @returns {Object} Object with computed e value and possibly adjusted precision */ function calculateExponent(num, e, exponent, isDecimal, precision) { - if (e === -1 || isNaN(exponent)) { + if (e === -1 || isNaN(e)) { e = isDecimal ? Math.floor(Math.log(num) / LOG_10_1000) : Math.floor(Math.log(num) / LOG_2_1024); @@ -303,7 +303,7 @@ function calculateExponent(num, e, exponent, isDecimal, precision) { if (precision > 0) { precision += 8 - e; } - e = 8; + return { e: 8, precision }; } return { e, precision }; diff --git a/dist/filesize.min.js b/dist/filesize.min.js index dc1de79..8f1ae97 100644 --- a/dist/filesize.min.js +++ b/dist/filesize.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.15 */ -const t="iec",e="jedec",i="si",n="byte",o="array",a="object",r="string",s="exponent",c="round",l={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},u=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],b=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),f=Math.log(1e3),p={[i]:{isDecimal:!0,ceil:1e3,actualStandard:e},[t]:{isDecimal:!1,ceil:1024,actualStandard:t},[e]:{isDecimal:!1,ceil:1024,actualStandard:e}};function m(t,e,i,n,o,a=!0){let r=t/(i?b[e]:u[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(i,{bits:u=!1,pad:b=!1,base:B=-1,round:y=2,locale:M="",localeOptions:h={},separator:g="",spacer:x=" ",symbols:N={},standard:v="",output:D=r,fullform:E=!1,fullforms:S=[],exponent:T=-1,roundingMethod:$=c,precision:j=0}={}){let k=T,w=Number(i),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(i,n){return p[i]?p[i]:2===n?{isDecimal:!1,ceil:1024,actualStandard:t}:{isDecimal:!0,ceil:1e3,actualStandard:e}}(v,B),z=!0===E,I=w<0,q=Math[$];if("bigint"!=typeof i&&isNaN(i))throw new TypeError("Invalid number");if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,r,c,u,b,d,f){const p=t>0?(0).toPrecision(t):0;return b===s?0:(f||(f=i?l.symbol[e].bits[0]:l.symbol[e].bytes[0]),r[f]&&(f=r[f]),c&&(f=u[0]||l.fullform[e][0]+(i?"bit":n)),b===o?[p,f]:b===a?{value:p,symbol:f,exponent:0,unit:f}:p+d+f)}(j,O,u,N,z,S,D,x);const{e:A,precision:C}=function(t,e,i,n,o){return(-1===e||isNaN(i))&&(e=n?Math.floor(Math.log(t)/f):Math.floor(Math.log(t)/d))<0&&(e=0),e>8&&(o>0&&(o+=8-e),e=8),{e:e,precision:o}}(w,k,T,Y,j);k=A;const F=-1===T||isNaN(T);if(D===s)return k;const{result:H,e:J}=m(w,k,Y,u,Z,F);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,y,q,F);if(G[0]=L.value,k=L.e,C>0){const t=function(t,e,i,n,o,a,r,s,c,l){let u=t.toPrecision(e);const b=-1===l||isNaN(l);if(u.includes("e")&&i<8&&b){i++;const{result:t}=m(n,i,o,a,r),l=c>0?Math.pow(10,c):1;u=(1===l?s(t):s(t*l)/l).toPrecision(e)}return{value:u,e:i}}(G[0],C,k,w,Y,u,Z,q,y,T);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=l.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,u,k,Y),G[1]=P,function(t,e,i,o,a,r,s,c,u,b,d,f,p){e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,c=a-s;r=`${i[0]}${e}${o.padEnd(s+c,"0")}`}return r}(t[0],o,a,r,s,c),u&&(t[1]=b[f]||l.fullform[d][f]+(p?"bit":n)+(1===t[0]?"":"s"))}(G,I,N,M,h,g,b,y,z,S,O,k,u),function(t,e,i,n,r){return n===o?t:n===a?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===r?`${t[0]} ${t[1]}`:t.join(r)}(G,k,P,D,x)}function y({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:s="",spacer:l=" ",symbols:u={},standard:b="",output:d=r,fullform:f=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=c,precision:M=0}={}){return r=>B(r,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:s,spacer:l,symbols:u,standard:b,output:d,fullform:f,fullforms:p,exponent:m,roundingMethod:y,precision:M})}export{B as filesize,y as partial};//# sourceMappingURL=filesize.min.js.map +const t="iec",e="jedec",i="si",n="byte",o="array",a="object",r="string",s="exponent",c="round",l={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},u=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],b=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),f=Math.log(1e3),p={[i]:{isDecimal:!0,ceil:1e3,actualStandard:e},[t]:{isDecimal:!1,ceil:1024,actualStandard:t},[e]:{isDecimal:!1,ceil:1024,actualStandard:e}};function m(t,e,i,n,o,a=!0){let r=t/(i?b[e]:u[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(i,{bits:u=!1,pad:b=!1,base:B=-1,round:y=2,locale:M="",localeOptions:h={},separator:g="",spacer:x=" ",symbols:N={},standard:v="",output:D=r,fullform:E=!1,fullforms:S=[],exponent:T=-1,roundingMethod:$=c,precision:j=0}={}){let k=T,w=Number(i),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(i,n){return p[i]?p[i]:2===n?{isDecimal:!1,ceil:1024,actualStandard:t}:{isDecimal:!0,ceil:1e3,actualStandard:e}}(v,B),z=!0===E,I=w<0,q=Math[$];if("bigint"!=typeof i&&isNaN(i))throw new TypeError("Invalid number");if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,r,c,u,b,d,f){const p=t>0?(0).toPrecision(t):0;return b===s?0:(f||(f=i?l.symbol[e].bits[0]:l.symbol[e].bytes[0]),r[f]&&(f=r[f]),c&&(f=u[0]||l.fullform[e][0]+(i?"bit":n)),b===o?[p,f]:b===a?{value:p,symbol:f,exponent:0,unit:f}:p+d+f)}(j,O,u,N,z,S,D,x);const{e:A,precision:C}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/f):Math.floor(Math.log(t)/d))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(w,k,0,Y,j);k=A;const F=-1===T||isNaN(T);if(D===s)return k;const{result:H,e:J}=m(w,k,Y,u,Z,F);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,y,q,F);if(G[0]=L.value,k=L.e,C>0){const t=function(t,e,i,n,o,a,r,s,c,l){let u=t.toPrecision(e);const b=-1===l||isNaN(l);if(u.includes("e")&&i<8&&b){i++;const{result:t}=m(n,i,o,a,r),l=c>0?Math.pow(10,c):1;u=(1===l?s(t):s(t*l)/l).toPrecision(e)}return{value:u,e:i}}(G[0],C,k,w,Y,u,Z,q,y,T);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=l.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,u,k,Y),G[1]=P,function(t,e,i,o,a,r,s,c,u,b,d,f,p){e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,c=a-s;r=`${i[0]}${e}${o.padEnd(s+c,"0")}`}return r}(t[0],o,a,r,s,c),u&&(t[1]=b[f]||l.fullform[d][f]+(p?"bit":n)+(1===t[0]?"":"s"))}(G,I,N,M,h,g,b,y,z,S,O,k,u),function(t,e,i,n,r){return n===o?t:n===a?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===r?`${t[0]} ${t[1]}`:t.join(r)}(G,k,P,D,x)}function y({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:s="",spacer:l=" ",symbols:u={},standard:b="",output:d=r,fullform:f=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=c,precision:M=0}={}){return r=>B(r,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:s,spacer:l,symbols:u,standard:b,output:d,fullform:f,fullforms:p,exponent:m,roundingMethod:y,precision:M})}export{B as filesize,y as partial};//# sourceMappingURL=filesize.min.js.map diff --git a/dist/filesize.min.js.map b/dist/filesize.min.js.map index 6f13d9d..0cfbec2 100644 --- a/dist/filesize.min.js.map +++ b/dist/filesize.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(exponent)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\te = 8;\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;AACO,MAIMA,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,CAC5B,EACA,KACA,QACA,WACA,cACA,gBACA,mBACA,oBACA,qBAGYC,EAAiB,CAC7B,EACA,IACA,IACA,IACA,KACA,KACA,KACA,KACA,MAIYC,EAAaC,KAAKC,IAAI,MACtBC,EAAcF,KAAKC,IAAI,KCrD9BE,EAAmB,CACxBpB,CAACA,GAAK,CAAEqB,WAAW,EAAMC,KAAM,IAAMC,eAAgBxB,GACrDD,CAACA,GAAM,CAAEuB,WAAW,EAAOC,KAAM,KAAMC,eAAgBzB,GACvDC,CAACA,GAAQ,CAAEsB,WAAW,EAAOC,KAAM,KAAMC,eAAgBxB,IA6FnD,SAAS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GDnUY,MCuUbV,EAAmB,GAAGV,EAAO,MAAMA,EAAO,KAAOA,EAAOgE,KAAKtD,EACrE,CCzLQuD,CAAajE,EAAQF,EAAGsB,EAAGP,EAAQH,EAC3C,CA4BO,SAASwD,GAAQpF,KACvBA,GAAO,EAAKqB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAiE"} +{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;AACO,MAIMA,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,CAC5B,EACA,KACA,QACA,WACA,cACA,gBACA,mBACA,oBACA,qBAGYC,EAAiB,CAC7B,EACA,IACA,IACA,IACA,KACA,KACA,KACA,KACA,MAIYC,EAAaC,KAAKC,IAAI,MACtBC,EAAcF,KAAKC,IAAI,KCrD9BE,EAAmB,CACxBpB,CAACA,GAAK,CAAEqB,WAAW,EAAMC,KAAM,IAAMC,eAAgBxB,GACrDD,CAACA,GAAM,CAAEuB,WAAW,EAAOC,KAAM,KAAMC,eAAgBzB,GACvDC,CAACA,GAAQ,CAAEsB,WAAW,EAAOC,KAAM,KAAMC,eAAgBxB,IA6FnD,SAASyB,EAA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AMT,GDnUY,MCuUbV,EAAmB,GAAGV,EAAO,MAAMA,EAAO,KAAOA,EAAOgE,KAAKtD,EACrE,CCzLQuD,CAAajE,EAAQF,EAAGsB,EAAGP,EAAQH,EAC3C,CA4BO,SAASwD,GAAQpF,KACvBA,GAAO,EAAKqB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAiE"} diff --git a/dist/filesize.umd.js b/dist/filesize.umd.js index 0ed62ee..761ad9f 100644 --- a/dist/filesize.umd.js +++ b/dist/filesize.umd.js @@ -290,7 +290,7 @@ function applyNumberFormatting(value, locale, localeOptions, separator, pad, rou * @returns {Object} Object with computed e value and possibly adjusted precision */ function calculateExponent(num, e, exponent, isDecimal, precision) { - if (e === -1 || isNaN(exponent)) { + if (e === -1 || isNaN(e)) { e = isDecimal ? Math.floor(Math.log(num) / LOG_10_1000) : Math.floor(Math.log(num) / LOG_2_1024); @@ -303,7 +303,7 @@ function calculateExponent(num, e, exponent, isDecimal, precision) { if (precision > 0) { precision += 8 - e; } - e = 8; + return { e: 8, precision }; } return { e, precision }; diff --git a/dist/filesize.umd.min.js b/dist/filesize.umd.min.js index ac0421e..6917d3c 100644 --- a/dist/filesize.umd.min.js +++ b/dist/filesize.umd.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.15 */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,function(t){"use strict";const e="iec",i="jedec",n="si",o="byte",a="array",r="object",s="string",l="exponent",u="round",c={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],f=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),p=Math.log(1e3),m={[n]:{isDecimal:!0,ceil:1e3,actualStandard:i},[e]:{isDecimal:!1,ceil:1024,actualStandard:e},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function y(t,e,i,n,o,a=!0){let r=t/(i?f[e]:b[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(t,{bits:n=!1,pad:b=!1,base:f=-1,round:B=2,locale:h="",localeOptions:M={},separator:g="",spacer:x=" ",symbols:N={},standard:T="",output:v=s,fullform:D=!1,fullforms:E=[],exponent:S=-1,roundingMethod:j=u,precision:$=0}={}){let k=S,w=Number(t),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(t,n){return m[t]?m[t]:2===n?{isDecimal:!1,ceil:1024,actualStandard:e}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(T,f),z=!0===D,I=w<0,q=Math[j];if("bigint"!=typeof t&&isNaN(t))throw new TypeError("Invalid number");if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,n,s,u,b,f,d){const p=t>0?(0).toPrecision(t):0;return b===l?0:(d||(d=i?c.symbol[e].bits[0]:c.symbol[e].bytes[0]),n[d]&&(d=n[d]),s&&(d=u[0]||c.fullform[e][0]+(i?"bit":o)),b===a?[p,d]:b===r?{value:p,symbol:d,exponent:0,unit:d}:p+f+d)}($,O,n,N,z,E,v,x);const{e:A,precision:C}=function(t,e,i,n,o){return(-1===e||isNaN(i))&&(e=n?Math.floor(Math.log(t)/p):Math.floor(Math.log(t)/d))<0&&(e=0),e>8&&(o>0&&(o+=8-e),e=8),{e:e,precision:o}}(w,k,S,Y,$);k=A;const F=-1===S||isNaN(S);if(v===l)return k;const{result:H,e:J}=y(w,k,Y,n,Z,F);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,B,q,F);if(G[0]=L.value,k=L.e,C>0){const t=function(t,e,i,n,o,a,r,s,l,u){let c=t.toPrecision(e);const b=-1===u||isNaN(u);if(c.includes("e")&&i<8&&b){i++;const{result:t}=y(n,i,o,a,r),u=l>0?Math.pow(10,l):1;c=(1===u?s(t):s(t*u)/u).toPrecision(e)}return{value:c,e:i}}(G[0],C,k,w,Y,n,Z,q,B,S);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=c.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,n,k,Y),G[1]=P,function(t,e,i,n,a,r,s,l,u,b,f,d,p){e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,l=a-s;r=`${i[0]}${e}${o.padEnd(s+l,"0")}`}return r}(t[0],n,a,r,s,l),u&&(t[1]=b[d]||c.fullform[f][d]+(p?"bit":o)+(1===t[0]?"":"s"))}(G,I,N,h,M,g,b,B,z,E,O,k,n),function(t,e,i,n,o){return n===a?t:n===r?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===o?`${t[0]} ${t[1]}`:t.join(o)}(G,k,P,v,x)}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:r="",spacer:l=" ",symbols:c={},standard:b="",output:f=s,fullform:d=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=u,precision:h=0}={}){return s=>B(s,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:r,spacer:l,symbols:c,standard:b,output:f,fullform:d,fullforms:p,exponent:m,roundingMethod:y,precision:h})}});//# sourceMappingURL=filesize.umd.min.js.map +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,function(t){"use strict";const e="iec",i="jedec",n="si",o="byte",a="array",r="object",s="string",c="exponent",l="round",u={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],f=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),p=Math.log(1e3),m={[n]:{isDecimal:!0,ceil:1e3,actualStandard:i},[e]:{isDecimal:!1,ceil:1024,actualStandard:e},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function y(t,e,i,n,o,a=!0){let r=t/(i?f[e]:b[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(t,{bits:n=!1,pad:b=!1,base:f=-1,round:B=2,locale:h="",localeOptions:M={},separator:g="",spacer:x=" ",symbols:N={},standard:T="",output:v=s,fullform:D=!1,fullforms:E=[],exponent:S=-1,roundingMethod:j=l,precision:$=0}={}){let k=S,w=Number(t),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(t,n){return m[t]?m[t]:2===n?{isDecimal:!1,ceil:1024,actualStandard:e}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(T,f),z=!0===D,I=w<0,q=Math[j];if("bigint"!=typeof t&&isNaN(t))throw new TypeError("Invalid number");if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,n,s,l,b,f,d){const p=t>0?(0).toPrecision(t):0;return b===c?0:(d||(d=i?u.symbol[e].bits[0]:u.symbol[e].bytes[0]),n[d]&&(d=n[d]),s&&(d=l[0]||u.fullform[e][0]+(i?"bit":o)),b===a?[p,d]:b===r?{value:p,symbol:d,exponent:0,unit:d}:p+f+d)}($,O,n,N,z,E,v,x);const{e:A,precision:C}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/p):Math.floor(Math.log(t)/d))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(w,k,0,Y,$);k=A;const F=-1===S||isNaN(S);if(v===c)return k;const{result:H,e:J}=y(w,k,Y,n,Z,F);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,B,q,F);if(G[0]=L.value,k=L.e,C>0){const t=function(t,e,i,n,o,a,r,s,c,l){let u=t.toPrecision(e);const b=-1===l||isNaN(l);if(u.includes("e")&&i<8&&b){i++;const{result:t}=y(n,i,o,a,r),l=c>0?Math.pow(10,c):1;u=(1===l?s(t):s(t*l)/l).toPrecision(e)}return{value:u,e:i}}(G[0],C,k,w,Y,n,Z,q,B,S);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=u.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,n,k,Y),G[1]=P,function(t,e,i,n,a,r,s,c,l,b,f,d,p){e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,c=a-s;r=`${i[0]}${e}${o.padEnd(s+c,"0")}`}return r}(t[0],n,a,r,s,c),l&&(t[1]=b[d]||u.fullform[f][d]+(p?"bit":o)+(1===t[0]?"":"s"))}(G,I,N,h,M,g,b,B,z,E,O,k,n),function(t,e,i,n,o){return n===a?t:n===r?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===o?`${t[0]} ${t[1]}`:t.join(o)}(G,k,P,v,x)}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:r="",spacer:c=" ",symbols:u={},standard:b="",output:f=s,fullform:d=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=l,precision:h=0}={}){return s=>B(s,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:r,spacer:c,symbols:u,standard:b,output:f,fullform:d,fullforms:p,exponent:m,roundingMethod:y,precision:h})}});//# sourceMappingURL=filesize.umd.min.js.map diff --git a/dist/filesize.umd.min.js.map b/dist/filesize.umd.min.js.map index 20c7f97..e395f04 100644 --- a/dist/filesize.umd.min.js.map +++ b/dist/filesize.umd.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(exponent)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\te = 8;\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,SAAA,CAAA,EAAA,CAAA,CAAAC,KAAA,SAAAP,GAAA,aACO,MAIMQ,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ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KC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASpC,EAAMS,SACfA,GAAW,EAAK4B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} +{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAA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,GDnUY,MCuUbV,EAAmB,GAAGT,EAAO,MAAMA,EAAO,KAAOA,EAAO+D,KAAKtD,EACrE,CCzLQuD,CAAahE,EAAQF,EAAGqB,EAAGP,EAAQH,EAC3C,CAiEA/C,EAAAM,SAAAA,EAAAN,EAAAuG,QArCO,UAAiBnF,KACvBA,GAAO,EAAKoB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASpC,EAAMS,SACfA,GAAW,EAAK4B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} diff --git a/src/helpers.js b/src/helpers.js index 4909869..49a45a1 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -339,7 +339,7 @@ export function decorateResult( * @param {Array} result - Result array with formatted value at [0] and symbol at [1] * @param {number} e - Current exponent * @param {string} u - Original resolved symbol (before custom override) - * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO) + * @param {number} output - Output type (ARRAY, OBJECT, STRING) * @param {string} spacer - String separator between value and unit * @returns {string|Array|Object|number} Formatted result in requested type */ diff --git a/types/helpers.d.ts b/types/helpers.d.ts index 088e4a3..b339854 100644 --- a/types/helpers.d.ts +++ b/types/helpers.d.ts @@ -229,7 +229,7 @@ export function decorateResult( * @param result - Result array with formatted value at [0] and symbol at [1] * @param e - Current exponent * @param u - Original resolved symbol (before custom override) - * @param output - Output type (ARRAY, OBJECT, STRING, EXPONENT) + * @param output - Output type (ARRAY, OBJECT, STRING) * @param spacer - String separator between value and unit * @returns Formatted result in requested type */ From 06253c3decfe08b3e6ef251044453323d0e6bcae Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 20:13:49 -0400 Subject: [PATCH 05/11] chore: rebuild dist --- dist/filesize.cjs | 2 +- dist/filesize.js | 2 +- dist/filesize.min.js.map | 2 +- dist/filesize.umd.js | 2 +- dist/filesize.umd.min.js.map | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/filesize.cjs b/dist/filesize.cjs index d6ba28c..e0051b0 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -404,7 +404,7 @@ function decorateResult( * @param {Array} result - Result array with formatted value at [0] and symbol at [1] * @param {number} e - Current exponent * @param {string} u - Original resolved symbol (before custom override) - * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO) + * @param {number} output - Output type (ARRAY, OBJECT, STRING) * @param {string} spacer - String separator between value and unit * @returns {string|Array|Object|number} Formatted result in requested type */ diff --git a/dist/filesize.js b/dist/filesize.js index 54780c8..865285f 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -400,7 +400,7 @@ function decorateResult( * @param {Array} result - Result array with formatted value at [0] and symbol at [1] * @param {number} e - Current exponent * @param {string} u - Original resolved symbol (before custom override) - * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO) + * @param {number} output - Output type (ARRAY, OBJECT, STRING) * @param {string} spacer - String separator between value and unit * @returns {string|Array|Object|number} Formatted result in requested type */ diff --git a/dist/filesize.min.js.map b/dist/filesize.min.js.map index 0cfbec2..91dfd82 100644 --- a/dist/filesize.min.js.map +++ b/dist/filesize.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;AACO,MAIMA,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,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AEhFiB,IACHtB,EAAO,GACNc,EAAUhB,IACVnB,EAAQM,SAASU,GAAgBG,IAAMhB,EDlUvB,MCkUoCT,IAAuB,IAAd2B,EAAO,GD/SlD,GAEJ,KC+SjB,CC/KC+D,CACC/D,EACAuB,EACAZ,EACAL,EACAE,EACAC,EACAN,EACAE,EACAiB,EACAR,EACAnB,EACAG,EACAhB,GD6KK,SAAsBkB,EAAQF,EAAGsB,EAAGP,EAAQH,GAClD,OAAIG,IAAWvC,EACP0B,EAGJa,IAAWtC,EACP,CACNoD,MAAO3B,EAAO,GACdpB,OAAQoB,EAAO,GACfe,SAAUjB,EACV+B,KAAMT,GDnUY,MCuUbV,EAAmB,GAAGV,EAAO,MAAMA,EAAO,KAAOA,EAAOgE,KAAKtD,EACrE,CCzLQuD,CAAajE,EAAQF,EAAGsB,EAAGP,EAAQH,EAC3C,CA4BO,SAASwD,GAAQpF,KACvBA,GAAO,EAAKqB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAiE"} +{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;AACO,MAIMA,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,C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EhFiB,IACHtB,EAAO,GACNc,EAAUhB,IACVnB,EAAQM,SAASU,GAAgBG,IAAMhB,EDlUvB,MCkUoCT,IAAuB,IAAd2B,EAAO,GD/SlD,GAEJ,KC+SjB,CC/KC+D,CACC/D,EACAuB,EACAZ,EACAL,EACAE,EACAC,EACAN,EACAE,EACAiB,EACAR,EACAnB,EACAG,EACAhB,GD6KK,SAAsBkB,EAAQF,EAAGsB,EAAGP,EAAQH,GAClD,OAAIG,IAAWvC,EACP0B,EAGJa,IAAWtC,EACP,CACNoD,MAAO3B,EAAO,GACdpB,OAAQoB,EAAO,GACfe,SAAUjB,EACV+B,KAAMT,GDnUY,MCuUbV,EAAmB,GAAGV,EAAO,MAAMA,EAAO,KAAOA,EAAOgE,KAAKtD,EACrE,CCzLQuD,CAAajE,EAAQF,EAAGsB,EAAGP,EAAQH,EAC3C,CA4BO,SAASwD,GAAQpF,KACvBA,GAAO,EAAKqB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAiE"} diff --git a/dist/filesize.umd.js b/dist/filesize.umd.js index 761ad9f..f2d970f 100644 --- a/dist/filesize.umd.js +++ b/dist/filesize.umd.js @@ -400,7 +400,7 @@ function decorateResult( * @param {Array} result - Result array with formatted value at [0] and symbol at [1] * @param {number} e - Current exponent * @param {string} u - Original resolved symbol (before custom override) - * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO) + * @param {number} output - Output type (ARRAY, OBJECT, STRING) * @param {string} spacer - String separator between value and unit * @returns {string|Array|Object|number} Formatted result in requested type */ diff --git a/dist/filesize.umd.min.js.map b/dist/filesize.umd.min.js.map index e395f04..392a1b5 100644 --- a/dist/filesize.umd.min.js.map +++ b/dist/filesize.umd.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING, EXPO)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAA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EAAQH,EAC3C,CAiEA/C,EAAAM,SAAAA,EAAAN,EAAAuG,QArCO,UAAiBnF,KACvBA,GAAO,EAAKoB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASpC,EAAMS,SACfA,GAAW,EAAK4B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} +{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,SAAA,CAAA,EAAA,CAAA,CAAAC,KAAA,SAAAP,GAAA,aACO,MAIMQ,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,CAC5B,EACA,KACA,QACA,WACA,cACA,gBACA,mBACA,oBACA,qBAGYC,EAAiB,CAC7B,EACA,IACA,IACA,IACA,KACA,KACA,KACA,KACA,MAIYC,EAAaC,KAAKC,IAAI,MACtBC,EAAcF,KAAKC,IAAI,KCrD9BE,EAAmB,CACxBpB,CAACA,GAAK,CAAEqB,WAAW,EAAMC,KAAM,IAAMC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AAsBkB,EAAQF,EAAGqB,EAAGP,EAAQH,GAClD,OAAIG,IAAWtC,EACP0B,EAGJY,IAAWrC,EACP,CACNmD,MAAO1B,EAAO,GACdpB,OAAQoB,EAAO,GACfc,SAAUhB,EACV8B,KAAMT,GDnUY,MCuUbV,EAAmB,GAAGT,EAAO,MAAMA,EAAO,KAAOA,EAAO+D,KAAKtD,EACrE,CCzLQuD,CAAahE,EAAQF,EAAGqB,EAAGP,EAAQH,EAC3C,CAiEA/C,EAAAM,SAAAA,EAAAN,EAAAuG,QArCO,UAAiBnF,KACvBA,GAAO,EAAKoB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASpC,EAAMS,SACfA,GAAW,EAAK4B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} From 945ae8810edffed98316f6054a73c2cb9fcddfa4 Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 20:17:26 -0400 Subject: [PATCH 06/11] docs: update AGENTS.md and TECHNICAL_DOCUMENTATION.md for delegate architecture --- AGENTS.md | 14 ++-- docs/TECHNICAL_DOCUMENTATION.md | 110 ++++++++++++++++++++++++++------ 2 files changed, 102 insertions(+), 22 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 01e6b38..1a3e07b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -80,12 +80,18 @@ Input → Validation → Standard Normalization → Exponent Calculation ### Key Components -1. **`filesize(arg, options)`**: Main conversion function -2. **`partial(options)`**: Creates pre-configured function +1. **`filesize(arg, options)`**: Orchestrator — delegates validation, exponent, value calc, rounding, formatting, and output dispatch +2. **`partial(options)`**: Creates pre-configured formatter with immutable frozen options 3. **`handleZeroValue()`**: Special handling for zero input -4. **`calculateOptimizedValue()`**: Core conversion logic -5. **`applyPrecisionHandling()`**: Precision + scientific notation fix +4. **`calculateOptimizedValue()`**: Core conversion logic with bits handling +5. **`applyPrecisionHandling()`**: Precision + scientific notation correction 6. **`applyNumberFormatting()`**: Locale, separator, padding +7. **`getBaseConfiguration()`**: Cached base/standard lookup table +8. **`calculateExponent()`**: Log-based exponent calculation with clamping +9. **`applyRounding()`**: Rounding + auto-increment ceiling adjustment +10. **`resolveSymbol()`**: Symbol table lookup with SI override for e=1 +11. **`decorateResult()`**: Negation, custom symbols, full form assembly +12. **`formatOutput()`**: Array/object/string output dispatch ### Standard Selection diff --git a/docs/TECHNICAL_DOCUMENTATION.md b/docs/TECHNICAL_DOCUMENTATION.md index b051424..e7aeccb 100644 --- a/docs/TECHNICAL_DOCUMENTATION.md +++ b/docs/TECHNICAL_DOCUMENTATION.md @@ -78,23 +78,29 @@ graph TB ```mermaid graph LR subgraph "filesize Library" - A[constants.js
Constants & Symbols] - B[filesize
Core Logic] - C[Types
TypeScript Definitions] + A[constants.js
Constants & Symbols] + B[filesize.js
Orchestrator
17 LOC pipeline] + C[helpers.js
10 Delegate Functions] + D[Types
TypeScript Definitions] end subgraph "External Dependencies" - D[Math Object
Rounding Functions] - E[Intl API
Localization] + E[Math Object
Rounding Functions] + F[Intl API
Localization] end A --> B - B --> D + A --> C + B --> C B --> E + B --> F + C --> E + C --> F style A fill:#d97706,stroke:#b45309,stroke-width:2px,color:#ffffff style B fill:#166534,stroke:#15803d,stroke-width:2px,color:#ffffff - style C fill:#1e40af,stroke:#1e3a8a,stroke-width:2px,color:#ffffff + style C fill:#1e40af,stroke:#15803d,stroke-width:2px,color:#ffffff + style D fill:#7c2d12,stroke:#92400e,stroke-width:2px,color:#ffffff ``` ## Mathematical Foundation @@ -331,7 +337,7 @@ flowchart TD Validate -->|Yes| ValidateRounding{Valid Rounding Method?} ValidateRounding -->|No| Error - ValidateRounding -->|Yes| Normalize[Normalize Base & Standard] + ValidateRounding -->|Yes| Normalize[Normalize Base & Standard
getBaseConfiguration] Normalize --> HandleNegative{Input < 0?} HandleNegative -->|Yes| FlipSign[Store negative flag, use absolute value] @@ -339,7 +345,7 @@ flowchart TD FlipSign --> CheckZero CheckZero -->|Yes| ZeroCase[Use handleZeroValue helper] - CheckZero -->|No| CalcExp[Calculate Exponent using logarithms] + CheckZero -->|No| CalcExp[Calculate Exponent
calculateExponent delegate] CalcExp --> CheckExp{Exponent > 8?} CheckExp -->|Yes| LimitExp[Limit to 8, Adjust Precision] @@ -347,30 +353,30 @@ flowchart TD LimitExp --> CheckExpOutput CheckExpOutput -->|Yes| ReturnExp[Return exponent value] - CheckExpOutput -->|No| CalcValue[Calculate value using optimized lookup
Includes bits conversion if needed] + CheckExpOutput -->|No| CalcValue[Calculate value
calculateOptimizedValue] - CalcValue --> Round[Apply Rounding with power of 10] - Round --> CheckOverflow{Value >= ceil & e < 8?} - CheckOverflow -->|Yes| Increment[Set value=1, increment exponent] + CalcValue --> Round[Apply Rounding
applyRounding delegate] + Round --> CheckOverflow{Value = ceil
Auto-increment?} + CheckOverflow -->|Yes| Increment[Set value=1,
increment exponent] CheckOverflow -->|No| CheckPrecision{Precision > 0?} Increment --> CheckPrecision - CheckPrecision -->|Yes| ApplyPrecision[Apply precision handling
Handle scientific notation] - CheckPrecision -->|No| GetSymbol[Lookup symbol from table] + CheckPrecision -->|Yes| ApplyPrecision[Apply precision
applyPrecisionHandling] + CheckPrecision -->|No| GetSymbol[Resolve symbol
resolveSymbol delegate] ApplyPrecision --> GetSymbol GetSymbol --> RestoreSign{Was negative?} - RestoreSign -->|Yes| ApplyNegative[Apply negative sign to value] + RestoreSign -->|Yes| ApplyNegative[Negate value] RestoreSign -->|No| CheckCustomSymbols{Custom symbols?} ApplyNegative --> CheckCustomSymbols CheckCustomSymbols -->|Yes| ApplySymbols[Apply custom symbols] - CheckCustomSymbols -->|No| FormatNumber[Apply number formatting
locale, separator, padding] + CheckCustomSymbols -->|No| FormatNumber[Apply number formatting
locale/separator/padding] ApplySymbols --> FormatNumber FormatNumber --> CheckFullForm{Full form enabled?} CheckFullForm -->|Yes| ExpandUnit[Use full unit names] - CheckFullForm -->|No| GenerateOutput[Generate output based on format] + CheckFullForm -->|No| GenerateOutput[Generate output by type] ExpandUnit --> GenerateOutput ZeroCase --> GenerateOutput @@ -432,6 +438,74 @@ Creates a partially applied function with preset options. **Returns:** Function +### Delegate Functions + +The library uses a pipeline of delegate functions to maintain a single `filesize()` orchestrator. This follows the **Single Responsibility Principle** — each delegate handles one concern. + +#### `calculateExponent(num, e, exponent, isDecimal, precision)` + +Calculates the exponent from the input value using `Math.log()`. Handles clamping (max 8), zero floor, and precision adjustment when exponent exceeds bounds. + +**Key behavior:** +- Auto-calculation (`e === -1` or `isNaN(e)`): uses logarithmic formula +- Clamps to `[0, 8]` range +- Adjusts precision count when `e > 8` (ensures meaningful digits for beyond-YiB values) + +#### `applyRounding(val, ceil, e, round, roundingFunc, autoExponent)` + +Applies rounding via a power-of-10 scale factor and handles auto-increment ceiling. + +**Key behavior:** +- Scales value by `10^round`, rounds, then divides back +- Auto-increments exponent when rounded value equals `ceil` (only in auto mode) +- Returns: `{ value, e }` + +#### `resolveSymbol(actualStandard, bits, e, isDecimal)` + +Resolves the unit symbol from the symbol table. Handles SI special case where exponent 1 always uses `kB`/`kbit` regardless of standard. + +**Returns:** `string` — resolved symbol + +#### `decorateResult(result, neg, symbols, locale, localeOptions, separator, pad, round, full, fullforms, actualStandard, e, bits)` + +Mutates the `result` array in-place. Applies negation, custom symbol overrides, locale/separator/padding formatting, and full form expansion. + +**Mutations:** +- `result[0]` → negated value + formatted number +- `result[1]` → potentially customized symbol + full unit name + +#### `formatOutput(result, e, u, output, spacer)` + +Dispatches the formatted result array into the requested output type. Handles `ARRAY`, `OBJECT`, and `STRING` (exponent is excluded — handled via early return in `filesize()`). + +**Key distinction:** `u` holds the **original** symbol before custom overrides; `result[1]` holds the **possibly overridden** symbol. The `OBJECT` output uses both: +- `symbol`: `result[1]` — what appears in string/array output +- `unit`: `u` — the base unit before customization + +#### `applyPrecisionHandling(value, precision, e, num, isDecimal, bits, ceil, roundingFunc, round, exponent)` + +Handles significant digit formatting via `Number.prototype.toPrecision()`. Corrects scientific notation by recalculating with incremented exponent. + +**Key behavior:** +- `toPrecision()` can produce strings like `"1e+21"` — if detected and `e < 8`, recalculates with `e + 1` +- Only auto-increments in auto-exponent mode + +#### `applyNumberFormatting(value, locale, localeOptions, separator, pad, round)` + +Applies locale-based formatting (`toLocaleString()`), custom decimal separator replacement, and zero-padding. Separators and decimals are resolved via the padding separator heuristic (skips leading minus sign for negative numbers). + +#### `calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent)` + +Divides by pre-computed power table. For bits mode, multiplies by 8 and auto-increments if result exceeds `ceil` (only in auto-exponent mode). + +#### `handleZeroValue(precision, actualStandard, bits, symbols, full, fullforms, output, spacer, symbol?)` + +Fast-path handling for zero input. Generates `0` (or `0.toPrecision(n)`) with appropriate base unit symbol and output formatting. + +#### `getBaseConfiguration(standard, base)` + +Cached lookup returning `{ isDecimal, ceil, actualStandard }`. Supports `"si"`, `"iec"`, `"jedec"` constants and base override `2`. + ### Configuration Options | Option | Type | Default | Description | From cdd336320023c84814b7c6c4e083fda961806c77 Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 20:26:18 -0400 Subject: [PATCH 07/11] fix: correct decorateResult/formatOutput types and JSDoc param types --- dist/filesize.cjs | 2 +- dist/filesize.js | 2 +- dist/filesize.min.js.map | 2 +- dist/filesize.umd.js | 2 +- dist/filesize.umd.min.js.map | 2 +- src/helpers.js | 2 +- types/helpers.d.ts | 13 +++++++------ 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/dist/filesize.cjs b/dist/filesize.cjs index e0051b0..746cb9c 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -404,7 +404,7 @@ function decorateResult( * @param {Array} result - Result array with formatted value at [0] and symbol at [1] * @param {number} e - Current exponent * @param {string} u - Original resolved symbol (before custom override) - * @param {number} output - Output type (ARRAY, OBJECT, STRING) + * @param {string} output - Output type (ARRAY, OBJECT, STRING) * @param {string} spacer - String separator between value and unit * @returns {string|Array|Object|number} Formatted result in requested type */ diff --git a/dist/filesize.js b/dist/filesize.js index 865285f..67be61b 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -400,7 +400,7 @@ function decorateResult( * @param {Array} result - Result array with formatted value at [0] and symbol at [1] * @param {number} e - Current exponent * @param {string} u - Original resolved symbol (before custom override) - * @param {number} output - Output type (ARRAY, OBJECT, STRING) + * @param {string} output - Output type (ARRAY, OBJECT, STRING) * @param {string} spacer - String separator between value and unit * @returns {string|Array|Object|number} Formatted result in requested type */ diff --git a/dist/filesize.min.js.map b/dist/filesize.min.js.map index 91dfd82..60007b6 100644 --- a/dist/filesize.min.js.map +++ b/dist/filesize.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;AACO,MAIMA,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,CAC5B,EACA,KACA,QACA,WACA,cACA,gBACA,mBACA,oBACA,qBAGYC,EAAiB,CAC7B,EACA,IACA,IACA,IACA,KACA,KACA,KACA,KACA,MAIYC,EAAaC,KAAKC,IAAI,MACtBC,EAAcF,KAAKC,IAAI,KCrD9BE,EAAmB,CACxBpB,CAACA,GAAK,CAAEqB,WAAW,EAAMC,KAAM,IAAMC,eAAgBxB,GACrDD,CAACA,GAAM,CAAEuB,WAAW,EAAOC,KAAM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AAWvC,EACP0B,EAGJa,IAAWtC,EACP,CACNoD,MAAO3B,EAAO,GACdpB,OAAQoB,EAAO,GACfe,SAAUjB,EACV+B,KAAMT,GDnUY,MCuUbV,EAAmB,GAAGV,EAAO,MAAMA,EAAO,KAAOA,EAAOgE,KAAKtD,EACrE,CCzLQuD,CAAajE,EAAQF,EAAGsB,EAAGP,EAAQH,EAC3C,CA4BO,SAASwD,GAAQpF,KACvBA,GAAO,EAAKqB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAiE"} +{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;AACO,MAIMA,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,CAC5B,EACA,KACA,QACA,WACA,cACA,gBACA,mBACA,oBACA,qBAGYC,EAAiB,CAC7B,EACA,IACA,IACA,IACA,KACA,KACA,KACA,KACA,MAIYC,EAAaC,KAAKC,IAAI,MACtBC,EAAcF,KAAKC,IAAI,KCrD9BE,EAAmB,CACxBpB,CAACA,GAAK,CAAEqB,WAAW,EAAMC,KAAM,IAAMC,eAAgBxB,GACrDD,CAACA,GAAM,CAAEuB,WAAW,EAAOC,KAAM,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AWvC,EACP0B,EAGJa,IAAWtC,EACP,CACNoD,MAAO3B,EAAO,GACdpB,OAAQoB,EAAO,GACfe,SAAUjB,EACV+B,KAAMT,GDnUY,MCuUbV,EAAmB,GAAGV,EAAO,MAAMA,EAAO,KAAOA,EAAOgE,KAAKtD,EACrE,CCzLQuD,CAAajE,EAAQF,EAAGsB,EAAGP,EAAQH,EAC3C,CA4BO,SAASwD,GAAQpF,KACvBA,GAAO,EAAKqB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAiE"} diff --git a/dist/filesize.umd.js b/dist/filesize.umd.js index f2d970f..5f51f08 100644 --- a/dist/filesize.umd.js +++ b/dist/filesize.umd.js @@ -400,7 +400,7 @@ function decorateResult( * @param {Array} result - Result array with formatted value at [0] and symbol at [1] * @param {number} e - Current exponent * @param {string} u - Original resolved symbol (before custom override) - * @param {number} output - Output type (ARRAY, OBJECT, STRING) + * @param {string} output - Output type (ARRAY, OBJECT, STRING) * @param {string} spacer - String separator between value and unit * @returns {string|Array|Object|number} Formatted result in requested type */ diff --git a/dist/filesize.umd.min.js.map b/dist/filesize.umd.min.js.map index 392a1b5..64e3cff 100644 --- a/dist/filesize.umd.min.js.map +++ b/dist/filesize.umd.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {number} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,SAAA,CAAA,EAAA,CAAA,CAAAC,KAAA,SAAAP,GAAA,aACO,MAIMQ,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS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MS,SACfA,GAAW,EAAK4B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} +{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,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AAAM,SAAAA,EAAAN,EAAAuG,QArCO,UAAiBnF,KACvBA,GAAO,EAAKoB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASpC,EAAMS,SACfA,GAAW,EAAK4B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} diff --git a/src/helpers.js b/src/helpers.js index 49a45a1..b7573dd 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -339,7 +339,7 @@ export function decorateResult( * @param {Array} result - Result array with formatted value at [0] and symbol at [1] * @param {number} e - Current exponent * @param {string} u - Original resolved symbol (before custom override) - * @param {number} output - Output type (ARRAY, OBJECT, STRING) + * @param {string} output - Output type (ARRAY, OBJECT, STRING) * @param {string} spacer - String separator between value and unit * @returns {string|Array|Object|number} Formatted result in requested type */ diff --git a/types/helpers.d.ts b/types/helpers.d.ts index b339854..e0e5e37 100644 --- a/types/helpers.d.ts +++ b/types/helpers.d.ts @@ -193,8 +193,9 @@ export function resolveSymbol( /** * Decorates the result: applies negation, custom symbols, number formatting, and full form names - * Mutates the result array in-place for both value (index 0) and symbol (index 1) - * @param result - Result array with numeric value at [0] and string symbol at [1] + * Mutates the result array in-place; result[0] becomes string | number via applyNumberFormatting(), + * result[1] may be updated for custom symbols or full form names + * @param result - Result array with value at [0] (string | number) and symbol at [1] (string) * @param neg - Whether the original input was negative * @param symbols - Custom symbol override map * @param locale - Locale string for formatting @@ -209,7 +210,7 @@ export function resolveSymbol( * @param bits - Whether formatting bit values */ export function decorateResult( - result: number[], + result: (number | string)[], neg: boolean, symbols: Record, locale: string | boolean, @@ -226,7 +227,7 @@ export function decorateResult( /** * Formats the computed result array into the requested output type - * @param result - Result array with formatted value at [0] and symbol at [1] + * @param result - Result array with formatted value at [0] (string | number) and symbol at [1] (string) * @param e - Current exponent * @param u - Original resolved symbol (before custom override) * @param output - Output type (ARRAY, OBJECT, STRING) @@ -234,9 +235,9 @@ export function decorateResult( * @returns Formatted result in requested type */ export function formatOutput( - result: number[], + result: (string | number)[], e: number, u: string, output: string, spacer: string -): string | number[] | { value: number | string; symbol: string; exponent: number; unit: string } | number; +): string | (string | number)[] | { value: string | number; symbol: string; exponent: number; unit: string }; From dce2e64f042c565019f5937a2a4c14c7ab654b0e Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 20:31:53 -0400 Subject: [PATCH 08/11] fix: parse result[0] as number before singular/plural check in fullform --- dist/filesize.cjs | 5 +++-- dist/filesize.js | 5 +++-- dist/filesize.min.js | 2 +- dist/filesize.min.js.map | 2 +- dist/filesize.umd.js | 5 +++-- dist/filesize.umd.min.js | 2 +- dist/filesize.umd.min.js.map | 2 +- src/helpers.js | 5 +++-- 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/dist/filesize.cjs b/dist/filesize.cjs index 746cb9c..b8805d6 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -393,9 +393,10 @@ function decorateResult( result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); if (full) { + const unit = bits ? BIT : BYTE; + const val = typeof result[0] === "string" ? parseFloat(result[0]) : result[0]; result[1] = - fullforms[e] || - STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); + fullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S); } } diff --git a/dist/filesize.js b/dist/filesize.js index 67be61b..465153b 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -389,9 +389,10 @@ function decorateResult( result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); if (full) { + const unit = bits ? BIT : BYTE; + const val = typeof result[0] === "string" ? parseFloat(result[0]) : result[0]; result[1] = - fullforms[e] || - STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); + fullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S); } } diff --git a/dist/filesize.min.js b/dist/filesize.min.js index 8f1ae97..24e0737 100644 --- a/dist/filesize.min.js +++ b/dist/filesize.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.15 */ -const t="iec",e="jedec",i="si",n="byte",o="array",a="object",r="string",s="exponent",c="round",l={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},u=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],b=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),f=Math.log(1e3),p={[i]:{isDecimal:!0,ceil:1e3,actualStandard:e},[t]:{isDecimal:!1,ceil:1024,actualStandard:t},[e]:{isDecimal:!1,ceil:1024,actualStandard:e}};function m(t,e,i,n,o,a=!0){let r=t/(i?b[e]:u[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(i,{bits:u=!1,pad:b=!1,base:B=-1,round:y=2,locale:M="",localeOptions:h={},separator:g="",spacer:x=" ",symbols:N={},standard:v="",output:D=r,fullform:E=!1,fullforms:S=[],exponent:T=-1,roundingMethod:$=c,precision:j=0}={}){let k=T,w=Number(i),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(i,n){return p[i]?p[i]:2===n?{isDecimal:!1,ceil:1024,actualStandard:t}:{isDecimal:!0,ceil:1e3,actualStandard:e}}(v,B),z=!0===E,I=w<0,q=Math[$];if("bigint"!=typeof i&&isNaN(i))throw new TypeError("Invalid number");if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,r,c,u,b,d,f){const p=t>0?(0).toPrecision(t):0;return b===s?0:(f||(f=i?l.symbol[e].bits[0]:l.symbol[e].bytes[0]),r[f]&&(f=r[f]),c&&(f=u[0]||l.fullform[e][0]+(i?"bit":n)),b===o?[p,f]:b===a?{value:p,symbol:f,exponent:0,unit:f}:p+d+f)}(j,O,u,N,z,S,D,x);const{e:A,precision:C}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/f):Math.floor(Math.log(t)/d))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(w,k,0,Y,j);k=A;const F=-1===T||isNaN(T);if(D===s)return k;const{result:H,e:J}=m(w,k,Y,u,Z,F);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,y,q,F);if(G[0]=L.value,k=L.e,C>0){const t=function(t,e,i,n,o,a,r,s,c,l){let u=t.toPrecision(e);const b=-1===l||isNaN(l);if(u.includes("e")&&i<8&&b){i++;const{result:t}=m(n,i,o,a,r),l=c>0?Math.pow(10,c):1;u=(1===l?s(t):s(t*l)/l).toPrecision(e)}return{value:u,e:i}}(G[0],C,k,w,Y,u,Z,q,y,T);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=l.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,u,k,Y),G[1]=P,function(t,e,i,o,a,r,s,c,u,b,d,f,p){e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,c=a-s;r=`${i[0]}${e}${o.padEnd(s+c,"0")}`}return r}(t[0],o,a,r,s,c),u&&(t[1]=b[f]||l.fullform[d][f]+(p?"bit":n)+(1===t[0]?"":"s"))}(G,I,N,M,h,g,b,y,z,S,O,k,u),function(t,e,i,n,r){return n===o?t:n===a?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===r?`${t[0]} ${t[1]}`:t.join(r)}(G,k,P,D,x)}function y({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:s="",spacer:l=" ",symbols:u={},standard:b="",output:d=r,fullform:f=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=c,precision:M=0}={}){return r=>B(r,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:s,spacer:l,symbols:u,standard:b,output:d,fullform:f,fullforms:p,exponent:m,roundingMethod:y,precision:M})}export{B as filesize,y as partial};//# sourceMappingURL=filesize.min.js.map +const t="iec",e="jedec",i="si",n="byte",o="array",a="object",r="string",s="exponent",c="round",l={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},u=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],b=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),f=Math.log(1e3),p={[i]:{isDecimal:!0,ceil:1e3,actualStandard:e},[t]:{isDecimal:!1,ceil:1024,actualStandard:t},[e]:{isDecimal:!1,ceil:1024,actualStandard:e}};function m(t,e,i,n,o,a=!0){let r=t/(i?b[e]:u[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(i,{bits:u=!1,pad:b=!1,base:B=-1,round:y=2,locale:M="",localeOptions:h={},separator:g="",spacer:x=" ",symbols:N={},standard:v="",output:D=r,fullform:E=!1,fullforms:S=[],exponent:T=-1,roundingMethod:$=c,precision:j=0}={}){let k=T,w=Number(i),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(i,n){return p[i]?p[i]:2===n?{isDecimal:!1,ceil:1024,actualStandard:t}:{isDecimal:!0,ceil:1e3,actualStandard:e}}(v,B),z=!0===E,I=w<0,F=Math[$];if("bigint"!=typeof i&&isNaN(i))throw new TypeError("Invalid number");if("function"!=typeof F)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,r,c,u,b,d,f){const p=t>0?(0).toPrecision(t):0;return b===s?0:(f||(f=i?l.symbol[e].bits[0]:l.symbol[e].bytes[0]),r[f]&&(f=r[f]),c&&(f=u[0]||l.fullform[e][0]+(i?"bit":n)),b===o?[p,f]:b===a?{value:p,symbol:f,exponent:0,unit:f}:p+d+f)}(j,O,u,N,z,S,D,x);const{e:q,precision:A}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/f):Math.floor(Math.log(t)/d))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(w,k,0,Y,j);k=q;const C=-1===T||isNaN(T);if(D===s)return k;const{result:H,e:J}=m(w,k,Y,u,Z,C);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,y,F,C);if(G[0]=L.value,k=L.e,A>0){const t=function(t,e,i,n,o,a,r,s,c,l){let u=t.toPrecision(e);const b=-1===l||isNaN(l);if(u.includes("e")&&i<8&&b){i++;const{result:t}=m(n,i,o,a,r),l=c>0?Math.pow(10,c):1;u=(1===l?s(t):s(t*l)/l).toPrecision(e)}return{value:u,e:i}}(G[0],A,k,w,Y,u,Z,F,y,T);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=l.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,u,k,Y),G[1]=P,function(t,e,i,o,a,r,s,c,u,b,d,f,p){if(e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,c=a-s;r=`${i[0]}${e}${o.padEnd(s+c,"0")}`}return r}(t[0],o,a,r,s,c),u){const e=p?"bit":n,i="string"==typeof t[0]?parseFloat(t[0]):t[0];t[1]=b[f]||l.fullform[d][f]+e+(1===i?"":"s")}}(G,I,N,M,h,g,b,y,z,S,O,k,u),function(t,e,i,n,r){return n===o?t:n===a?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===r?`${t[0]} ${t[1]}`:t.join(r)}(G,k,P,D,x)}function y({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:s="",spacer:l=" ",symbols:u={},standard:b="",output:d=r,fullform:f=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=c,precision:M=0}={}){return r=>B(r,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:s,spacer:l,symbols:u,standard:b,output:d,fullform:f,fullforms:p,exponent:m,roundingMethod:y,precision:M})}export{B as filesize,y as partial};//# sourceMappingURL=filesize.min.js.map diff --git a/dist/filesize.min.js.map b/dist/filesize.min.js.map index 60007b6..e993ec4 100644 --- a/dist/filesize.min.js.map +++ b/dist/filesize.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;AACO,MAIMA,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EA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A,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAiE"} +{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tconst unit = bits ? BIT : BYTE;\n\t\tconst val = typeof result[0] === \"string\" ? parseFloat(result[0]) : result[0];\n\t\tresult[1] =\n\t\t\tfullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","parseFloat","decorateResult","join","formatOutput","partial"],"mappings":";;;;AACO,MAIMA,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,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,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAkE"} diff --git a/dist/filesize.umd.js b/dist/filesize.umd.js index 5f51f08..83afa9f 100644 --- a/dist/filesize.umd.js +++ b/dist/filesize.umd.js @@ -389,9 +389,10 @@ function decorateResult( result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); if (full) { + const unit = bits ? BIT : BYTE; + const val = typeof result[0] === "string" ? parseFloat(result[0]) : result[0]; result[1] = - fullforms[e] || - STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); + fullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S); } } diff --git a/dist/filesize.umd.min.js b/dist/filesize.umd.min.js index 6917d3c..705e50b 100644 --- a/dist/filesize.umd.min.js +++ b/dist/filesize.umd.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.15 */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,function(t){"use strict";const e="iec",i="jedec",n="si",o="byte",a="array",r="object",s="string",c="exponent",l="round",u={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],f=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),p=Math.log(1e3),m={[n]:{isDecimal:!0,ceil:1e3,actualStandard:i},[e]:{isDecimal:!1,ceil:1024,actualStandard:e},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function y(t,e,i,n,o,a=!0){let r=t/(i?f[e]:b[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(t,{bits:n=!1,pad:b=!1,base:f=-1,round:B=2,locale:h="",localeOptions:M={},separator:g="",spacer:x=" ",symbols:N={},standard:T="",output:v=s,fullform:D=!1,fullforms:E=[],exponent:S=-1,roundingMethod:j=l,precision:$=0}={}){let k=S,w=Number(t),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(t,n){return m[t]?m[t]:2===n?{isDecimal:!1,ceil:1024,actualStandard:e}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(T,f),z=!0===D,I=w<0,q=Math[j];if("bigint"!=typeof t&&isNaN(t))throw new TypeError("Invalid number");if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,n,s,l,b,f,d){const p=t>0?(0).toPrecision(t):0;return b===c?0:(d||(d=i?u.symbol[e].bits[0]:u.symbol[e].bytes[0]),n[d]&&(d=n[d]),s&&(d=l[0]||u.fullform[e][0]+(i?"bit":o)),b===a?[p,d]:b===r?{value:p,symbol:d,exponent:0,unit:d}:p+f+d)}($,O,n,N,z,E,v,x);const{e:A,precision:C}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/p):Math.floor(Math.log(t)/d))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(w,k,0,Y,$);k=A;const F=-1===S||isNaN(S);if(v===c)return k;const{result:H,e:J}=y(w,k,Y,n,Z,F);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,B,q,F);if(G[0]=L.value,k=L.e,C>0){const t=function(t,e,i,n,o,a,r,s,c,l){let u=t.toPrecision(e);const b=-1===l||isNaN(l);if(u.includes("e")&&i<8&&b){i++;const{result:t}=y(n,i,o,a,r),l=c>0?Math.pow(10,c):1;u=(1===l?s(t):s(t*l)/l).toPrecision(e)}return{value:u,e:i}}(G[0],C,k,w,Y,n,Z,q,B,S);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=u.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,n,k,Y),G[1]=P,function(t,e,i,n,a,r,s,c,l,b,f,d,p){e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,c=a-s;r=`${i[0]}${e}${o.padEnd(s+c,"0")}`}return r}(t[0],n,a,r,s,c),l&&(t[1]=b[d]||u.fullform[f][d]+(p?"bit":o)+(1===t[0]?"":"s"))}(G,I,N,h,M,g,b,B,z,E,O,k,n),function(t,e,i,n,o){return n===a?t:n===r?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===o?`${t[0]} ${t[1]}`:t.join(o)}(G,k,P,v,x)}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:r="",spacer:c=" ",symbols:u={},standard:b="",output:f=s,fullform:d=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=l,precision:h=0}={}){return s=>B(s,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:r,spacer:c,symbols:u,standard:b,output:f,fullform:d,fullforms:p,exponent:m,roundingMethod:y,precision:h})}});//# sourceMappingURL=filesize.umd.min.js.map +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,function(t){"use strict";const e="iec",i="jedec",n="si",o="byte",a="array",r="object",s="string",c="exponent",l="round",u={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],f=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),p=Math.log(1e3),m={[n]:{isDecimal:!0,ceil:1e3,actualStandard:i},[e]:{isDecimal:!1,ceil:1024,actualStandard:e},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function y(t,e,i,n,o,a=!0){let r=t/(i?f[e]:b[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(t,{bits:n=!1,pad:b=!1,base:f=-1,round:B=2,locale:h="",localeOptions:M={},separator:g="",spacer:x=" ",symbols:N={},standard:T="",output:v=s,fullform:D=!1,fullforms:E=[],exponent:S=-1,roundingMethod:j=l,precision:$=0}={}){let k=S,w=Number(t),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(t,n){return m[t]?m[t]:2===n?{isDecimal:!1,ceil:1024,actualStandard:e}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(T,f),z=!0===D,I=w<0,F=Math[j];if("bigint"!=typeof t&&isNaN(t))throw new TypeError("Invalid number");if("function"!=typeof F)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,n,s,l,b,f,d){const p=t>0?(0).toPrecision(t):0;return b===c?0:(d||(d=i?u.symbol[e].bits[0]:u.symbol[e].bytes[0]),n[d]&&(d=n[d]),s&&(d=l[0]||u.fullform[e][0]+(i?"bit":o)),b===a?[p,d]:b===r?{value:p,symbol:d,exponent:0,unit:d}:p+f+d)}($,O,n,N,z,E,v,x);const{e:q,precision:A}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/p):Math.floor(Math.log(t)/d))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(w,k,0,Y,$);k=q;const C=-1===S||isNaN(S);if(v===c)return k;const{result:H,e:J}=y(w,k,Y,n,Z,C);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,B,F,C);if(G[0]=L.value,k=L.e,A>0){const t=function(t,e,i,n,o,a,r,s,c,l){let u=t.toPrecision(e);const b=-1===l||isNaN(l);if(u.includes("e")&&i<8&&b){i++;const{result:t}=y(n,i,o,a,r),l=c>0?Math.pow(10,c):1;u=(1===l?s(t):s(t*l)/l).toPrecision(e)}return{value:u,e:i}}(G[0],A,k,w,Y,n,Z,F,B,S);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=u.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,n,k,Y),G[1]=P,function(t,e,i,n,a,r,s,c,l,b,f,d,p){if(e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,c=a-s;r=`${i[0]}${e}${o.padEnd(s+c,"0")}`}return r}(t[0],n,a,r,s,c),l){const e=p?"bit":o,i="string"==typeof t[0]?parseFloat(t[0]):t[0];t[1]=b[d]||u.fullform[f][d]+e+(1===i?"":"s")}}(G,I,N,h,M,g,b,B,z,E,O,k,n),function(t,e,i,n,o){return n===a?t:n===r?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===o?`${t[0]} ${t[1]}`:t.join(o)}(G,k,P,v,x)}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:r="",spacer:c=" ",symbols:u={},standard:b="",output:f=s,fullform:d=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=l,precision:h=0}={}){return s=>B(s,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:r,spacer:c,symbols:u,standard:b,output:f,fullform:d,fullforms:p,exponent:m,roundingMethod:y,precision:h})}});//# sourceMappingURL=filesize.umd.min.js.map diff --git a/dist/filesize.umd.min.js.map b/dist/filesize.umd.min.js.map index 64e3cff..bc15f12 100644 --- a/dist/filesize.umd.min.js.map +++ b/dist/filesize.umd.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tresult[1] =\n\t\t\tfullforms[e] ||\n\t\t\tSTRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,SAAA,CAAA,EAAA,CAAA,CAAAC,KAAA,SAAAP,GAAA,aACO,MAIMQ,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MA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W,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} +{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tconst unit = bits ? BIT : BYTE;\n\t\tconst val = typeof result[0] === \"string\" ? parseFloat(result[0]) : result[0];\n\t\tresult[1] =\n\t\t\tfullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","parseFloat","decorateResult","join","formatOutput","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO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,KAAOA,EAAOgE,KAAKvD,EACrE,CC1LQwD,CAAajE,EAAQF,EAAGqB,EAAGP,EAAQH,EAC3C,CAiEA/C,EAAAM,SAAAA,EAAAN,EAAAwG,QArCO,UAAiBpF,KACvBA,GAAO,EAAKoB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASpC,EAAMS,SACfA,GAAW,EAAK4B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} diff --git a/src/helpers.js b/src/helpers.js index b7573dd..479f754 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -328,9 +328,10 @@ export function decorateResult( result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); if (full) { + const unit = bits ? BIT : BYTE; + const val = typeof result[0] === "string" ? parseFloat(result[0]) : result[0]; result[1] = - fullforms[e] || - STRINGS.fullform[actualStandard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S); + fullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S); } } From 43069a048d65a14c18d514b1f48742431adf9165 Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 20:48:13 -0400 Subject: [PATCH 09/11] fix: cover edge cases and fix Infinity/BigInt/partial immutability --- coverage.txt | 4 +- dist/filesize.cjs | 42 ++++++++++++----- dist/filesize.js | 42 ++++++++++++----- dist/filesize.min.js | 2 +- dist/filesize.min.js.map | 2 +- dist/filesize.umd.js | 42 ++++++++++++----- dist/filesize.umd.min.js | 2 +- dist/filesize.umd.min.js.map | 2 +- src/filesize.js | 38 ++++++++++----- src/helpers.js | 4 ++ tests/unit/filesize-helpers.test.js | 71 +++++++++++++++++++++++++++++ tests/unit/filesize.test.js | 60 ++++++++++++++++++++++++ 12 files changed, 261 insertions(+), 50 deletions(-) diff --git a/coverage.txt b/coverage.txt index 869a960..2fd0754 100644 --- a/coverage.txt +++ b/coverage.txt @@ -5,8 +5,8 @@ ℹ src | | | | ℹ constants.js | 100.00 | 100.00 | 100.00 | ℹ filesize.js | 100.00 | 100.00 | 100.00 | -ℹ helpers.js | 100.00 | 100.00 | 100.00 | +ℹ helpers.js | 100.00 | 98.96 | 100.00 | ℹ -------------------------------------------------------------- -ℹ all files | 100.00 | 100.00 | 100.00 | +ℹ all files | 100.00 | 99.13 | 100.00 | ℹ -------------------------------------------------------------- ℹ end of coverage report diff --git a/dist/filesize.cjs b/dist/filesize.cjs index b8805d6..4a59b94 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -228,6 +228,10 @@ function applyPrecisionHandling( round, exponent, ) { + if (typeof value === "string") { + value = parseFloat(value); + } + let result = value.toPrecision(precision); const autoExponent = exponent === -1 || isNaN(exponent); @@ -475,21 +479,31 @@ function filesize( } = {}, ) { let e = exponent, - num = Number(arg), + num, result = [], val = 0, u = EMPTY; + if (typeof arg === "bigint") { + num = Number(arg); + } else { + num = Number(arg); + + if (isNaN(arg)) { + throw new TypeError(INVALID_NUMBER); + } + + if (!isFinite(num)) { + throw new TypeError(INVALID_NUMBER); + } + } + const { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base); const full = fullform === true, neg = num < 0, roundingFunc = Math[roundingMethod]; - if (typeof arg !== "bigint" && isNaN(arg)) { - throw new TypeError(INVALID_NUMBER); - } - if (typeof roundingFunc !== FUNCTION) { throw new TypeError(INVALID_ROUND); } @@ -614,18 +628,24 @@ function partial({ base = -1, round = 2, locale = EMPTY, - localeOptions = {}, separator = EMPTY, spacer = SPACE, - symbols = {}, standard = EMPTY, output = STRING, fullform = false, - fullforms = [], exponent = -1, roundingMethod = ROUND, precision = 0, + localeOptions = {}, + symbols = {}, + fullforms = [], } = {}) { + const cloned = { + localeOptions: JSON.parse(JSON.stringify(localeOptions)), + symbols: JSON.parse(JSON.stringify(symbols)), + fullforms: JSON.parse(JSON.stringify(fullforms)), + }; + return (arg) => filesize(arg, { bits, @@ -633,14 +653,14 @@ function partial({ base, round, locale, - localeOptions, + localeOptions: cloned.localeOptions, separator, spacer, - symbols, + symbols: cloned.symbols, standard, output, fullform, - fullforms, + fullforms: cloned.fullforms, exponent, roundingMethod, precision, diff --git a/dist/filesize.js b/dist/filesize.js index 465153b..5b36fb6 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -224,6 +224,10 @@ function applyPrecisionHandling( round, exponent, ) { + if (typeof value === "string") { + value = parseFloat(value); + } + let result = value.toPrecision(precision); const autoExponent = exponent === -1 || isNaN(exponent); @@ -469,21 +473,31 @@ function filesize( } = {}, ) { let e = exponent, - num = Number(arg), + num, result = [], val = 0, u = EMPTY; + if (typeof arg === "bigint") { + num = Number(arg); + } else { + num = Number(arg); + + if (isNaN(arg)) { + throw new TypeError(INVALID_NUMBER); + } + + if (!isFinite(num)) { + throw new TypeError(INVALID_NUMBER); + } + } + const { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base); const full = fullform === true, neg = num < 0, roundingFunc = Math[roundingMethod]; - if (typeof arg !== "bigint" && isNaN(arg)) { - throw new TypeError(INVALID_NUMBER); - } - if (typeof roundingFunc !== FUNCTION) { throw new TypeError(INVALID_ROUND); } @@ -608,18 +622,24 @@ function partial({ base = -1, round = 2, locale = EMPTY, - localeOptions = {}, separator = EMPTY, spacer = SPACE, - symbols = {}, standard = EMPTY, output = STRING, fullform = false, - fullforms = [], exponent = -1, roundingMethod = ROUND, precision = 0, + localeOptions = {}, + symbols = {}, + fullforms = [], } = {}) { + const cloned = { + localeOptions: JSON.parse(JSON.stringify(localeOptions)), + symbols: JSON.parse(JSON.stringify(symbols)), + fullforms: JSON.parse(JSON.stringify(fullforms)), + }; + return (arg) => filesize(arg, { bits, @@ -627,14 +647,14 @@ function partial({ base, round, locale, - localeOptions, + localeOptions: cloned.localeOptions, separator, spacer, - symbols, + symbols: cloned.symbols, standard, output, fullform, - fullforms, + fullforms: cloned.fullforms, exponent, roundingMethod, precision, diff --git a/dist/filesize.min.js b/dist/filesize.min.js index 24e0737..12dda0b 100644 --- a/dist/filesize.min.js +++ b/dist/filesize.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.15 */ -const t="iec",e="jedec",i="si",n="byte",o="array",a="object",r="string",s="exponent",c="round",l={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},u=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],b=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),f=Math.log(1e3),p={[i]:{isDecimal:!0,ceil:1e3,actualStandard:e},[t]:{isDecimal:!1,ceil:1024,actualStandard:t},[e]:{isDecimal:!1,ceil:1024,actualStandard:e}};function m(t,e,i,n,o,a=!0){let r=t/(i?b[e]:u[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(i,{bits:u=!1,pad:b=!1,base:B=-1,round:y=2,locale:M="",localeOptions:h={},separator:g="",spacer:x=" ",symbols:N={},standard:v="",output:D=r,fullform:E=!1,fullforms:S=[],exponent:T=-1,roundingMethod:$=c,precision:j=0}={}){let k=T,w=Number(i),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(i,n){return p[i]?p[i]:2===n?{isDecimal:!1,ceil:1024,actualStandard:t}:{isDecimal:!0,ceil:1e3,actualStandard:e}}(v,B),z=!0===E,I=w<0,F=Math[$];if("bigint"!=typeof i&&isNaN(i))throw new TypeError("Invalid number");if("function"!=typeof F)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,r,c,u,b,d,f){const p=t>0?(0).toPrecision(t):0;return b===s?0:(f||(f=i?l.symbol[e].bits[0]:l.symbol[e].bytes[0]),r[f]&&(f=r[f]),c&&(f=u[0]||l.fullform[e][0]+(i?"bit":n)),b===o?[p,f]:b===a?{value:p,symbol:f,exponent:0,unit:f}:p+d+f)}(j,O,u,N,z,S,D,x);const{e:q,precision:A}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/f):Math.floor(Math.log(t)/d))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(w,k,0,Y,j);k=q;const C=-1===T||isNaN(T);if(D===s)return k;const{result:H,e:J}=m(w,k,Y,u,Z,C);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,y,F,C);if(G[0]=L.value,k=L.e,A>0){const t=function(t,e,i,n,o,a,r,s,c,l){let u=t.toPrecision(e);const b=-1===l||isNaN(l);if(u.includes("e")&&i<8&&b){i++;const{result:t}=m(n,i,o,a,r),l=c>0?Math.pow(10,c):1;u=(1===l?s(t):s(t*l)/l).toPrecision(e)}return{value:u,e:i}}(G[0],A,k,w,Y,u,Z,F,y,T);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=l.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,u,k,Y),G[1]=P,function(t,e,i,o,a,r,s,c,u,b,d,f,p){if(e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,c=a-s;r=`${i[0]}${e}${o.padEnd(s+c,"0")}`}return r}(t[0],o,a,r,s,c),u){const e=p?"bit":n,i="string"==typeof t[0]?parseFloat(t[0]):t[0];t[1]=b[f]||l.fullform[d][f]+e+(1===i?"":"s")}}(G,I,N,M,h,g,b,y,z,S,O,k,u),function(t,e,i,n,r){return n===o?t:n===a?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===r?`${t[0]} ${t[1]}`:t.join(r)}(G,k,P,D,x)}function y({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:s="",spacer:l=" ",symbols:u={},standard:b="",output:d=r,fullform:f=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=c,precision:M=0}={}){return r=>B(r,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:s,spacer:l,symbols:u,standard:b,output:d,fullform:f,fullforms:p,exponent:m,roundingMethod:y,precision:M})}export{B as filesize,y as partial};//# sourceMappingURL=filesize.min.js.map +const t="Invalid number",e="iec",i="jedec",n="si",o="byte",r="array",a="object",s="string",l="exponent",c="round",u={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],f=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],p=Math.log(1024),d=Math.log(1e3),m={[n]:{isDecimal:!0,ceil:1e3,actualStandard:i},[e]:{isDecimal:!1,ceil:1024,actualStandard:e},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function y(t,e,i,n,o,r=!0){let a=t/(i?f[e]:b[e]);return n&&(a*=8,r&&a>=o&&e<8&&(a/=o,e++)),{result:a,e:e}}function B(n,{bits:b=!1,pad:f=!1,base:B=-1,round:h=2,locale:M="",localeOptions:N={},separator:g="",spacer:S=" ",symbols:x={},standard:O="",output:E=s,fullform:T=!1,fullforms:v=[],exponent:w=-1,roundingMethod:D=c,precision:J=0}={}){let $,j=w,k=[],G=0,K="";if("bigint"==typeof n)$=Number(n);else{if($=Number(n),isNaN(n))throw new TypeError(t);if(!isFinite($))throw new TypeError(t)}const{isDecimal:P,ceil:Y,actualStandard:Z}=function(t,n){return m[t]?m[t]:2===n?{isDecimal:!1,ceil:1024,actualStandard:e}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(O,B),F=!0===T,z=$<0,I=Math[D];if("function"!=typeof I)throw new TypeError("Invalid rounding method");if(z&&($=-$),0===$)return function(t,e,i,n,s,c,b,f,p){const d=t>0?(0).toPrecision(t):0;return b===l?0:(p||(p=i?u.symbol[e].bits[0]:u.symbol[e].bytes[0]),n[p]&&(p=n[p]),s&&(p=c[0]||u.fullform[e][0]+(i?"bit":o)),b===r?[d,p]:b===a?{value:d,symbol:p,exponent:0,unit:p}:d+f+p)}(J,Z,b,x,F,v,E,S);const{e:q,precision:A}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/d):Math.floor(Math.log(t)/p))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}($,j,0,P,J);j=q;const C=-1===w||isNaN(w);if(E===l)return j;const{result:H,e:L}=y($,j,P,b,Y,C);G=H,j=L;const Q=function(t,e,i,n,o,r){const a=i>0&&n>0?Math.pow(10,n):1;let s=1===a?o(t):o(t*a)/a;return s===e&&i<8&&r&&(s=1,i++),{value:s,e:i}}(G,Y,j,h,I,C);if(k[0]=Q.value,j=Q.e,A>0){const t=function(t,e,i,n,o,r,a,s,l,c){"string"==typeof t&&(t=parseFloat(t));let u=t.toPrecision(e);const b=-1===c||isNaN(c);if(u.includes("e")&&i<8&&b){i++;const{result:t}=y(n,i,o,r,a),c=l>0?Math.pow(10,l):1;u=(1===c?s(t):s(t*c)/c).toPrecision(e)}return{value:u,e:i}}(k[0],A,j,$,P,b,Y,I,h,w);k[0]=t.value,j=t.e}return K=function(t,e,i,n){const o=u.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(Z,b,j,P),k[1]=K,function(t,e,i,n,r,a,s,l,c,b,f,p,d){if(e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,r){let a=t;if(!0===e?a=a.toLocaleString():e.length>0?a=a.toLocaleString(e,i):n.length>0&&(a=a.toString().replace(".",n)),o&&r>0){const t=a.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,l=r-s;a=`${i[0]}${e}${o.padEnd(s+l,"0")}`}return a}(t[0],n,r,a,s,l),c){const e=d?"bit":o,i="string"==typeof t[0]?parseFloat(t[0]):t[0];t[1]=b[p]||u.fullform[f][p]+e+(1===i?"":"s")}}(k,z,x,M,N,g,f,h,F,v,Z,j,b),function(t,e,i,n,o){return n===r?t:n===a?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===o?`${t[0]} ${t[1]}`:t.join(o)}(k,j,K,E,S)}function h({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",separator:r="",spacer:a=" ",standard:l="",output:u=s,fullform:b=!1,exponent:f=-1,roundingMethod:p=c,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){const M={localeOptions:JSON.parse(JSON.stringify(m)),symbols:JSON.parse(JSON.stringify(y)),fullforms:JSON.parse(JSON.stringify(h))};return s=>B(s,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:M.localeOptions,separator:r,spacer:a,symbols:M.symbols,standard:l,output:u,fullform:b,fullforms:M.fullforms,exponent:f,roundingMethod:p,precision:d})}export{B as filesize,h as partial};//# sourceMappingURL=filesize.min.js.map diff --git a/dist/filesize.min.js.map b/dist/filesize.min.js.map index e993ec4..140608c 100644 --- a/dist/filesize.min.js.map +++ b/dist/filesize.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tconst unit = bits ? BIT : BYTE;\n\t\tconst val = typeof result[0] === \"string\" ? parseFloat(result[0]) : result[0];\n\t\tresult[1] =\n\t\t\tfullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","parseFloat","decorateResult","join","formatOutput","partial"],"mappings":";;;;AACO,MAIMA,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,CAC5B,EACA,KACA,QACA,WACA,cACA,gBACA,mBACA,oBACA,qBAGYC,EAAiB,CAC7B,EACA,IACA,IACA,IACA,KACA,KACA,KACA,KACA,MAIYC,EAAaC,KAAKC,IAAI,MACtBC,EAAcF,KAAKC,IAAI,KCrD9BE,EAAmB,CACxBpB,CAACA,GAAK,CAAEqB,WAAW,EAAMC,KAAM,IAAMC,eAAgBxB,GACrDD,CAACA,GAAM,CAAEuB,WAAW,EAAOC,KAAM,KAAMC,eAAgBzB,GACvDC,CAACA,GAAQ,CAAEsB,WAAW,EAAOC,KAAM,KAAMC,eAAgBxB,IA6FnD,SAASyB,EAAwBC,EAAKC,EAAGL,EAAWX,EAAMY,EAAMK,GAAe,GAErF,IAAIC,EAASH,GADHJ,EAAYN,EAAeW,GAAKZ,EAAcY,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Y,MCwUbV,EAAmB,GAAGV,EAAO,MAAMA,EAAO,KAAOA,EAAOiE,KAAKvD,EACrE,CC1LQwD,CAAalE,EAAQF,EAAGsB,EAAGP,EAAQH,EAC3C,CA4BO,SAASyD,GAAQrF,KACvBA,GAAO,EAAKqB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK6B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA5B,WACA6B,YACAC,WACAC,iBACAC,aAEH,QAAAhB,cAAAkE"} +{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tif (typeof value === \"string\") {\n\t\tvalue = parseFloat(value);\n\t}\n\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tconst unit = bits ? BIT : BYTE;\n\t\tconst val = typeof result[0] === \"string\" ? parseFloat(result[0]) : result[0];\n\t\tresult[1] =\n\t\t\tfullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum,\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tif (typeof arg === \"bigint\") {\n\t\tnum = Number(arg);\n\t} else {\n\t\tnum = Number(arg);\n\n\t\tif (isNaN(arg)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\n\t\tif (!isFinite(num)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\t}\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n\tlocaleOptions = {},\n\tsymbols = {},\n\tfullforms = [],\n} = {}) {\n\tconst cloned = {\n\t\tlocaleOptions: JSON.parse(JSON.stringify(localeOptions)),\n\t\tsymbols: JSON.parse(JSON.stringify(symbols)),\n\t\tfullforms: JSON.parse(JSON.stringify(fullforms)),\n\t};\n\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions: cloned.localeOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols: cloned.symbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms: cloned.fullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["INVALID_NUMBER","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","Number","isNaN","TypeError","isFinite","getBaseConfiguration","full","neg","roundingFunc","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","parseFloat","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial","cloned","JSON","parse","stringify"],"mappings":";;;;AACO,MAAMA,EAAiB,iBAIjBC,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ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AAMD,KAAKE,UAAUhE,IACzCG,QAAS2D,KAAKC,MAAMD,KAAKE,UAAU7D,IACnCG,UAAWwD,KAAKC,MAAMD,KAAKE,UAAU1D,KAGtC,OAAQZ,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,cAAe6D,EAAO7D,cACtBC,YACAC,SACAC,QAAS0D,EAAO1D,QAChBC,WACAC,SACA5B,WACA6B,UAAWuD,EAAOvD,UAClBC,WACAC,iBACAC,aAEH,QAAAhB,cAAAmE"} diff --git a/dist/filesize.umd.js b/dist/filesize.umd.js index 83afa9f..1241704 100644 --- a/dist/filesize.umd.js +++ b/dist/filesize.umd.js @@ -224,6 +224,10 @@ function applyPrecisionHandling( round, exponent, ) { + if (typeof value === "string") { + value = parseFloat(value); + } + let result = value.toPrecision(precision); const autoExponent = exponent === -1 || isNaN(exponent); @@ -469,21 +473,31 @@ function filesize( } = {}, ) { let e = exponent, - num = Number(arg), + num, result = [], val = 0, u = EMPTY; + if (typeof arg === "bigint") { + num = Number(arg); + } else { + num = Number(arg); + + if (isNaN(arg)) { + throw new TypeError(INVALID_NUMBER); + } + + if (!isFinite(num)) { + throw new TypeError(INVALID_NUMBER); + } + } + const { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base); const full = fullform === true, neg = num < 0, roundingFunc = Math[roundingMethod]; - if (typeof arg !== "bigint" && isNaN(arg)) { - throw new TypeError(INVALID_NUMBER); - } - if (typeof roundingFunc !== FUNCTION) { throw new TypeError(INVALID_ROUND); } @@ -608,18 +622,24 @@ function partial({ base = -1, round = 2, locale = EMPTY, - localeOptions = {}, separator = EMPTY, spacer = SPACE, - symbols = {}, standard = EMPTY, output = STRING, fullform = false, - fullforms = [], exponent = -1, roundingMethod = ROUND, precision = 0, + localeOptions = {}, + symbols = {}, + fullforms = [], } = {}) { + const cloned = { + localeOptions: JSON.parse(JSON.stringify(localeOptions)), + symbols: JSON.parse(JSON.stringify(symbols)), + fullforms: JSON.parse(JSON.stringify(fullforms)), + }; + return (arg) => filesize(arg, { bits, @@ -627,14 +647,14 @@ function partial({ base, round, locale, - localeOptions, + localeOptions: cloned.localeOptions, separator, spacer, - symbols, + symbols: cloned.symbols, standard, output, fullform, - fullforms, + fullforms: cloned.fullforms, exponent, roundingMethod, precision, diff --git a/dist/filesize.umd.min.js b/dist/filesize.umd.min.js index 705e50b..a01ce4c 100644 --- a/dist/filesize.umd.min.js +++ b/dist/filesize.umd.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.15 */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,function(t){"use strict";const e="iec",i="jedec",n="si",o="byte",a="array",r="object",s="string",c="exponent",l="round",u={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],f=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),p=Math.log(1e3),m={[n]:{isDecimal:!0,ceil:1e3,actualStandard:i},[e]:{isDecimal:!1,ceil:1024,actualStandard:e},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function y(t,e,i,n,o,a=!0){let r=t/(i?f[e]:b[e]);return n&&(r*=8,a&&r>=o&&e<8&&(r/=o,e++)),{result:r,e:e}}function B(t,{bits:n=!1,pad:b=!1,base:f=-1,round:B=2,locale:h="",localeOptions:M={},separator:g="",spacer:x=" ",symbols:N={},standard:T="",output:v=s,fullform:D=!1,fullforms:E=[],exponent:S=-1,roundingMethod:j=l,precision:$=0}={}){let k=S,w=Number(t),G=[],K=0,P="";const{isDecimal:Y,ceil:Z,actualStandard:O}=function(t,n){return m[t]?m[t]:2===n?{isDecimal:!1,ceil:1024,actualStandard:e}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(T,f),z=!0===D,I=w<0,F=Math[j];if("bigint"!=typeof t&&isNaN(t))throw new TypeError("Invalid number");if("function"!=typeof F)throw new TypeError("Invalid rounding method");if(I&&(w=-w),0===w)return function(t,e,i,n,s,l,b,f,d){const p=t>0?(0).toPrecision(t):0;return b===c?0:(d||(d=i?u.symbol[e].bits[0]:u.symbol[e].bytes[0]),n[d]&&(d=n[d]),s&&(d=l[0]||u.fullform[e][0]+(i?"bit":o)),b===a?[p,d]:b===r?{value:p,symbol:d,exponent:0,unit:d}:p+f+d)}($,O,n,N,z,E,v,x);const{e:q,precision:A}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/p):Math.floor(Math.log(t)/d))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(w,k,0,Y,$);k=q;const C=-1===S||isNaN(S);if(v===c)return k;const{result:H,e:J}=y(w,k,Y,n,Z,C);K=H,k=J;const L=function(t,e,i,n,o,a){const r=i>0&&n>0?Math.pow(10,n):1;let s=1===r?o(t):o(t*r)/r;return s===e&&i<8&&a&&(s=1,i++),{value:s,e:i}}(K,Z,k,B,F,C);if(G[0]=L.value,k=L.e,A>0){const t=function(t,e,i,n,o,a,r,s,c,l){let u=t.toPrecision(e);const b=-1===l||isNaN(l);if(u.includes("e")&&i<8&&b){i++;const{result:t}=y(n,i,o,a,r),l=c>0?Math.pow(10,c):1;u=(1===l?s(t):s(t*l)/l).toPrecision(e)}return{value:u,e:i}}(G[0],A,k,w,Y,n,Z,F,B,S);G[0]=t.value,k=t.e}return P=function(t,e,i,n){const o=u.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(O,n,k,Y),G[1]=P,function(t,e,i,n,a,r,s,c,l,b,f,d,p){if(e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,a){let r=t;if(!0===e?r=r.toLocaleString():e.length>0?r=r.toLocaleString(e,i):n.length>0&&(r=r.toString().replace(".",n)),o&&a>0){const t=r.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,c=a-s;r=`${i[0]}${e}${o.padEnd(s+c,"0")}`}return r}(t[0],n,a,r,s,c),l){const e=p?"bit":o,i="string"==typeof t[0]?parseFloat(t[0]):t[0];t[1]=b[d]||u.fullform[f][d]+e+(1===i?"":"s")}}(G,I,N,h,M,g,b,B,z,E,O,k,n),function(t,e,i,n,o){return n===a?t:n===r?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===o?`${t[0]} ${t[1]}`:t.join(o)}(G,k,P,v,x)}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",localeOptions:a={},separator:r="",spacer:c=" ",symbols:u={},standard:b="",output:f=s,fullform:d=!1,fullforms:p=[],exponent:m=-1,roundingMethod:y=l,precision:h=0}={}){return s=>B(s,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:a,separator:r,spacer:c,symbols:u,standard:b,output:f,fullform:d,fullforms:p,exponent:m,roundingMethod:y,precision:h})}});//# sourceMappingURL=filesize.umd.min.js.map +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,function(t){"use strict";const e="Invalid number",i="iec",n="jedec",o="si",r="byte",a="array",s="object",l="string",c="exponent",u="round",f={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],d=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],p=Math.log(1024),m=Math.log(1e3),y={[o]:{isDecimal:!0,ceil:1e3,actualStandard:n},[i]:{isDecimal:!1,ceil:1024,actualStandard:i},[n]:{isDecimal:!1,ceil:1024,actualStandard:n}};function h(t,e,i,n,o,r=!0){let a=t/(i?d[e]:b[e]);return n&&(a*=8,r&&a>=o&&e<8&&(a/=o,e++)),{result:a,e:e}}function B(t,{bits:o=!1,pad:b=!1,base:d=-1,round:B=2,locale:M="",localeOptions:N={},separator:g="",spacer:x=" ",symbols:S={},standard:O="",output:T=l,fullform:E=!1,fullforms:v=[],exponent:w=-1,roundingMethod:D=u,precision:J=0}={}){let j,$=w,k=[],G=0,K="";if("bigint"==typeof t)j=Number(t);else{if(j=Number(t),isNaN(t))throw new TypeError(e);if(!isFinite(j))throw new TypeError(e)}const{isDecimal:P,ceil:Y,actualStandard:Z}=function(t,e){return y[t]?y[t]:2===e?{isDecimal:!1,ceil:1024,actualStandard:i}:{isDecimal:!0,ceil:1e3,actualStandard:n}}(O,d),F=!0===E,z=j<0,I=Math[D];if("function"!=typeof I)throw new TypeError("Invalid rounding method");if(z&&(j=-j),0===j)return function(t,e,i,n,o,l,u,b,d){const p=t>0?(0).toPrecision(t):0;return u===c?0:(d||(d=i?f.symbol[e].bits[0]:f.symbol[e].bytes[0]),n[d]&&(d=n[d]),o&&(d=l[0]||f.fullform[e][0]+(i?"bit":r)),u===a?[p,d]:u===s?{value:p,symbol:d,exponent:0,unit:d}:p+b+d)}(J,Z,o,S,F,v,T,x);const{e:q,precision:A}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/m):Math.floor(Math.log(t)/p))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(j,$,0,P,J);$=q;const C=-1===w||isNaN(w);if(T===c)return $;const{result:H,e:L}=h(j,$,P,o,Y,C);G=H,$=L;const Q=function(t,e,i,n,o,r){const a=i>0&&n>0?Math.pow(10,n):1;let s=1===a?o(t):o(t*a)/a;return s===e&&i<8&&r&&(s=1,i++),{value:s,e:i}}(G,Y,$,B,I,C);if(k[0]=Q.value,$=Q.e,A>0){const t=function(t,e,i,n,o,r,a,s,l,c){"string"==typeof t&&(t=parseFloat(t));let u=t.toPrecision(e);const f=-1===c||isNaN(c);if(u.includes("e")&&i<8&&f){i++;const{result:t}=h(n,i,o,r,a),c=l>0?Math.pow(10,l):1;u=(1===c?s(t):s(t*c)/c).toPrecision(e)}return{value:u,e:i}}(k[0],A,$,j,P,o,Y,I,B,w);k[0]=t.value,$=t.e}return K=function(t,e,i,n){const o=f.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(Z,o,$,P),k[1]=K,function(t,e,i,n,o,a,s,l,c,u,b,d,p){if(e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,r){let a=t;if(!0===e?a=a.toLocaleString():e.length>0?a=a.toLocaleString(e,i):n.length>0&&(a=a.toString().replace(".",n)),o&&r>0){const t=a.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,l=r-s;a=`${i[0]}${e}${o.padEnd(s+l,"0")}`}return a}(t[0],n,o,a,s,l),c){const e=p?"bit":r,i="string"==typeof t[0]?parseFloat(t[0]):t[0];t[1]=u[d]||f.fullform[b][d]+e+(1===i?"":"s")}}(k,z,S,M,N,g,b,B,F,v,Z,$,o),function(t,e,i,n,o){return n===a?t:n===s?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===o?`${t[0]} ${t[1]}`:t.join(o)}(k,$,K,T,x)}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",separator:r="",spacer:a=" ",standard:s="",output:c=l,fullform:f=!1,exponent:b=-1,roundingMethod:d=u,precision:p=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){const M={localeOptions:JSON.parse(JSON.stringify(m)),symbols:JSON.parse(JSON.stringify(y)),fullforms:JSON.parse(JSON.stringify(h))};return l=>B(l,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:M.localeOptions,separator:r,spacer:a,symbols:M.symbols,standard:s,output:c,fullform:f,fullforms:M.fullforms,exponent:b,roundingMethod:d,precision:p})}});//# sourceMappingURL=filesize.umd.min.js.map diff --git a/dist/filesize.umd.min.js.map b/dist/filesize.umd.min.js.map index bc15f12..b7c2771 100644 --- a/dist/filesize.umd.min.js.map +++ b/dist/filesize.umd.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tconst unit = bits ? BIT : BYTE;\n\t\tconst val = typeof result[0] === \"string\" ? parseFloat(result[0]) : result[0];\n\t\tresult[1] =\n\t\t\tfullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum = Number(arg),\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof arg !== \"bigint\" && isNaN(arg)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tsymbols = {},\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\tfullforms = [],\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n} = {}) {\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","Number","val","u","getBaseConfiguration","full","neg","roundingFunc","isNaN","TypeError","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","parseFloat","decorateResult","join","formatOutput","partial"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,SAAA,CAAA,EAAA,CAAA,CAAAC,KAAA,SAAAP,GAAA,aACO,MAIMQ,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAKzDE,EAAgB,CAC5B,EACA,KACA,QACA,WACA,cACA,gBACA,m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EDhUI,MCgUST,EACpB6C,EAA2B,iBAAdlB,EAAO,GAAkB8D,WAAW9D,EAAO,IAAMA,EAAO,GAC3EA,EAAO,GACNa,EAAUf,IAAMnB,EAAQM,SAASU,GAAgBG,GAAK8B,GAAgB,IAARV,EDhT5C,GAEJ,IC+ShB,CACD,CChLC6C,CACC/D,EACAsB,EACAZ,EACAL,EACAE,EACAC,EACAN,EACAE,EACAiB,EACAR,EACAlB,EACAG,EACAhB,GD8KK,SAAsBkB,EAAQF,EAAGqB,EAAGP,EAAQH,GAClD,OAAIG,IAAWtC,EACP0B,EAGJY,IAAWrC,EACP,CACNmD,MAAO1B,EAAO,GACdpB,OAAQoB,EAAO,GACfc,SAAUhB,EACV8B,KAAMT,GDpUY,MCwUbV,EAAmB,GAAGT,EAAO,MAAMA,EAAO,KAAOA,EAAOgE,KAAKvD,EACrE,CC1LQwD,CAAajE,EAAQF,EAAGqB,EAAGP,EAAQH,EAC3C,CAiEA/C,EAAAM,SAAAA,EAAAN,EAAAwG,QArCO,UAAiBpF,KACvBA,GAAO,EAAKoB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKC,cACdA,EAAgB,CAAA,EAAEC,UAClBA,EAAYF,GAAKG,OACjBA,EFpLoB,IEoLNC,QACdA,EAAU,CAAA,EAAEC,SACZA,EAAWL,GAAKM,OAChBA,EAASpC,EAAMS,SACfA,GAAW,EAAK4B,UAChBA,EAAY,GAAEC,SACdA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,GACT,IACH,OAAQf,GACPjC,EAASiC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,gBACAC,YACAC,SACAC,UACAC,WACAC,SACA3B,WACA4B,YACAC,WACAC,iBACAC,aAEH,CAAA"} +{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tif (typeof value === \"string\") {\n\t\tvalue = parseFloat(value);\n\t}\n\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tconst unit = bits ? BIT : BYTE;\n\t\tconst val = typeof result[0] === \"string\" ? parseFloat(result[0]) : result[0];\n\t\tresult[1] =\n\t\t\tfullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum,\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tif (typeof arg === \"bigint\") {\n\t\tnum = Number(arg);\n\t} else {\n\t\tnum = Number(arg);\n\n\t\tif (isNaN(arg)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\n\t\tif (!isFinite(num)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\t}\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n\tlocaleOptions = {},\n\tsymbols = {},\n\tfullforms = [],\n} = {}) {\n\tconst cloned = {\n\t\tlocaleOptions: JSON.parse(JSON.stringify(localeOptions)),\n\t\tsymbols: JSON.parse(JSON.stringify(symbols)),\n\t\tfullforms: JSON.parse(JSON.stringify(fullforms)),\n\t};\n\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions: cloned.localeOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols: cloned.symbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms: cloned.fullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","INVALID_NUMBER","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","Number","isNaN","TypeError","isFinite","getBaseConfiguration","full","neg","roundingFunc","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","parseFloat","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial","cloned","JSON","parse","stringify"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAA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oB,EACAX,EACAlB,EACAG,EACAhB,GDwKK,SAAsBkB,EAAQF,EAAGoB,EAAGN,EAAQH,GAClD,OAAIG,IAAWtC,EACP0B,EAGJY,IAAWrC,EACP,CACNoD,MAAO3B,EAAO,GACdpB,OAAQoB,EAAO,GACfc,SAAUhB,EACV+B,KAAMX,GDxUY,MC4UbT,EAAmB,GAAGT,EAAO,MAAMA,EAAO,KAAOA,EAAOiE,KAAKxD,EACrE,CCpLQyD,CAAalE,EAAQF,EAAGoB,EAAGN,EAAQH,EAC3C,CAuEAhD,EAAAM,SAAAA,EAAAN,EAAA0G,QA3CO,UAAiBrF,KACvBA,GAAO,EAAKoB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKE,UACdA,EAAYF,GAAKG,OACjBA,EF7LoB,IE6LNE,SACdA,EAAWL,GAAKM,OAChBA,EAASpC,EAAMS,SACfA,GAAW,EAAK6B,SAChBA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,EAACT,cACbA,EAAgB,CAAA,EAAEG,QAClBA,EAAU,CAAA,EAAEG,UACZA,EAAY,IACT,IACH,MAAMuD,EAAS,CACd7D,cAAe8D,KAAKC,MAAMD,KAAKE,UAAUhE,IACzCG,QAAS2D,KAAKC,MAAMD,KAAKE,UAAU7D,IACnCG,UAAWwD,KAAKC,MAAMD,KAAKE,UAAU1D,KAGtC,OAAQZ,GACPlC,EAASkC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,cAAe6D,EAAO7D,cACtBC,YACAC,SACAC,QAAS0D,EAAO1D,QAChBC,WACAC,SACA3B,WACA4B,UAAWuD,EAAOvD,UAClBC,WACAC,iBACAC,aAEH,CAAA"} diff --git a/src/filesize.js b/src/filesize.js index 3d79a9b..e654635 100644 --- a/src/filesize.js +++ b/src/filesize.js @@ -69,21 +69,31 @@ export function filesize( } = {}, ) { let e = exponent, - num = Number(arg), + num, result = [], val = 0, u = EMPTY; + if (typeof arg === "bigint") { + num = Number(arg); + } else { + num = Number(arg); + + if (isNaN(arg)) { + throw new TypeError(INVALID_NUMBER); + } + + if (!isFinite(num)) { + throw new TypeError(INVALID_NUMBER); + } + } + const { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base); const full = fullform === true, neg = num < 0, roundingFunc = Math[roundingMethod]; - if (typeof arg !== "bigint" && isNaN(arg)) { - throw new TypeError(INVALID_NUMBER); - } - if (typeof roundingFunc !== FUNCTION) { throw new TypeError(INVALID_ROUND); } @@ -208,18 +218,24 @@ export function partial({ base = -1, round = 2, locale = EMPTY, - localeOptions = {}, separator = EMPTY, spacer = SPACE, - symbols = {}, standard = EMPTY, output = STRING, fullform = false, - fullforms = [], exponent = -1, roundingMethod = ROUND, precision = 0, + localeOptions = {}, + symbols = {}, + fullforms = [], } = {}) { + const cloned = { + localeOptions: JSON.parse(JSON.stringify(localeOptions)), + symbols: JSON.parse(JSON.stringify(symbols)), + fullforms: JSON.parse(JSON.stringify(fullforms)), + }; + return (arg) => filesize(arg, { bits, @@ -227,14 +243,14 @@ export function partial({ base, round, locale, - localeOptions, + localeOptions: cloned.localeOptions, separator, spacer, - symbols, + symbols: cloned.symbols, standard, output, fullform, - fullforms, + fullforms: cloned.fullforms, exponent, roundingMethod, precision, diff --git a/src/helpers.js b/src/helpers.js index 479f754..d902728 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -163,6 +163,10 @@ export function applyPrecisionHandling( round, exponent, ) { + if (typeof value === "string") { + value = parseFloat(value); + } + let result = value.toPrecision(precision); const autoExponent = exponent === -1 || isNaN(exponent); diff --git a/tests/unit/filesize-helpers.test.js b/tests/unit/filesize-helpers.test.js index 4116f59..36449cc 100644 --- a/tests/unit/filesize-helpers.test.js +++ b/tests/unit/filesize-helpers.test.js @@ -11,6 +11,7 @@ import { calculateOptimizedValue, applyPrecisionHandling, applyNumberFormatting, + applyRounding, } from "../../src/helpers.js"; describe("Helper Functions", () => { @@ -243,5 +244,75 @@ describe("Helper Functions", () => { const result = applyNumberFormatting(1.5, "", {}, "", true, 0); assert.strictEqual(result, 1.5); }); + + it("should handle string value input without crashing", () => { + const result = applyNumberFormatting("1.5", "en-US", {}, "", false, 2); + assert.strictEqual(result, "1.5"); + }); + }); + + describe("applyRounding ceil boundary", () => { + it("should trigger auto-increment when result equals ceil", () => { + const result = applyRounding(1000, 1000, 0, 0, Math.round, true); + assert.deepStrictEqual(result, { value: 1, e: 1 }); + }); + }); +}); + +describe("handleZeroValue with explicit symbol", () => { + it("should use provided symbol for string output", () => { + const result = handleZeroValue(0, "jedec", false, {}, false, [], "string", " ", "CustomB"); + assert.strictEqual(result, "0 CustomB"); + }); + + it("should use provided symbol for array output", () => { + const result = handleZeroValue(0, "jedec", false, {}, false, [], "array", " ", "CustomB"); + assert.deepStrictEqual(result, [0, "CustomB"]); + }); + + it("should use provided symbol for object output", () => { + const result = handleZeroValue(0, "jedec", false, {}, false, [], "object", " ", "CustomB"); + assert.deepStrictEqual(result, { value: 0, symbol: "CustomB", exponent: 0, unit: "CustomB" }); + }); + + it("should use provided symbol for exponent output", () => { + const result = handleZeroValue(0, "jedec", false, {}, false, [], "exponent", " ", "CustomB"); + assert.strictEqual(result, 0); + }); +}); + +describe("applyPrecisionHandling with string value", () => { + it("should parse string value and apply precision", () => { + const result = applyPrecisionHandling("1.5", 2, 1, 1024, false, false, 1024, Math.round, 2, -1); + assert.deepStrictEqual(result, { value: "1.5", e: 1 }); + }); + + it("should handle string from toPrecision output", () => { + const result = applyPrecisionHandling( + "1.2345", + 3, + 1, + 1024, + false, + false, + 1024, + Math.round, + 2, + -1, + ); + assert.strictEqual(typeof result.value, "string"); + assert.strictEqual(typeof result.e, "number"); + }); +}); + +describe("handleZeroValue with fullform and custom fullforms", () => { + it("should use custom fullforms for string output", () => { + const result = handleZeroValue(0, "jedec", false, {}, true, ["my byte"], "string", " "); + assert.strictEqual(result, "0 my byte"); + }); + + it("should use custom fullforms for object output", () => { + const result = handleZeroValue(0, "jedec", false, {}, true, ["my byte"], "object", " "); + assert.deepStrictEqual(result, { value: 0, symbol: "my byte", exponent: 0, unit: "my byte" }); }); }); diff --git a/tests/unit/filesize.test.js b/tests/unit/filesize.test.js index 6c6e44c..126bc54 100644 --- a/tests/unit/filesize.test.js +++ b/tests/unit/filesize.test.js @@ -28,6 +28,14 @@ describe("filesize", () => { assert.strictEqual(filesize(-1000), "-1 kB"); assert.strictEqual(filesize(-1000000), "-1 MB"); }); + + it("should throw TypeError for Infinity", () => { + assert.throws(() => filesize(Infinity), TypeError); + }); + + it("should throw TypeError for -Infinity", () => { + assert.throws(() => filesize(-Infinity), TypeError); + }); }); describe("Bits option", () => { @@ -218,6 +226,14 @@ describe("filesize", () => { "1 thousand-byte", ); }); + + it("should handle bits fullform singular", () => { + assert.strictEqual(filesize(0.125, { bits: true, fullform: true }), "1 bit"); + }); + + it("should handle bits fullform plural", () => { + assert.strictEqual(filesize(0.25, { bits: true, fullform: true }), "2 bits"); + }); }); describe("Base and exponent options", () => { @@ -449,6 +465,20 @@ describe("filesize", () => { "0.990 GiB", ); }); + + it("should return string value in object output when precision > 0", () => { + const result = filesize(1234567890, { precision: 2, output: "object" }); + assert.strictEqual(typeof result.value, "string"); + assert.strictEqual(result.value, "1.2"); + }); + + it("should skip padding when round is 0", () => { + assert.strictEqual(filesize(1000, { pad: true, round: 0 }), "1 kB"); + }); + + it("should fall back to JEDEC default for unknown standard", () => { + assert.strictEqual(filesize(1024, { standard: "foobar" }), "1.02 kB"); + }); }); describe("Edge cases", () => { @@ -911,5 +941,35 @@ describe("partial", () => { assert.strictEqual(format1(1000), "1 first_kB"); assert.strictEqual(format2(1000), "1 second_kB"); }); + + it("should not be affected by mutations to localeOptions reference", () => { + const opts = { localeOptions: { useGrouping: true } }; + const format = partial(opts); + + assert.strictEqual(typeof format(1234567), "string"); + + opts.localeOptions.useGrouping = false; + assert.strictEqual(typeof format(1234567), "string"); + }); + + it("should not be affected by mutations to symbols reference", () => { + const opts = { symbols: { kB: "original_kB" } }; + const format = partial(opts); + + assert.strictEqual(format(1000), "1 original_kB"); + + opts.symbols.kB = "mutated_kB"; + assert.strictEqual(format(1000), "1 original_kB"); + }); + + it("should not be affected by mutations to fullforms reference", () => { + const opts = { fullforms: ["custom"], fullform: true }; + const format = partial(opts); + + assert.strictEqual(format(1), "1 custom"); + + opts.fullforms[0] = "mutated"; + assert.strictEqual(format(1), "1 custom"); + }); }); }); From ecead4e367be5b444fe12182aebec00dd8928207 Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 21:00:24 -0400 Subject: [PATCH 10/11] refactor: replace ternaries with full conditionals in helpers.js --- coverage.txt | 4 +- dist/filesize.cjs | 113 +++++++++++++++++++++++++++++------ dist/filesize.js | 113 +++++++++++++++++++++++++++++------ dist/filesize.min.js | 2 +- dist/filesize.min.js.map | 2 +- dist/filesize.umd.js | 113 +++++++++++++++++++++++++++++------ dist/filesize.umd.min.js | 2 +- dist/filesize.umd.min.js.map | 2 +- src/helpers.js | 113 +++++++++++++++++++++++++++++------ tests/unit/filesize.test.js | 8 +++ 10 files changed, 394 insertions(+), 78 deletions(-) diff --git a/coverage.txt b/coverage.txt index 2fd0754..3c54cd6 100644 --- a/coverage.txt +++ b/coverage.txt @@ -5,8 +5,8 @@ ℹ src | | | | ℹ constants.js | 100.00 | 100.00 | 100.00 | ℹ filesize.js | 100.00 | 100.00 | 100.00 | -ℹ helpers.js | 100.00 | 98.96 | 100.00 | +ℹ helpers.js | 100.00 | 99.00 | 100.00 | ℹ -------------------------------------------------------------- -ℹ all files | 100.00 | 99.13 | 100.00 | +ℹ all files | 100.00 | 99.18 | 100.00 | ℹ -------------------------------------------------------------- ℹ end of coverage report diff --git a/dist/filesize.cjs b/dist/filesize.cjs index 4a59b94..7ed9aa6 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -141,7 +141,12 @@ function handleZeroValue( spacer, symbol, ) { - const value = precision > 0 ? (0).toPrecision(precision) : 0; + let value; + if (precision > 0) { + value = (0).toPrecision(precision); + } else { + value = 0; + } if (output === EXPONENT) { return 0; @@ -161,7 +166,16 @@ function handleZeroValue( // Apply full form if (full) { - symbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE); + if (fullforms[0]) { + symbol = fullforms[0]; + } else { + symbol = STRINGS.fullform[actualStandard][0]; + if (bits) { + symbol += BIT; + } else { + symbol += BYTE; + } + } } // Return in requested format @@ -187,7 +201,12 @@ function handleZeroValue( * @returns {Object} Object with result and e properties */ function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) { - const d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e]; + let d; + if (isDecimal) { + d = DECIMAL_POWERS[e]; + } else { + d = BINARY_POWERS[e]; + } let result = num / d; if (bits) { @@ -240,10 +259,19 @@ function applyPrecisionHandling( if (result.includes(E) && e < 8 && autoExponent) { e++; const { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil); - const p = round > 0 ? Math.pow(10, round) : 1; - result = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision( - precision, - ); + let p; + if (round > 0) { + p = Math.pow(10, round); + } else { + p = 1; + } + let computed; + if (p === 1) { + computed = roundingFunc(valueResult); + } else { + computed = roundingFunc(valueResult * p) / p; + } + result = computed.toPrecision(precision); } return { value: result, e }; @@ -299,9 +327,11 @@ function applyNumberFormatting(value, locale, localeOptions, separator, pad, rou */ function calculateExponent(num, e, exponent, isDecimal, precision) { if (e === -1 || isNaN(e)) { - e = isDecimal - ? Math.floor(Math.log(num) / LOG_10_1000) - : Math.floor(Math.log(num) / LOG_2_1024); + if (isDecimal) { + e = Math.floor(Math.log(num) / LOG_10_1000); + } else { + e = Math.floor(Math.log(num) / LOG_2_1024); + } if (e < 0) { e = 0; } @@ -328,8 +358,18 @@ function calculateExponent(num, e, exponent, isDecimal, precision) { * @returns {Object} Object with rounded value and possibly incremented exponent */ function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { - const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; - let r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; + let p; + if (e > 0 && round > 0) { + p = Math.pow(10, round); + } else { + p = 1; + } + let r; + if (p === 1) { + r = roundingFunc(val); + } else { + r = roundingFunc(val * p) / p; + } if (r === ceil && e < 8 && autoExponent) { r = 1; @@ -350,7 +390,17 @@ function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { */ function resolveSymbol(actualStandard, bits, e, isDecimal) { const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; - return isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; + let result; + if (isDecimal && e === 1) { + if (bits) { + result = SI_KBIT; + } else { + result = SI_KBYTE; + } + } else { + result = symbolTable[e]; + } + return result; } /** @@ -397,10 +447,31 @@ function decorateResult( result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); if (full) { - const unit = bits ? BIT : BYTE; - const val = typeof result[0] === "string" ? parseFloat(result[0]) : result[0]; - result[1] = - fullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S); + let unit; + if (bits) { + unit = BIT; + } else { + unit = BYTE; + } + let val; + if (typeof result[0] === "string") { + val = parseFloat(result[0]); + } else { + val = result[0]; + } + // Determine singular/plural suffix + let suffix; + if (val === 1) { + suffix = EMPTY; + } else { + suffix = S; + } + // Determine symbol — custom fullforms are the complete name, defaults get unit+suffix + if (fullforms[e]) { + result[1] = fullforms[e]; + } else { + result[1] = STRINGS.fullform[actualStandard][e] + unit + suffix; + } } } @@ -427,7 +498,13 @@ function formatOutput(result, e, u, output, spacer) { }; } - return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); + let formatted; + if (spacer === SPACE) { + formatted = `${result[0]} ${result[1]}`; + } else { + formatted = result.join(spacer); + } + return formatted; } /** diff --git a/dist/filesize.js b/dist/filesize.js index 5b36fb6..70e3662 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -137,7 +137,12 @@ function handleZeroValue( spacer, symbol, ) { - const value = precision > 0 ? (0).toPrecision(precision) : 0; + let value; + if (precision > 0) { + value = (0).toPrecision(precision); + } else { + value = 0; + } if (output === EXPONENT) { return 0; @@ -157,7 +162,16 @@ function handleZeroValue( // Apply full form if (full) { - symbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE); + if (fullforms[0]) { + symbol = fullforms[0]; + } else { + symbol = STRINGS.fullform[actualStandard][0]; + if (bits) { + symbol += BIT; + } else { + symbol += BYTE; + } + } } // Return in requested format @@ -183,7 +197,12 @@ function handleZeroValue( * @returns {Object} Object with result and e properties */ function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) { - const d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e]; + let d; + if (isDecimal) { + d = DECIMAL_POWERS[e]; + } else { + d = BINARY_POWERS[e]; + } let result = num / d; if (bits) { @@ -236,10 +255,19 @@ function applyPrecisionHandling( if (result.includes(E) && e < 8 && autoExponent) { e++; const { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil); - const p = round > 0 ? Math.pow(10, round) : 1; - result = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision( - precision, - ); + let p; + if (round > 0) { + p = Math.pow(10, round); + } else { + p = 1; + } + let computed; + if (p === 1) { + computed = roundingFunc(valueResult); + } else { + computed = roundingFunc(valueResult * p) / p; + } + result = computed.toPrecision(precision); } return { value: result, e }; @@ -295,9 +323,11 @@ function applyNumberFormatting(value, locale, localeOptions, separator, pad, rou */ function calculateExponent(num, e, exponent, isDecimal, precision) { if (e === -1 || isNaN(e)) { - e = isDecimal - ? Math.floor(Math.log(num) / LOG_10_1000) - : Math.floor(Math.log(num) / LOG_2_1024); + if (isDecimal) { + e = Math.floor(Math.log(num) / LOG_10_1000); + } else { + e = Math.floor(Math.log(num) / LOG_2_1024); + } if (e < 0) { e = 0; } @@ -324,8 +354,18 @@ function calculateExponent(num, e, exponent, isDecimal, precision) { * @returns {Object} Object with rounded value and possibly incremented exponent */ function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { - const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; - let r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; + let p; + if (e > 0 && round > 0) { + p = Math.pow(10, round); + } else { + p = 1; + } + let r; + if (p === 1) { + r = roundingFunc(val); + } else { + r = roundingFunc(val * p) / p; + } if (r === ceil && e < 8 && autoExponent) { r = 1; @@ -346,7 +386,17 @@ function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { */ function resolveSymbol(actualStandard, bits, e, isDecimal) { const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; - return isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; + let result; + if (isDecimal && e === 1) { + if (bits) { + result = SI_KBIT; + } else { + result = SI_KBYTE; + } + } else { + result = symbolTable[e]; + } + return result; } /** @@ -393,10 +443,31 @@ function decorateResult( result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); if (full) { - const unit = bits ? BIT : BYTE; - const val = typeof result[0] === "string" ? parseFloat(result[0]) : result[0]; - result[1] = - fullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S); + let unit; + if (bits) { + unit = BIT; + } else { + unit = BYTE; + } + let val; + if (typeof result[0] === "string") { + val = parseFloat(result[0]); + } else { + val = result[0]; + } + // Determine singular/plural suffix + let suffix; + if (val === 1) { + suffix = EMPTY; + } else { + suffix = S; + } + // Determine symbol — custom fullforms are the complete name, defaults get unit+suffix + if (fullforms[e]) { + result[1] = fullforms[e]; + } else { + result[1] = STRINGS.fullform[actualStandard][e] + unit + suffix; + } } } @@ -423,7 +494,13 @@ function formatOutput(result, e, u, output, spacer) { }; } - return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); + let formatted; + if (spacer === SPACE) { + formatted = `${result[0]} ${result[1]}`; + } else { + formatted = result.join(spacer); + } + return formatted; }/** * Converts a file size in bytes to a human-readable string with appropriate units * @param {number|string|bigint} arg - The file size in bytes to convert diff --git a/dist/filesize.min.js b/dist/filesize.min.js index 12dda0b..4454afc 100644 --- a/dist/filesize.min.js +++ b/dist/filesize.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.15 */ -const t="Invalid number",e="iec",i="jedec",n="si",o="byte",r="array",a="object",s="string",l="exponent",c="round",u={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],f=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],p=Math.log(1024),d=Math.log(1e3),m={[n]:{isDecimal:!0,ceil:1e3,actualStandard:i},[e]:{isDecimal:!1,ceil:1024,actualStandard:e},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function y(t,e,i,n,o,r=!0){let a=t/(i?f[e]:b[e]);return n&&(a*=8,r&&a>=o&&e<8&&(a/=o,e++)),{result:a,e:e}}function B(n,{bits:b=!1,pad:f=!1,base:B=-1,round:h=2,locale:M="",localeOptions:N={},separator:g="",spacer:S=" ",symbols:x={},standard:O="",output:E=s,fullform:T=!1,fullforms:v=[],exponent:w=-1,roundingMethod:D=c,precision:J=0}={}){let $,j=w,k=[],G=0,K="";if("bigint"==typeof n)$=Number(n);else{if($=Number(n),isNaN(n))throw new TypeError(t);if(!isFinite($))throw new TypeError(t)}const{isDecimal:P,ceil:Y,actualStandard:Z}=function(t,n){return m[t]?m[t]:2===n?{isDecimal:!1,ceil:1024,actualStandard:e}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(O,B),F=!0===T,z=$<0,I=Math[D];if("function"!=typeof I)throw new TypeError("Invalid rounding method");if(z&&($=-$),0===$)return function(t,e,i,n,s,c,b,f,p){const d=t>0?(0).toPrecision(t):0;return b===l?0:(p||(p=i?u.symbol[e].bits[0]:u.symbol[e].bytes[0]),n[p]&&(p=n[p]),s&&(p=c[0]||u.fullform[e][0]+(i?"bit":o)),b===r?[d,p]:b===a?{value:d,symbol:p,exponent:0,unit:p}:d+f+p)}(J,Z,b,x,F,v,E,S);const{e:q,precision:A}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/d):Math.floor(Math.log(t)/p))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}($,j,0,P,J);j=q;const C=-1===w||isNaN(w);if(E===l)return j;const{result:H,e:L}=y($,j,P,b,Y,C);G=H,j=L;const Q=function(t,e,i,n,o,r){const a=i>0&&n>0?Math.pow(10,n):1;let s=1===a?o(t):o(t*a)/a;return s===e&&i<8&&r&&(s=1,i++),{value:s,e:i}}(G,Y,j,h,I,C);if(k[0]=Q.value,j=Q.e,A>0){const t=function(t,e,i,n,o,r,a,s,l,c){"string"==typeof t&&(t=parseFloat(t));let u=t.toPrecision(e);const b=-1===c||isNaN(c);if(u.includes("e")&&i<8&&b){i++;const{result:t}=y(n,i,o,r,a),c=l>0?Math.pow(10,l):1;u=(1===c?s(t):s(t*c)/c).toPrecision(e)}return{value:u,e:i}}(k[0],A,j,$,P,b,Y,I,h,w);k[0]=t.value,j=t.e}return K=function(t,e,i,n){const o=u.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(Z,b,j,P),k[1]=K,function(t,e,i,n,r,a,s,l,c,b,f,p,d){if(e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,r){let a=t;if(!0===e?a=a.toLocaleString():e.length>0?a=a.toLocaleString(e,i):n.length>0&&(a=a.toString().replace(".",n)),o&&r>0){const t=a.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,l=r-s;a=`${i[0]}${e}${o.padEnd(s+l,"0")}`}return a}(t[0],n,r,a,s,l),c){const e=d?"bit":o,i="string"==typeof t[0]?parseFloat(t[0]):t[0];t[1]=b[p]||u.fullform[f][p]+e+(1===i?"":"s")}}(k,z,x,M,N,g,f,h,F,v,Z,j,b),function(t,e,i,n,o){return n===r?t:n===a?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===o?`${t[0]} ${t[1]}`:t.join(o)}(k,j,K,E,S)}function h({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",separator:r="",spacer:a=" ",standard:l="",output:u=s,fullform:b=!1,exponent:f=-1,roundingMethod:p=c,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){const M={localeOptions:JSON.parse(JSON.stringify(m)),symbols:JSON.parse(JSON.stringify(y)),fullforms:JSON.parse(JSON.stringify(h))};return s=>B(s,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:M.localeOptions,separator:r,spacer:a,symbols:M.symbols,standard:l,output:u,fullform:b,fullforms:M.fullforms,exponent:f,roundingMethod:p,precision:d})}export{B as filesize,h as partial};//# sourceMappingURL=filesize.min.js.map +const t="Invalid number",e="iec",i="jedec",n="si",o="byte",r="array",a="object",l="string",s="exponent",u="round",c={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],f=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],p=Math.log(1024),d=Math.log(1e3),m={[n]:{isDecimal:!0,ceil:1e3,actualStandard:i},[e]:{isDecimal:!1,ceil:1024,actualStandard:e},[i]:{isDecimal:!1,ceil:1024,actualStandard:i}};function y(t,e,i,n,o,r=!0){let a;a=i?f[e]:b[e];let l=t/a;return n&&(l*=8,r&&l>=o&&e<8&&(l/=o,e++)),{result:l,e:e}}function B(n,{bits:b=!1,pad:f=!1,base:B=-1,round:h=2,locale:M="",localeOptions:N={},separator:g="",spacer:S=" ",symbols:x={},standard:O="",output:E=l,fullform:T=!1,fullforms:v=[],exponent:w=-1,roundingMethod:D=u,precision:J=0}={}){let $,j=w,k=[],G=0,K="";if("bigint"==typeof n)$=Number(n);else{if($=Number(n),isNaN(n))throw new TypeError(t);if(!isFinite($))throw new TypeError(t)}const{isDecimal:P,ceil:Y,actualStandard:Z}=function(t,n){return m[t]?m[t]:2===n?{isDecimal:!1,ceil:1024,actualStandard:e}:{isDecimal:!0,ceil:1e3,actualStandard:i}}(O,B),F=!0===T,z=$<0,I=Math[D];if("function"!=typeof I)throw new TypeError("Invalid rounding method");if(z&&($=-$),0===$)return function(t,e,i,n,l,u,b,f,p){let d;return d=t>0?(0).toPrecision(t):0,b===s?0:(p||(p=i?c.symbol[e].bits[0]:c.symbol[e].bytes[0]),n[p]&&(p=n[p]),l&&(u[0]?p=u[0]:(p=c.fullform[e][0],p+=i?"bit":o)),b===r?[d,p]:b===a?{value:d,symbol:p,exponent:0,unit:p}:d+f+p)}(J,Z,b,x,F,v,E,S);const{e:q,precision:A}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/d):Math.floor(Math.log(t)/p))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}($,j,0,P,J);j=q;const C=-1===w||isNaN(w);if(E===s)return j;const{result:H,e:L}=y($,j,P,b,Y,C);G=H,j=L;const Q=function(t,e,i,n,o,r){let a,l;return a=i>0&&n>0?Math.pow(10,n):1,l=1===a?o(t):o(t*a)/a,l===e&&i<8&&r&&(l=1,i++),{value:l,e:i}}(G,Y,j,h,I,C);if(k[0]=Q.value,j=Q.e,A>0){const t=function(t,e,i,n,o,r,a,l,s,u){"string"==typeof t&&(t=parseFloat(t));let c=t.toPrecision(e);const b=-1===u||isNaN(u);if(c.includes("e")&&i<8&&b){i++;const{result:t}=y(n,i,o,r,a);let u,b;u=s>0?Math.pow(10,s):1,b=1===u?l(t):l(t*u)/u,c=b.toPrecision(e)}return{value:c,e:i}}(k[0],A,j,$,P,b,Y,I,h,w);k[0]=t.value,j=t.e}return K=function(t,e,i,n){const o=c.symbol[t][e?"bits":"bytes"];let r;return r=n&&1===i?e?"kbit":"kB":o[i],r}(Z,b,j,P),k[1]=K,function(t,e,i,n,r,a,l,s,u,b,f,p,d){if(e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,r){let a=t;if(!0===e?a=a.toLocaleString():e.length>0?a=a.toLocaleString(e,i):n.length>0&&(a=a.toString().replace(".",n)),o&&r>0){const t=a.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",l=o.length,s=r-l;a=`${i[0]}${e}${o.padEnd(l+s,"0")}`}return a}(t[0],n,r,a,l,s),u){let e,i,n;e=d?"bit":o,i="string"==typeof t[0]?parseFloat(t[0]):t[0],n=1===i?"":"s",b[p]?t[1]=b[p]:t[1]=c.fullform[f][p]+e+n}}(k,z,x,M,N,g,f,h,F,v,Z,j,b),function(t,e,i,n,o){if(n===r)return t;if(n===a)return{value:t[0],symbol:t[1],exponent:e,unit:i};let l;return l=" "===o?`${t[0]} ${t[1]}`:t.join(o),l}(k,j,K,E,S)}function h({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",separator:r="",spacer:a=" ",standard:s="",output:c=l,fullform:b=!1,exponent:f=-1,roundingMethod:p=u,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){const M={localeOptions:JSON.parse(JSON.stringify(m)),symbols:JSON.parse(JSON.stringify(y)),fullforms:JSON.parse(JSON.stringify(h))};return l=>B(l,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:M.localeOptions,separator:r,spacer:a,symbols:M.symbols,standard:s,output:c,fullform:b,fullforms:M.fullforms,exponent:f,roundingMethod:p,precision:d})}export{B as filesize,h as partial};//# sourceMappingURL=filesize.min.js.map diff --git a/dist/filesize.min.js.map b/dist/filesize.min.js.map index 140608c..4e9eb7b 100644 --- a/dist/filesize.min.js.map +++ b/dist/filesize.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tif (typeof value === \"string\") {\n\t\tvalue = parseFloat(value);\n\t}\n\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tconst unit = bits ? BIT : BYTE;\n\t\tconst val = typeof result[0] === \"string\" ? parseFloat(result[0]) : result[0];\n\t\tresult[1] =\n\t\t\tfullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum,\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tif (typeof arg === \"bigint\") {\n\t\tnum = Number(arg);\n\t} else {\n\t\tnum = Number(arg);\n\n\t\tif (isNaN(arg)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\n\t\tif (!isFinite(num)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\t}\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n\tlocaleOptions = {},\n\tsymbols = {},\n\tfullforms = [],\n} = {}) {\n\tconst cloned = {\n\t\tlocaleOptions: JSON.parse(JSON.stringify(localeOptions)),\n\t\tsymbols: JSON.parse(JSON.stringify(symbols)),\n\t\tfullforms: JSON.parse(JSON.stringify(fullforms)),\n\t};\n\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions: cloned.localeOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols: cloned.symbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms: cloned.fullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["INVALID_NUMBER","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","Number","isNaN","TypeError","isFinite","getBaseConfiguration","full","neg","roundingFunc","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","parseFloat","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial","cloned","JSON","parse","stringify"],"mappings":";;;;AACO,MAAMA,EAAiB,iBAIjBC,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG,MAAO,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,MAAO,QAAS,WAK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AKC,MAAMD,KAAKE,UAAU7D,IACnCG,UAAWwD,KAAKC,MAAMD,KAAKE,UAAU1D,KAGtC,OAAQZ,GACPD,EAASC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,cAAe6D,EAAO7D,cACtBC,YACAC,SACAC,QAAS0D,EAAO1D,QAChBC,WACAC,SACA5B,WACA6B,UAAWuD,EAAOvD,UAClBC,WACAC,iBACAC,aAEH,QAAAhB,cAAAmE"} +{"version":3,"file":"filesize.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tlet value;\n\tif (precision > 0) {\n\t\tvalue = (0).toPrecision(precision);\n\t} else {\n\t\tvalue = 0;\n\t}\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tif (fullforms[0]) {\n\t\t\tsymbol = fullforms[0];\n\t\t} else {\n\t\t\tsymbol = STRINGS.fullform[actualStandard][0];\n\t\t\tif (bits) {\n\t\t\t\tsymbol += BIT;\n\t\t\t} else {\n\t\t\t\tsymbol += BYTE;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tlet d;\n\tif (isDecimal) {\n\t\td = DECIMAL_POWERS[e];\n\t} else {\n\t\td = BINARY_POWERS[e];\n\t}\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tif (typeof value === \"string\") {\n\t\tvalue = parseFloat(value);\n\t}\n\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tlet p;\n\t\tif (round > 0) {\n\t\t\tp = Math.pow(10, round);\n\t\t} else {\n\t\t\tp = 1;\n\t\t}\n\t\tlet computed;\n\t\tif (p === 1) {\n\t\t\tcomputed = roundingFunc(valueResult);\n\t\t} else {\n\t\t\tcomputed = roundingFunc(valueResult * p) / p;\n\t\t}\n\t\tresult = computed.toPrecision(precision);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\tif (isDecimal) {\n\t\t\te = Math.floor(Math.log(num) / LOG_10_1000);\n\t\t} else {\n\t\t\te = Math.floor(Math.log(num) / LOG_2_1024);\n\t\t}\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tlet p;\n\tif (e > 0 && round > 0) {\n\t\tp = Math.pow(10, round);\n\t} else {\n\t\tp = 1;\n\t}\n\tlet r;\n\tif (p === 1) {\n\t\tr = roundingFunc(val);\n\t} else {\n\t\tr = roundingFunc(val * p) / p;\n\t}\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\tlet result;\n\tif (isDecimal && e === 1) {\n\t\tif (bits) {\n\t\t\tresult = SI_KBIT;\n\t\t} else {\n\t\t\tresult = SI_KBYTE;\n\t\t}\n\t} else {\n\t\tresult = symbolTable[e];\n\t}\n\treturn result;\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tlet unit;\n\t\tif (bits) {\n\t\t\tunit = BIT;\n\t\t} else {\n\t\t\tunit = BYTE;\n\t\t}\n\t\tlet val;\n\t\tif (typeof result[0] === \"string\") {\n\t\t\tval = parseFloat(result[0]);\n\t\t} else {\n\t\t\tval = result[0];\n\t\t}\n\t\t// Determine singular/plural suffix\n\t\tlet suffix;\n\t\tif (val === 1) {\n\t\t\tsuffix = EMPTY;\n\t\t} else {\n\t\t\tsuffix = S;\n\t\t}\n\t\t// Determine symbol — custom fullforms are the complete name, defaults get unit+suffix\n\t\tif (fullforms[e]) {\n\t\t\tresult[1] = fullforms[e];\n\t\t} else {\n\t\t\tresult[1] = STRINGS.fullform[actualStandard][e] + unit + suffix;\n\t\t}\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\tlet formatted;\n\tif (spacer === SPACE) {\n\t\tformatted = `${result[0]} ${result[1]}`;\n\t} else {\n\t\tformatted = result.join(spacer);\n\t}\n\treturn formatted;\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum,\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tif (typeof arg === \"bigint\") {\n\t\tnum = Number(arg);\n\t} else {\n\t\tnum = Number(arg);\n\n\t\tif (isNaN(arg)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\n\t\tif (!isFinite(num)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\t}\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n\tlocaleOptions = {},\n\tsymbols = {},\n\tfullforms = [],\n} = {}) {\n\tconst cloned = {\n\t\tlocaleOptions: JSON.parse(JSON.stringify(localeOptions)),\n\t\tsymbols: JSON.parse(JSON.stringify(symbols)),\n\t\tfullforms: JSON.parse(JSON.stringify(fullforms)),\n\t};\n\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions: cloned.localeOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols: cloned.symbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms: cloned.fullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["INVALID_NUMBER","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","d","result","filesize","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","Number","isNaN","TypeError","isFinite","getBaseConfiguration","full","neg","roundingFunc","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","r","pow","applyRounding","precisionResult","parseFloat","includes","computed","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","suffix","decorateResult","formatted","join","formatOutput","partial","cloned","JSON","parse","stringify"],"mappings":";;;;AACO,MAAMA,EAAiB,iBAIjBC,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAM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AhB,GD+OK,SAAsBmB,EAAQH,EAAGsB,EAAGN,EAAQH,GAClD,GAAIG,IAAWxC,EACd,OAAO2B,EAGR,GAAIa,IAAWvC,EACd,MAAO,CACNsD,MAAO5B,EAAO,GACdrB,OAAQqB,EAAO,GACfe,SAAUlB,EACViC,KAAMX,GAIR,IAAIiD,EAMJ,OAJCA,EDrZmB,MCoZhB1D,EACS,GAAGV,EAAO,MAAMA,EAAO,KAEvBA,EAAOqE,KAAK3D,GAElB0D,CACR,CCjQQE,CAAatE,EAAQH,EAAGsB,EAAGN,EAAQH,EAC3C,CA4BO,SAAS6D,GAAQ1F,KACvBA,GAAO,EAAKsB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKE,UACdA,EAAYF,GAAKG,OACjBA,EF7LoB,IE6LNE,SACdA,EAAWL,GAAKM,OAChBA,EAAStC,EAAMS,SACfA,GAAW,EAAK+B,SAChBA,GAAW,EAAEC,eACbA,EAAiBvC,EAAKwC,UACtBA,EAAY,EAACT,cACbA,EAAgB,CAAA,EAAEG,QAClBA,EAAU,CAAA,EAAEG,UACZA,EAAY,IACT,IACH,MAAM0D,EAAS,CACdhE,cAAeiE,KAAKC,MAAMD,KAAKE,UAAUnE,IACzCG,QAAS8D,KAAKC,MAAMD,KAAKE,UAAUhE,IACnCG,UAAW2D,KAAKC,MAAMD,KAAKE,UAAU7D,KAGtC,OAAQZ,GACPD,EAASC,EAAK,CACbrB,OACAsB,MACAC,OACAC,QACAC,SACAE,cAAegE,EAAOhE,cACtBC,YACAC,SACAC,QAAS6D,EAAO7D,QAChBC,WACAC,SACA7B,WACA8B,UAAW0D,EAAO1D,UAClBC,WACAC,iBACAC,aAEH,QAAAhB,cAAAsE"} diff --git a/dist/filesize.umd.js b/dist/filesize.umd.js index 1241704..52c68db 100644 --- a/dist/filesize.umd.js +++ b/dist/filesize.umd.js @@ -137,7 +137,12 @@ function handleZeroValue( spacer, symbol, ) { - const value = precision > 0 ? (0).toPrecision(precision) : 0; + let value; + if (precision > 0) { + value = (0).toPrecision(precision); + } else { + value = 0; + } if (output === EXPONENT) { return 0; @@ -157,7 +162,16 @@ function handleZeroValue( // Apply full form if (full) { - symbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE); + if (fullforms[0]) { + symbol = fullforms[0]; + } else { + symbol = STRINGS.fullform[actualStandard][0]; + if (bits) { + symbol += BIT; + } else { + symbol += BYTE; + } + } } // Return in requested format @@ -183,7 +197,12 @@ function handleZeroValue( * @returns {Object} Object with result and e properties */ function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) { - const d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e]; + let d; + if (isDecimal) { + d = DECIMAL_POWERS[e]; + } else { + d = BINARY_POWERS[e]; + } let result = num / d; if (bits) { @@ -236,10 +255,19 @@ function applyPrecisionHandling( if (result.includes(E) && e < 8 && autoExponent) { e++; const { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil); - const p = round > 0 ? Math.pow(10, round) : 1; - result = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision( - precision, - ); + let p; + if (round > 0) { + p = Math.pow(10, round); + } else { + p = 1; + } + let computed; + if (p === 1) { + computed = roundingFunc(valueResult); + } else { + computed = roundingFunc(valueResult * p) / p; + } + result = computed.toPrecision(precision); } return { value: result, e }; @@ -295,9 +323,11 @@ function applyNumberFormatting(value, locale, localeOptions, separator, pad, rou */ function calculateExponent(num, e, exponent, isDecimal, precision) { if (e === -1 || isNaN(e)) { - e = isDecimal - ? Math.floor(Math.log(num) / LOG_10_1000) - : Math.floor(Math.log(num) / LOG_2_1024); + if (isDecimal) { + e = Math.floor(Math.log(num) / LOG_10_1000); + } else { + e = Math.floor(Math.log(num) / LOG_2_1024); + } if (e < 0) { e = 0; } @@ -324,8 +354,18 @@ function calculateExponent(num, e, exponent, isDecimal, precision) { * @returns {Object} Object with rounded value and possibly incremented exponent */ function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { - const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; - let r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; + let p; + if (e > 0 && round > 0) { + p = Math.pow(10, round); + } else { + p = 1; + } + let r; + if (p === 1) { + r = roundingFunc(val); + } else { + r = roundingFunc(val * p) / p; + } if (r === ceil && e < 8 && autoExponent) { r = 1; @@ -346,7 +386,17 @@ function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { */ function resolveSymbol(actualStandard, bits, e, isDecimal) { const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; - return isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; + let result; + if (isDecimal && e === 1) { + if (bits) { + result = SI_KBIT; + } else { + result = SI_KBYTE; + } + } else { + result = symbolTable[e]; + } + return result; } /** @@ -393,10 +443,31 @@ function decorateResult( result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); if (full) { - const unit = bits ? BIT : BYTE; - const val = typeof result[0] === "string" ? parseFloat(result[0]) : result[0]; - result[1] = - fullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S); + let unit; + if (bits) { + unit = BIT; + } else { + unit = BYTE; + } + let val; + if (typeof result[0] === "string") { + val = parseFloat(result[0]); + } else { + val = result[0]; + } + // Determine singular/plural suffix + let suffix; + if (val === 1) { + suffix = EMPTY; + } else { + suffix = S; + } + // Determine symbol — custom fullforms are the complete name, defaults get unit+suffix + if (fullforms[e]) { + result[1] = fullforms[e]; + } else { + result[1] = STRINGS.fullform[actualStandard][e] + unit + suffix; + } } } @@ -423,7 +494,13 @@ function formatOutput(result, e, u, output, spacer) { }; } - return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); + let formatted; + if (spacer === SPACE) { + formatted = `${result[0]} ${result[1]}`; + } else { + formatted = result.join(spacer); + } + return formatted; }/** * Converts a file size in bytes to a human-readable string with appropriate units * @param {number|string|bigint} arg - The file size in bytes to convert diff --git a/dist/filesize.umd.min.js b/dist/filesize.umd.min.js index a01ce4c..944f738 100644 --- a/dist/filesize.umd.min.js +++ b/dist/filesize.umd.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.15 */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,function(t){"use strict";const e="Invalid number",i="iec",n="jedec",o="si",r="byte",a="array",s="object",l="string",c="exponent",u="round",f={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],d=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],p=Math.log(1024),m=Math.log(1e3),y={[o]:{isDecimal:!0,ceil:1e3,actualStandard:n},[i]:{isDecimal:!1,ceil:1024,actualStandard:i},[n]:{isDecimal:!1,ceil:1024,actualStandard:n}};function h(t,e,i,n,o,r=!0){let a=t/(i?d[e]:b[e]);return n&&(a*=8,r&&a>=o&&e<8&&(a/=o,e++)),{result:a,e:e}}function B(t,{bits:o=!1,pad:b=!1,base:d=-1,round:B=2,locale:M="",localeOptions:N={},separator:g="",spacer:x=" ",symbols:S={},standard:O="",output:T=l,fullform:E=!1,fullforms:v=[],exponent:w=-1,roundingMethod:D=u,precision:J=0}={}){let j,$=w,k=[],G=0,K="";if("bigint"==typeof t)j=Number(t);else{if(j=Number(t),isNaN(t))throw new TypeError(e);if(!isFinite(j))throw new TypeError(e)}const{isDecimal:P,ceil:Y,actualStandard:Z}=function(t,e){return y[t]?y[t]:2===e?{isDecimal:!1,ceil:1024,actualStandard:i}:{isDecimal:!0,ceil:1e3,actualStandard:n}}(O,d),F=!0===E,z=j<0,I=Math[D];if("function"!=typeof I)throw new TypeError("Invalid rounding method");if(z&&(j=-j),0===j)return function(t,e,i,n,o,l,u,b,d){const p=t>0?(0).toPrecision(t):0;return u===c?0:(d||(d=i?f.symbol[e].bits[0]:f.symbol[e].bytes[0]),n[d]&&(d=n[d]),o&&(d=l[0]||f.fullform[e][0]+(i?"bit":r)),u===a?[p,d]:u===s?{value:p,symbol:d,exponent:0,unit:d}:p+b+d)}(J,Z,o,S,F,v,T,x);const{e:q,precision:A}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/m):Math.floor(Math.log(t)/p))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(j,$,0,P,J);$=q;const C=-1===w||isNaN(w);if(T===c)return $;const{result:H,e:L}=h(j,$,P,o,Y,C);G=H,$=L;const Q=function(t,e,i,n,o,r){const a=i>0&&n>0?Math.pow(10,n):1;let s=1===a?o(t):o(t*a)/a;return s===e&&i<8&&r&&(s=1,i++),{value:s,e:i}}(G,Y,$,B,I,C);if(k[0]=Q.value,$=Q.e,A>0){const t=function(t,e,i,n,o,r,a,s,l,c){"string"==typeof t&&(t=parseFloat(t));let u=t.toPrecision(e);const f=-1===c||isNaN(c);if(u.includes("e")&&i<8&&f){i++;const{result:t}=h(n,i,o,r,a),c=l>0?Math.pow(10,l):1;u=(1===c?s(t):s(t*c)/c).toPrecision(e)}return{value:u,e:i}}(k[0],A,$,j,P,o,Y,I,B,w);k[0]=t.value,$=t.e}return K=function(t,e,i,n){const o=f.symbol[t][e?"bits":"bytes"];return n&&1===i?e?"kbit":"kB":o[i]}(Z,o,$,P),k[1]=K,function(t,e,i,n,o,a,s,l,c,u,b,d,p){if(e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,r){let a=t;if(!0===e?a=a.toLocaleString():e.length>0?a=a.toLocaleString(e,i):n.length>0&&(a=a.toString().replace(".",n)),o&&r>0){const t=a.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,l=r-s;a=`${i[0]}${e}${o.padEnd(s+l,"0")}`}return a}(t[0],n,o,a,s,l),c){const e=p?"bit":r,i="string"==typeof t[0]?parseFloat(t[0]):t[0];t[1]=u[d]||f.fullform[b][d]+e+(1===i?"":"s")}}(k,z,S,M,N,g,b,B,F,v,Z,$,o),function(t,e,i,n,o){return n===a?t:n===s?{value:t[0],symbol:t[1],exponent:e,unit:i}:" "===o?`${t[0]} ${t[1]}`:t.join(o)}(k,$,K,T,x)}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",separator:r="",spacer:a=" ",standard:s="",output:c=l,fullform:f=!1,exponent:b=-1,roundingMethod:d=u,precision:p=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){const M={localeOptions:JSON.parse(JSON.stringify(m)),symbols:JSON.parse(JSON.stringify(y)),fullforms:JSON.parse(JSON.stringify(h))};return l=>B(l,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:M.localeOptions,separator:r,spacer:a,symbols:M.symbols,standard:s,output:c,fullform:f,fullforms:M.fullforms,exponent:b,roundingMethod:d,precision:p})}});//# sourceMappingURL=filesize.umd.min.js.map +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,function(t){"use strict";const e="Invalid number",i="iec",n="jedec",o="si",r="byte",a="array",s="object",l="string",u="exponent",c="round",f={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}},b=[1,1024,1048576,1073741824,1099511627776,0x4000000000000,0x1000000000000000,11805916207174113e5,12089258196146292e8],d=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],p=Math.log(1024),m=Math.log(1e3),y={[o]:{isDecimal:!0,ceil:1e3,actualStandard:n},[i]:{isDecimal:!1,ceil:1024,actualStandard:i},[n]:{isDecimal:!1,ceil:1024,actualStandard:n}};function h(t,e,i,n,o,r=!0){let a;a=i?d[e]:b[e];let s=t/a;return n&&(s*=8,r&&s>=o&&e<8&&(s/=o,e++)),{result:s,e:e}}function B(t,{bits:o=!1,pad:b=!1,base:d=-1,round:B=2,locale:M="",localeOptions:N={},separator:g="",spacer:x=" ",symbols:S={},standard:O="",output:T=l,fullform:E=!1,fullforms:v=[],exponent:w=-1,roundingMethod:D=c,precision:J=0}={}){let j,$=w,k=[],G=0,K="";if("bigint"==typeof t)j=Number(t);else{if(j=Number(t),isNaN(t))throw new TypeError(e);if(!isFinite(j))throw new TypeError(e)}const{isDecimal:P,ceil:Y,actualStandard:Z}=function(t,e){return y[t]?y[t]:2===e?{isDecimal:!1,ceil:1024,actualStandard:i}:{isDecimal:!0,ceil:1e3,actualStandard:n}}(O,d),F=!0===E,z=j<0,I=Math[D];if("function"!=typeof I)throw new TypeError("Invalid rounding method");if(z&&(j=-j),0===j)return function(t,e,i,n,o,l,c,b,d){let p;return p=t>0?(0).toPrecision(t):0,c===u?0:(d||(d=i?f.symbol[e].bits[0]:f.symbol[e].bytes[0]),n[d]&&(d=n[d]),o&&(l[0]?d=l[0]:(d=f.fullform[e][0],d+=i?"bit":r)),c===a?[p,d]:c===s?{value:p,symbol:d,exponent:0,unit:d}:p+b+d)}(J,Z,o,S,F,v,T,x);const{e:q,precision:A}=function(t,e,i,n,o){return(-1===e||isNaN(e))&&(e=n?Math.floor(Math.log(t)/m):Math.floor(Math.log(t)/p))<0&&(e=0),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(j,$,0,P,J);$=q;const C=-1===w||isNaN(w);if(T===u)return $;const{result:H,e:L}=h(j,$,P,o,Y,C);G=H,$=L;const Q=function(t,e,i,n,o,r){let a,s;return a=i>0&&n>0?Math.pow(10,n):1,s=1===a?o(t):o(t*a)/a,s===e&&i<8&&r&&(s=1,i++),{value:s,e:i}}(G,Y,$,B,I,C);if(k[0]=Q.value,$=Q.e,A>0){const t=function(t,e,i,n,o,r,a,s,l,u){"string"==typeof t&&(t=parseFloat(t));let c=t.toPrecision(e);const f=-1===u||isNaN(u);if(c.includes("e")&&i<8&&f){i++;const{result:t}=h(n,i,o,r,a);let u,f;u=l>0?Math.pow(10,l):1,f=1===u?s(t):s(t*u)/u,c=f.toPrecision(e)}return{value:c,e:i}}(k[0],A,$,j,P,o,Y,I,B,w);k[0]=t.value,$=t.e}return K=function(t,e,i,n){const o=f.symbol[t][e?"bits":"bytes"];let r;return r=n&&1===i?e?"kbit":"kB":o[i],r}(Z,o,$,P),k[1]=K,function(t,e,i,n,o,a,s,l,u,c,b,d,p){if(e&&(t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),t[0]=function(t,e,i,n,o,r){let a=t;if(!0===e?a=a.toLocaleString():e.length>0?a=a.toLocaleString(e,i):n.length>0&&(a=a.toString().replace(".",n)),o&&r>0){const t=a.toString(),e=n||(t.slice(1).match(/[.,]/g)||[]).pop()||".",i=t.split(e),o=i[1]||"",s=o.length,l=r-s;a=`${i[0]}${e}${o.padEnd(s+l,"0")}`}return a}(t[0],n,o,a,s,l),u){let e,i,n;e=p?"bit":r,i="string"==typeof t[0]?parseFloat(t[0]):t[0],n=1===i?"":"s",c[d]?t[1]=c[d]:t[1]=f.fullform[b][d]+e+n}}(k,z,S,M,N,g,b,B,F,v,Z,$,o),function(t,e,i,n,o){if(n===a)return t;if(n===s)return{value:t[0],symbol:t[1],exponent:e,unit:i};let r;return r=" "===o?`${t[0]} ${t[1]}`:t.join(o),r}(k,$,K,T,x)}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",separator:r="",spacer:a=" ",standard:s="",output:u=l,fullform:f=!1,exponent:b=-1,roundingMethod:d=c,precision:p=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){const M={localeOptions:JSON.parse(JSON.stringify(m)),symbols:JSON.parse(JSON.stringify(y)),fullforms:JSON.parse(JSON.stringify(h))};return l=>B(l,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:M.localeOptions,separator:r,spacer:a,symbols:M.symbols,standard:s,output:u,fullform:f,fullforms:M.fullforms,exponent:b,roundingMethod:d,precision:p})}});//# sourceMappingURL=filesize.umd.min.js.map diff --git a/dist/filesize.umd.min.js.map b/dist/filesize.umd.min.js.map index b7c2771..5dab373 100644 --- a/dist/filesize.umd.min.js.map +++ b/dist/filesize.umd.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tconst value = precision > 0 ? (0).toPrecision(precision) : 0;\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tsymbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE);\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e];\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tif (typeof value === \"string\") {\n\t\tvalue = parseFloat(value);\n\t}\n\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tconst p = round > 0 ? Math.pow(10, round) : 1;\n\t\tresult = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision(\n\t\t\tprecision,\n\t\t);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\te = isDecimal\n\t\t\t? Math.floor(Math.log(num) / LOG_10_1000)\n\t\t\t: Math.floor(Math.log(num) / LOG_2_1024);\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tconst p = e > 0 && round > 0 ? Math.pow(10, round) : 1;\n\tlet r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p;\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\treturn isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e];\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tconst unit = bits ? BIT : BYTE;\n\t\tconst val = typeof result[0] === \"string\" ? parseFloat(result[0]) : result[0];\n\t\tresult[1] =\n\t\t\tfullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S);\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\treturn spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer);\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum,\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tif (typeof arg === \"bigint\") {\n\t\tnum = Number(arg);\n\t} else {\n\t\tnum = Number(arg);\n\n\t\tif (isNaN(arg)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\n\t\tif (!isFinite(num)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\t}\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n\tlocaleOptions = {},\n\tsymbols = {},\n\tfullforms = [],\n} = {}) {\n\tconst cloned = {\n\t\tlocaleOptions: JSON.parse(JSON.stringify(localeOptions)),\n\t\tsymbols: JSON.parse(JSON.stringify(symbols)),\n\t\tfullforms: JSON.parse(JSON.stringify(fullforms)),\n\t};\n\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions: cloned.localeOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols: cloned.symbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms: cloned.fullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","INVALID_NUMBER","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","Number","isNaN","TypeError","isFinite","getBaseConfiguration","full","neg","roundingFunc","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","pow","r","applyRounding","precisionResult","parseFloat","includes","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","decorateResult","join","formatOutput","partial","cloned","JSON","parse","stringify"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,SAAA,CAAA,EAAA,CAAA,CAAAC,KAAA,SAAAP,GAAA,aACO,MAAMQ,EAAiB,iBAIjBC,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,I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AAQH,EAC3C,CAuEAhD,EAAAM,SAAAA,EAAAN,EAAA0G,QA3CO,UAAiBrF,KACvBA,GAAO,EAAKoB,IACZA,GAAM,EAAKC,KACXA,GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKE,UACdA,EAAYF,GAAKG,OACjBA,EF7LoB,IE6LNE,SACdA,EAAWL,GAAKM,OAChBA,EAASpC,EAAMS,SACfA,GAAW,EAAK6B,SAChBA,GAAW,EAAEC,eACbA,EAAiBrC,EAAKsC,UACtBA,EAAY,EAACT,cACbA,EAAgB,CAAA,EAAEG,QAClBA,EAAU,CAAA,EAAEG,UACZA,EAAY,IACT,IACH,MAAMuD,EAAS,CACd7D,cAAe8D,KAAKC,MAAMD,KAAKE,UAAUhE,IACzCG,QAAS2D,KAAKC,MAAMD,KAAKE,UAAU7D,IACnCG,UAAWwD,KAAKC,MAAMD,KAAKE,UAAU1D,KAGtC,OAAQZ,GACPlC,EAASkC,EAAK,CACbnB,OACAoB,MACAC,OACAC,QACAC,SACAE,cAAe6D,EAAO7D,cACtBC,YACAC,SACAC,QAAS0D,EAAO1D,QAChBC,WACAC,SACA3B,WACA4B,UAAWuD,EAAOvD,UAClBC,WACAC,iBACAC,aAEH,CAAA"} +{"version":3,"file":"filesize.umd.min.js","sources":["../src/constants.js","../src/helpers.js","../src/filesize.js"],"sourcesContent":["// Error Messages\nexport const INVALID_NUMBER = \"Invalid number\";\nexport const INVALID_ROUND = \"Invalid rounding method\";\n\n// Standard Types\nexport const IEC = \"iec\";\nexport const JEDEC = \"jedec\";\nexport const SI = \"si\";\n\n// Unit Types\nexport const BIT = \"bit\";\nexport const BITS = \"bits\";\nexport const BYTE = \"byte\";\nexport const BYTES = \"bytes\";\nexport const SI_KBIT = \"kbit\";\nexport const SI_KBYTE = \"kB\";\n\n// Output Format Types\nexport const ARRAY = \"array\";\nexport const FUNCTION = \"function\";\nexport const OBJECT = \"object\";\nexport const STRING = \"string\";\n\n// Processing Constants\nexport const EXPONENT = \"exponent\";\nexport const ROUND = \"round\";\n\n// Special Characters and Values\nexport const E = \"e\";\nexport const EMPTY = \"\";\nexport const PERIOD = \".\";\nexport const S = \"s\";\nexport const SPACE = \" \";\nexport const ZERO = \"0\";\n\n// Data Structures\nexport const STRINGS = {\n\tsymbol: {\n\t\tiec: {\n\t\t\tbits: [\"bit\", \"Kibit\", \"Mibit\", \"Gibit\", \"Tibit\", \"Pibit\", \"Eibit\", \"Zibit\", \"Yibit\"],\n\t\t\tbytes: [\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"],\n\t\t},\n\t\tjedec: {\n\t\t\tbits: [\"bit\", \"Kbit\", \"Mbit\", \"Gbit\", \"Tbit\", \"Pbit\", \"Ebit\", \"Zbit\", \"Ybit\"],\n\t\t\tbytes: [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"],\n\t\t},\n\t},\n\tfullform: {\n\t\tiec: [\"\", \"kibi\", \"mebi\", \"gibi\", \"tebi\", \"pebi\", \"exbi\", \"zebi\", \"yobi\"],\n\t\tjedec: [\"\", \"kilo\", \"mega\", \"giga\", \"tera\", \"peta\", \"exa\", \"zetta\", \"yotta\"],\n\t},\n};\n\n// Pre-computed lookup tables for performance optimization\nexport const BINARY_POWERS = [\n\t1, // 2^0\n\t1024, // 2^10\n\t1048576, // 2^20\n\t1073741824, // 2^30\n\t1099511627776, // 2^40\n\t1125899906842624, // 2^50\n\t1152921504606846976, // 2^60\n\t1180591620717411303424, // 2^70\n\t1208925819614629174706176, // 2^80\n];\n\nexport const DECIMAL_POWERS = [\n\t1, // 10^0\n\t1000, // 10^3\n\t1000000, // 10^6\n\t1000000000, // 10^9\n\t1000000000000, // 10^12\n\t1000000000000000, // 10^15\n\t1000000000000000000, // 10^18\n\t1000000000000000000000, // 10^21\n\t1000000000000000000000000, // 10^24\n];\n\n// Pre-computed log values for faster exponent calculation\nexport const LOG_2_1024 = Math.log(1024);\nexport const LOG_10_1000 = Math.log(1000);\n","import {\n\tARRAY,\n\tBINARY_POWERS,\n\tBIT,\n\tBITS,\n\tBYTE,\n\tBYTES,\n\tDECIMAL_POWERS,\n\tE,\n\tEMPTY,\n\tEXPONENT,\n\tIEC,\n\tJEDEC,\n\tLOG_10_1000,\n\tLOG_2_1024,\n\tOBJECT,\n\tPERIOD,\n\tS,\n\tSI,\n\tSI_KBIT,\n\tSI_KBYTE,\n\tSPACE,\n\tSTRINGS,\n\tZERO,\n} from \"./constants.js\";\n\n// Cached configuration lookup for better performance\nconst STANDARD_CONFIGS = {\n\t[SI]: { isDecimal: true, ceil: 1000, actualStandard: JEDEC },\n\t[IEC]: { isDecimal: false, ceil: 1024, actualStandard: IEC },\n\t[JEDEC]: { isDecimal: false, ceil: 1024, actualStandard: JEDEC },\n};\n\n/**\n * Optimized base configuration lookup\n * @param {string} standard - Standard type\n * @param {number} base - Base number\n * @returns {Object} Configuration object\n */\nexport function getBaseConfiguration(standard, base) {\n\t// Use cached lookup table for better performance\n\tif (STANDARD_CONFIGS[standard]) {\n\t\treturn STANDARD_CONFIGS[standard];\n\t}\n\n\t// Base override\n\tif (base === 2) {\n\t\treturn { isDecimal: false, ceil: 1024, actualStandard: IEC };\n\t}\n\n\t// Default\n\treturn { isDecimal: true, ceil: 1000, actualStandard: JEDEC };\n}\n\n/**\n * Optimized zero value handling\n * @param {number} precision - Precision value\n * @param {string} actualStandard - Standard to use\n * @param {boolean} bits - Whether to use bits\n * @param {Object} symbols - Custom symbols\n * @param {boolean} full - Whether to use full form\n * @param {Array} fullforms - Custom full forms\n * @param {string} output - Output format\n * @param {string} spacer - Spacer character\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @returns {string|Array|Object|number} Formatted result\n */\nexport function handleZeroValue(\n\tprecision,\n\tactualStandard,\n\tbits,\n\tsymbols,\n\tfull,\n\tfullforms,\n\toutput,\n\tspacer,\n\tsymbol,\n) {\n\tlet value;\n\tif (precision > 0) {\n\t\tvalue = (0).toPrecision(precision);\n\t} else {\n\t\tvalue = 0;\n\t}\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\t// Set default symbol if not provided\n\tif (!symbol) {\n\t\tsymbol = bits\n\t\t\t? STRINGS.symbol[actualStandard].bits[0]\n\t\t\t: STRINGS.symbol[actualStandard].bytes[0];\n\t}\n\n\t// Apply symbol customization\n\tif (symbols[symbol]) {\n\t\tsymbol = symbols[symbol];\n\t}\n\n\t// Apply full form\n\tif (full) {\n\t\tif (fullforms[0]) {\n\t\t\tsymbol = fullforms[0];\n\t\t} else {\n\t\t\tsymbol = STRINGS.fullform[actualStandard][0];\n\t\t\tif (bits) {\n\t\t\t\tsymbol += BIT;\n\t\t\t} else {\n\t\t\t\tsymbol += BYTE;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return in requested format\n\tif (output === ARRAY) {\n\t\treturn [value, symbol];\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn { value, symbol, exponent: 0, unit: symbol };\n\t}\n\n\treturn value + spacer + symbol;\n}\n\n/**\n * Optimized value calculation with bits handling\n * @param {number} num - Input number\n * @param {number} e - Exponent\n * @param {boolean} isDecimal - Whether to use decimal powers\n * @param {boolean} bits - Whether to calculate bits\n * @param {number} ceil - Ceiling value for auto-increment\n * @param {boolean} autoExponent - Whether exponent is auto (-1 or NaN)\n * @returns {Object} Object with result and e properties\n */\nexport function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tlet d;\n\tif (isDecimal) {\n\t\td = DECIMAL_POWERS[e];\n\t} else {\n\t\td = BINARY_POWERS[e];\n\t}\n\tlet result = num / d;\n\n\tif (bits) {\n\t\tresult *= 8;\n\t\t// Handle auto-increment for bits (only when exponent is auto)\n\t\tif (autoExponent && result >= ceil && e < 8) {\n\t\t\tresult /= ceil;\n\t\t\te++;\n\t\t}\n\t}\n\n\treturn { result, e };\n}\n\n/**\n * Optimized precision handling with scientific notation correction\n * @param {number} value - Current value\n * @param {number} precision - Precision to apply\n * @param {number} e - Current exponent\n * @param {number} num - Original number\n * @param {boolean} isDecimal - Whether using decimal base\n * @param {boolean} bits - Whether calculating bits\n * @param {number} ceil - Ceiling value\n * @param {Function} roundingFunc - Rounding function\n * @param {number} round - Round value\n * @param {number} exponent - Forced exponent (-1 for auto)\n * @returns {Object} Object with value and e properties\n */\nexport function applyPrecisionHandling(\n\tvalue,\n\tprecision,\n\te,\n\tnum,\n\tisDecimal,\n\tbits,\n\tceil,\n\troundingFunc,\n\tround,\n\texponent,\n) {\n\tif (typeof value === \"string\") {\n\t\tvalue = parseFloat(value);\n\t}\n\n\tlet result = value.toPrecision(precision);\n\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\t// Handle scientific notation by recalculating with incremented exponent\n\tif (result.includes(E) && e < 8 && autoExponent) {\n\t\te++;\n\t\tconst { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil);\n\t\tlet p;\n\t\tif (round > 0) {\n\t\t\tp = Math.pow(10, round);\n\t\t} else {\n\t\t\tp = 1;\n\t\t}\n\t\tlet computed;\n\t\tif (p === 1) {\n\t\t\tcomputed = roundingFunc(valueResult);\n\t\t} else {\n\t\t\tcomputed = roundingFunc(valueResult * p) / p;\n\t\t}\n\t\tresult = computed.toPrecision(precision);\n\t}\n\n\treturn { value: result, e };\n}\n\n/**\n * Optimized number formatting with locale, separator, and padding\n * @param {number|string} value - Value to format\n * @param {string|boolean} locale - Locale setting\n * @param {Object} localeOptions - Locale options\n * @param {string} separator - Custom separator\n * @param {boolean} pad - Whether to pad\n * @param {number} round - Round value\n * @returns {string|number} Formatted value\n */\nexport function applyNumberFormatting(value, locale, localeOptions, separator, pad, round) {\n\tlet result = value;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString();\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, localeOptions);\n\t} else if (separator.length > 0) {\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Apply padding\n\tif (pad && round > 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || (resultStr.slice(1).match(/[.,]/g) || []).pop() || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tconst l = s.length;\n\t\tconst n = round - l;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;\n\t}\n\n\treturn result;\n}\n\n/**\n * Calculates exponent from the input value using pre-computed log values and clamps to supported range\n * Also adjusts precision when exponent exceeds the lookup table bounds\n * @param {number} num - Input file size in bytes\n * @param {number} e - Current exponent value\n * @param {number} exponent - Original user-provided exponent option (-1 for auto)\n * @param {boolean} isDecimal - Whether to use decimal (SI) base\n * @param {number} precision - Current precision value (modified when e > 8)\n * @returns {Object} Object with computed e value and possibly adjusted precision\n */\nexport function calculateExponent(num, e, exponent, isDecimal, precision) {\n\tif (e === -1 || isNaN(e)) {\n\t\tif (isDecimal) {\n\t\t\te = Math.floor(Math.log(num) / LOG_10_1000);\n\t\t} else {\n\t\t\te = Math.floor(Math.log(num) / LOG_2_1024);\n\t\t}\n\t\tif (e < 0) {\n\t\t\te = 0;\n\t\t}\n\t}\n\n\tif (e > 8) {\n\t\tif (precision > 0) {\n\t\t\tprecision += 8 - e;\n\t\t}\n\t\treturn { e: 8, precision };\n\t}\n\n\treturn { e, precision };\n}\n\n/**\n * Applies rounding to the raw calculated value and handles auto-increment ceiling\n * @param {number} val - Raw value before rounding\n * @param {number} ceil - Ceiling threshold (1000 for SI, 1024 for IEC)\n * @param {number} e - Current exponent value\n * @param {number} round - Number of decimal places\n * @param {Function} roundingFunc - Rounding method (Math.round, Math.floor, Math.ceil)\n * @param {boolean} autoExponent - Whether exponent is auto-calculated (-1 or NaN)\n * @returns {Object} Object with rounded value and possibly incremented exponent\n */\nexport function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {\n\tlet p;\n\tif (e > 0 && round > 0) {\n\t\tp = Math.pow(10, round);\n\t} else {\n\t\tp = 1;\n\t}\n\tlet r;\n\tif (p === 1) {\n\t\tr = roundingFunc(val);\n\t} else {\n\t\tr = roundingFunc(val * p) / p;\n\t}\n\n\tif (r === ceil && e < 8 && autoExponent) {\n\t\tr = 1;\n\t\te++;\n\t}\n\n\treturn { value: r, e };\n}\n\n/**\n * Resolves the unit symbol for the given standard, bits mode, and exponent\n * Handles SI standard special case where exponent 1 always uses \"kB\" or \"kbit\"\n * @param {string} actualStandard - The resolved standard (iec, jedec)\n * @param {boolean} bits - Whether formatting bit values\n * @param {number} e - Current exponent index\n * @param {boolean} isDecimal - Whether using decimal (SI) base\n * @returns {string} The resolved unit symbol string\n */\nexport function resolveSymbol(actualStandard, bits, e, isDecimal) {\n\tconst symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES];\n\tlet result;\n\tif (isDecimal && e === 1) {\n\t\tif (bits) {\n\t\t\tresult = SI_KBIT;\n\t\t} else {\n\t\t\tresult = SI_KBYTE;\n\t\t}\n\t} else {\n\t\tresult = symbolTable[e];\n\t}\n\treturn result;\n}\n\n/**\n * Decorates the result: applies negation, custom symbols, number formatting, and full form names\n * Mutates the result array in-place for both value (index 0) and symbol (index 1)\n * @param {Array} result - Result array with numeric value at [0] and string symbol at [1]\n * @param {boolean} neg - Whether the original input was negative\n * @param {Object} symbols - Custom symbol override map\n * @param {string|boolean} locale - Locale string for formatting\n * @param {Object} localeOptions - Additional locale formatting options\n * @param {string} separator - Custom decimal separator\n * @param {boolean} pad - Whether zero-pad decimals\n * @param {number} round - Target decimal count for padding\n * @param {boolean} full - Whether to use full unit names\n * @param {Array} fullforms - Custom full unit name overrides\n * @param {string} actualStandard - Unit standard for full form lookup\n * @param {number} e - Current exponent index\n * @param {boolean} bits - Whether formatting bit values\n * @returns {void} Mutates result array in place\n */\nexport function decorateResult(\n\tresult,\n\tneg,\n\tsymbols,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\tfull,\n\tfullforms,\n\tactualStandard,\n\te,\n\tbits,\n) {\n\tif (neg) {\n\t\tresult[0] = -result[0];\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\tresult[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round);\n\n\tif (full) {\n\t\tlet unit;\n\t\tif (bits) {\n\t\t\tunit = BIT;\n\t\t} else {\n\t\t\tunit = BYTE;\n\t\t}\n\t\tlet val;\n\t\tif (typeof result[0] === \"string\") {\n\t\t\tval = parseFloat(result[0]);\n\t\t} else {\n\t\t\tval = result[0];\n\t\t}\n\t\t// Determine singular/plural suffix\n\t\tlet suffix;\n\t\tif (val === 1) {\n\t\t\tsuffix = EMPTY;\n\t\t} else {\n\t\t\tsuffix = S;\n\t\t}\n\t\t// Determine symbol — custom fullforms are the complete name, defaults get unit+suffix\n\t\tif (fullforms[e]) {\n\t\t\tresult[1] = fullforms[e];\n\t\t} else {\n\t\t\tresult[1] = STRINGS.fullform[actualStandard][e] + unit + suffix;\n\t\t}\n\t}\n}\n\n/**\n * Formats the computed result array into the requested output type\n * @param {Array} result - Result array with formatted value at [0] and symbol at [1]\n * @param {number} e - Current exponent\n * @param {string} u - Original resolved symbol (before custom override)\n * @param {string} output - Output type (ARRAY, OBJECT, STRING)\n * @param {string} spacer - String separator between value and unit\n * @returns {string|Array|Object|number} Formatted result in requested type\n */\nexport function formatOutput(result, e, u, output, spacer) {\n\tif (output === ARRAY) {\n\t\treturn result;\n\t}\n\n\tif (output === OBJECT) {\n\t\treturn {\n\t\t\tvalue: result[0],\n\t\t\tsymbol: result[1],\n\t\t\texponent: e,\n\t\t\tunit: u,\n\t\t};\n\t}\n\n\tlet formatted;\n\tif (spacer === SPACE) {\n\t\tformatted = `${result[0]} ${result[1]}`;\n\t} else {\n\t\tformatted = result.join(spacer);\n\t}\n\treturn formatted;\n}\n","import {\n\tEMPTY,\n\tEXPONENT,\n\tFUNCTION,\n\tINVALID_NUMBER,\n\tINVALID_ROUND,\n\tROUND,\n\tSPACE,\n\tSTRING,\n} from \"./constants.js\";\nimport {\n\tapplyPrecisionHandling,\n\tapplyRounding,\n\tcalculateExponent,\n\tcalculateOptimizedValue,\n\tdecorateResult,\n\tformatOutput,\n\tgetBaseConfiguration,\n\thandleZeroValue,\n\tresolveSymbol,\n} from \"./helpers.js\";\n\n/**\n * Converts a file size in bytes to a human-readable string with appropriate units\n * @param {number|string|bigint} arg - The file size in bytes to convert\n * @param {Object} [options={}] - Configuration options for formatting\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {string|Array|Object|number} Formatted file size based on output option\n * @throws {TypeError} When arg is not a valid number or roundingMethod is invalid\n * @example\n * filesize(1024) // \"1.02 kB\"\n * filesize(1024, {bits: true}) // \"8.19 kbit\"\n * filesize(1024, {output: \"object\"}) // {value: 1.02, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n */\nexport function filesize(\n\targ,\n\t{\n\t\tbits = false,\n\t\tpad = false,\n\t\tbase = -1,\n\t\tround = 2,\n\t\tlocale = EMPTY,\n\t\tlocaleOptions = {},\n\t\tseparator = EMPTY,\n\t\tspacer = SPACE,\n\t\tsymbols = {},\n\t\tstandard = EMPTY,\n\t\toutput = STRING,\n\t\tfullform = false,\n\t\tfullforms = [],\n\t\texponent = -1,\n\t\troundingMethod = ROUND,\n\t\tprecision = 0,\n\t} = {},\n) {\n\tlet e = exponent,\n\t\tnum,\n\t\tresult = [],\n\t\tval = 0,\n\t\tu = EMPTY;\n\n\tif (typeof arg === \"bigint\") {\n\t\tnum = Number(arg);\n\t} else {\n\t\tnum = Number(arg);\n\n\t\tif (isNaN(arg)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\n\t\tif (!isFinite(num)) {\n\t\t\tthrow new TypeError(INVALID_NUMBER);\n\t\t}\n\t}\n\n\tconst { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base);\n\n\tconst full = fullform === true,\n\t\tneg = num < 0,\n\t\troundingFunc = Math[roundingMethod];\n\n\tif (typeof roundingFunc !== FUNCTION) {\n\t\tthrow new TypeError(INVALID_ROUND);\n\t}\n\n\tif (neg) {\n\t\tnum = -num;\n\t}\n\n\tif (num === 0) {\n\t\treturn handleZeroValue(\n\t\t\tprecision,\n\t\t\tactualStandard,\n\t\t\tbits,\n\t\t\tsymbols,\n\t\t\tfull,\n\t\t\tfullforms,\n\t\t\toutput,\n\t\t\tspacer,\n\t\t);\n\t}\n\n\t// Exponent calculation + clamp + precision adjustment\n\tconst { e: calculatedE, precision: precisionAdjusted } = calculateExponent(\n\t\tnum,\n\t\te,\n\t\texponent,\n\t\tisDecimal,\n\t\tprecision,\n\t);\n\te = calculatedE;\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tif (output === EXPONENT) {\n\t\treturn e;\n\t}\n\n\tconst { result: valueResult, e: valueExponent } = calculateOptimizedValue(\n\t\tnum,\n\t\te,\n\t\tisDecimal,\n\t\tbits,\n\t\tceil,\n\t\tautoExponent,\n\t);\n\tval = valueResult;\n\te = valueExponent;\n\n\t// Rounding + auto-increment ceiling\n\tconst rounded = applyRounding(val, ceil, e, round, roundingFunc, autoExponent);\n\tresult[0] = rounded.value;\n\te = rounded.e;\n\n\t// Precision handling\n\tif (precisionAdjusted > 0) {\n\t\tconst precisionResult = applyPrecisionHandling(\n\t\t\tresult[0],\n\t\t\tprecisionAdjusted,\n\t\t\te,\n\t\t\tnum,\n\t\t\tisDecimal,\n\t\t\tbits,\n\t\t\tceil,\n\t\t\troundingFunc,\n\t\t\tround,\n\t\t\texponent,\n\t\t);\n\t\tresult[0] = precisionResult.value;\n\t\te = precisionResult.e;\n\t}\n\n\tu = resolveSymbol(actualStandard, bits, e, isDecimal);\n\tresult[1] = u;\n\n\tdecorateResult(\n\t\tresult,\n\t\tneg,\n\t\tsymbols,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\tfull,\n\t\tfullforms,\n\t\tactualStandard,\n\t\te,\n\t\tbits,\n\t);\n\n\treturn formatOutput(result, e, u, output, spacer);\n}\n\n/**\n * Creates a partially applied version of filesize with preset options\n * @param {Object} [options={}] - Configuration options (same as filesize)\n * @param {boolean} [options.bits=false] - If true, calculates bits instead of bytes\n * @param {boolean} [options.pad=false] - If true, pads decimal places to match round parameter\n * @param {number} [options.base=-1] - Number base (2 for binary, 10 for decimal, -1 for auto)\n * @param {number} [options.round=2] - Number of decimal places to round to\n * @param {string|boolean} [options.locale=\"\"] - Locale for number formatting, true for system locale\n * @param {Object} [options.localeOptions={}] - Additional options for locale formatting\n * @param {string} [options.separator=\"\"] - Custom decimal separator\n * @param {string} [options.spacer=\" \"] - String to separate value and unit\n * @param {Object} [options.symbols={}] - Custom unit symbols\n * @param {string} [options.standard=\"\"] - Unit standard to use (SI, IEC, JEDEC)\n * @param {string} [options.output=\"string\"] - Output format: \"string\", \"array\", \"object\", or \"exponent\"\n * @param {boolean} [options.fullform=false] - If true, uses full unit names instead of abbreviations\n * @param {Array} [options.fullforms=[]] - Custom full unit names\n * @param {number} [options.exponent=-1] - Force specific exponent (-1 for auto)\n * @param {string} [options.roundingMethod=\"round\"] - Math rounding method to use\n * @param {number} [options.precision=0] - Number of significant digits (0 for auto)\n * @returns {Function} A function that takes a file size and returns formatted output\n * @example\n * const formatBytes = partial({round: 1, standard: \"iec\"});\n * formatBytes(1024) // \"1 KiB\"\n * formatBytes(2048) // \"2 KiB\"\n * formatBytes(1536) // \"1.5 KiB\"\n */\nexport function partial({\n\tbits = false,\n\tpad = false,\n\tbase = -1,\n\tround = 2,\n\tlocale = EMPTY,\n\tseparator = EMPTY,\n\tspacer = SPACE,\n\tstandard = EMPTY,\n\toutput = STRING,\n\tfullform = false,\n\texponent = -1,\n\troundingMethod = ROUND,\n\tprecision = 0,\n\tlocaleOptions = {},\n\tsymbols = {},\n\tfullforms = [],\n} = {}) {\n\tconst cloned = {\n\t\tlocaleOptions: JSON.parse(JSON.stringify(localeOptions)),\n\t\tsymbols: JSON.parse(JSON.stringify(symbols)),\n\t\tfullforms: JSON.parse(JSON.stringify(fullforms)),\n\t};\n\n\treturn (arg) =>\n\t\tfilesize(arg, {\n\t\t\tbits,\n\t\t\tpad,\n\t\t\tbase,\n\t\t\tround,\n\t\t\tlocale,\n\t\t\tlocaleOptions: cloned.localeOptions,\n\t\t\tseparator,\n\t\t\tspacer,\n\t\t\tsymbols: cloned.symbols,\n\t\t\tstandard,\n\t\t\toutput,\n\t\t\tfullform,\n\t\t\tfullforms: cloned.fullforms,\n\t\t\texponent,\n\t\t\troundingMethod,\n\t\t\tprecision,\n\t\t});\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","filesize","this","INVALID_NUMBER","IEC","JEDEC","SI","BYTE","ARRAY","OBJECT","STRING","EXPONENT","ROUND","STRINGS","symbol","iec","bits","bytes","jedec","fullform","BINARY_POWERS","DECIMAL_POWERS","LOG_2_1024","Math","log","LOG_10_1000","STANDARD_CONFIGS","isDecimal","ceil","actualStandard","calculateOptimizedValue","num","e","autoExponent","d","result","arg","pad","base","round","locale","EMPTY","localeOptions","separator","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","Number","isNaN","TypeError","isFinite","getBaseConfiguration","full","neg","roundingFunc","value","toPrecision","unit","handleZeroValue","calculatedE","precisionAdjusted","floor","calculateExponent","valueResult","valueExponent","rounded","p","r","pow","applyRounding","precisionResult","parseFloat","includes","computed","applyPrecisionHandling","symbolTable","resolveSymbol","toLocaleString","length","toString","replace","resultStr","x","slice","match","pop","tmp","split","s","l","n","padEnd","applyNumberFormatting","suffix","decorateResult","formatted","join","formatOutput","partial","cloned","JSON","parse","stringify"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,SAAA,CAAA,EAAA,CAAA,CAAAC,KAAA,SAAAP,GAAA,aACO,MAAMQ,EAAiB,iBAIjBC,EAAM,MACNC,EAAQ,QACRC,EAAK,KAKLC,EAAO,OAMPC,EAAQ,QAERC,EAAS,SACTC,EAAS,SAGTC,EAAW,WACXC,EAAQ,QAWRC,EAAU,CACtBC,OAAQ,CACPC,IAAK,CACJC,KAAM,CAAC,MAAO,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,QAAS,SAC7EC,MAAO,CAAC,IAAK,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,QAE/DC,MAAO,CACNF,KAAM,CAAC,MAAO,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QACtEC,MAAO,CAAC,IAAK,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,QAGzDE,SAAU,CACTJ,IAAK,CAAC,GAAI,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,OAAQ,QAClEG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AAQ,EAACC,OACTA,EAASC,GAAKE,UACdA,EAAYF,GAAKG,OACjBA,EF7LoB,IE6LNE,SACdA,EAAWL,GAAKM,OAChBA,EAASrC,EAAMS,SACfA,GAAW,EAAK8B,SAChBA,GAAW,EAAEC,eACbA,EAAiBtC,EAAKuC,UACtBA,EAAY,EAACT,cACbA,EAAgB,CAAA,EAAEG,QAClBA,EAAU,CAAA,EAAEG,UACZA,EAAY,IACT,IACH,MAAM0D,EAAS,CACdhE,cAAeiE,KAAKC,MAAMD,KAAKE,UAAUnE,IACzCG,QAAS8D,KAAKC,MAAMD,KAAKE,UAAUhE,IACnCG,UAAW2D,KAAKC,MAAMD,KAAKE,UAAU7D,KAGtC,OAAQZ,GACPnC,EAASmC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,cAAegE,EAAOhE,cACtBC,YACAC,SACAC,QAAS6D,EAAO7D,QAChBC,WACAC,SACA5B,WACA6B,UAAW0D,EAAO1D,UAClBC,WACAC,iBACAC,aAEH,CAAA"} diff --git a/src/helpers.js b/src/helpers.js index d902728..7001825 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -76,7 +76,12 @@ export function handleZeroValue( spacer, symbol, ) { - const value = precision > 0 ? (0).toPrecision(precision) : 0; + let value; + if (precision > 0) { + value = (0).toPrecision(precision); + } else { + value = 0; + } if (output === EXPONENT) { return 0; @@ -96,7 +101,16 @@ export function handleZeroValue( // Apply full form if (full) { - symbol = fullforms[0] || STRINGS.fullform[actualStandard][0] + (bits ? BIT : BYTE); + if (fullforms[0]) { + symbol = fullforms[0]; + } else { + symbol = STRINGS.fullform[actualStandard][0]; + if (bits) { + symbol += BIT; + } else { + symbol += BYTE; + } + } } // Return in requested format @@ -122,7 +136,12 @@ export function handleZeroValue( * @returns {Object} Object with result and e properties */ export function calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent = true) { - const d = isDecimal ? DECIMAL_POWERS[e] : BINARY_POWERS[e]; + let d; + if (isDecimal) { + d = DECIMAL_POWERS[e]; + } else { + d = BINARY_POWERS[e]; + } let result = num / d; if (bits) { @@ -175,10 +194,19 @@ export function applyPrecisionHandling( if (result.includes(E) && e < 8 && autoExponent) { e++; const { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil); - const p = round > 0 ? Math.pow(10, round) : 1; - result = (p === 1 ? roundingFunc(valueResult) : roundingFunc(valueResult * p) / p).toPrecision( - precision, - ); + let p; + if (round > 0) { + p = Math.pow(10, round); + } else { + p = 1; + } + let computed; + if (p === 1) { + computed = roundingFunc(valueResult); + } else { + computed = roundingFunc(valueResult * p) / p; + } + result = computed.toPrecision(precision); } return { value: result, e }; @@ -234,9 +262,11 @@ export function applyNumberFormatting(value, locale, localeOptions, separator, p */ export function calculateExponent(num, e, exponent, isDecimal, precision) { if (e === -1 || isNaN(e)) { - e = isDecimal - ? Math.floor(Math.log(num) / LOG_10_1000) - : Math.floor(Math.log(num) / LOG_2_1024); + if (isDecimal) { + e = Math.floor(Math.log(num) / LOG_10_1000); + } else { + e = Math.floor(Math.log(num) / LOG_2_1024); + } if (e < 0) { e = 0; } @@ -263,8 +293,18 @@ export function calculateExponent(num, e, exponent, isDecimal, precision) { * @returns {Object} Object with rounded value and possibly incremented exponent */ export function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { - const p = e > 0 && round > 0 ? Math.pow(10, round) : 1; - let r = p === 1 ? roundingFunc(val) : roundingFunc(val * p) / p; + let p; + if (e > 0 && round > 0) { + p = Math.pow(10, round); + } else { + p = 1; + } + let r; + if (p === 1) { + r = roundingFunc(val); + } else { + r = roundingFunc(val * p) / p; + } if (r === ceil && e < 8 && autoExponent) { r = 1; @@ -285,7 +325,17 @@ export function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) { */ export function resolveSymbol(actualStandard, bits, e, isDecimal) { const symbolTable = STRINGS.symbol[actualStandard][bits ? BITS : BYTES]; - return isDecimal && e === 1 ? (bits ? SI_KBIT : SI_KBYTE) : symbolTable[e]; + let result; + if (isDecimal && e === 1) { + if (bits) { + result = SI_KBIT; + } else { + result = SI_KBYTE; + } + } else { + result = symbolTable[e]; + } + return result; } /** @@ -332,10 +382,31 @@ export function decorateResult( result[0] = applyNumberFormatting(result[0], locale, localeOptions, separator, pad, round); if (full) { - const unit = bits ? BIT : BYTE; - const val = typeof result[0] === "string" ? parseFloat(result[0]) : result[0]; - result[1] = - fullforms[e] || STRINGS.fullform[actualStandard][e] + unit + (val === 1 ? EMPTY : S); + let unit; + if (bits) { + unit = BIT; + } else { + unit = BYTE; + } + let val; + if (typeof result[0] === "string") { + val = parseFloat(result[0]); + } else { + val = result[0]; + } + // Determine singular/plural suffix + let suffix; + if (val === 1) { + suffix = EMPTY; + } else { + suffix = S; + } + // Determine symbol — custom fullforms are the complete name, defaults get unit+suffix + if (fullforms[e]) { + result[1] = fullforms[e]; + } else { + result[1] = STRINGS.fullform[actualStandard][e] + unit + suffix; + } } } @@ -362,5 +433,11 @@ export function formatOutput(result, e, u, output, spacer) { }; } - return spacer === SPACE ? `${result[0]} ${result[1]}` : result.join(spacer); + let formatted; + if (spacer === SPACE) { + formatted = `${result[0]} ${result[1]}`; + } else { + formatted = result.join(spacer); + } + return formatted; } diff --git a/tests/unit/filesize.test.js b/tests/unit/filesize.test.js index 126bc54..751764b 100644 --- a/tests/unit/filesize.test.js +++ b/tests/unit/filesize.test.js @@ -234,6 +234,14 @@ describe("filesize", () => { it("should handle bits fullform plural", () => { assert.strictEqual(filesize(0.25, { bits: true, fullform: true }), "2 bits"); }); + + it("should handle fullform with precision (string value path)", () => { + assert.strictEqual( + filesize(1058223158, { standard: "iec", precision: 3, fullform: true }), + "0.990 gibibytes", + ); + assert.strictEqual(filesize(1234567890, { precision: 2, fullform: true }), "1.2 gigabytes"); + }); }); describe("Base and exponent options", () => { From d2ef0db556eff1356d5cc001c3bb8436e03715fb Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Sun, 19 Apr 2026 21:02:15 -0400 Subject: [PATCH 11/11] chore: build and update coverage --- coverage.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coverage.txt b/coverage.txt index 3c54cd6..869a960 100644 --- a/coverage.txt +++ b/coverage.txt @@ -5,8 +5,8 @@ ℹ src | | | | ℹ constants.js | 100.00 | 100.00 | 100.00 | ℹ filesize.js | 100.00 | 100.00 | 100.00 | -ℹ helpers.js | 100.00 | 99.00 | 100.00 | +ℹ helpers.js | 100.00 | 100.00 | 100.00 | ℹ -------------------------------------------------------------- -ℹ all files | 100.00 | 99.18 | 100.00 | +ℹ all files | 100.00 | 100.00 | 100.00 | ℹ -------------------------------------------------------------- ℹ end of coverage report