From a7b30fc272a74d1b8d0fe3019d186a74b5c9e03a Mon Sep 17 00:00:00 2001 From: Ferit Date: Fri, 9 Oct 2026 23:12:24 +0300 Subject: [PATCH 1/2] fix: honor locale and separator options for zero values --- dist/filesize.cjs | 20 ++++++++++++++++++++ dist/filesize.js | 20 ++++++++++++++++++++ dist/filesize.min.js | 2 +- dist/filesize.min.js.map | 2 +- dist/filesize.umd.js | 20 ++++++++++++++++++++ dist/filesize.umd.min.js | 2 +- dist/filesize.umd.min.js.map | 2 +- src/filesize.js | 4 ++++ src/helpers.js | 16 ++++++++++++++++ tests/unit/filesize.test.js | 19 +++++++++++++++++++ 10 files changed, 103 insertions(+), 4 deletions(-) diff --git a/dist/filesize.cjs b/dist/filesize.cjs index f5f72f6..87309d2 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -131,6 +131,9 @@ function getBaseConfiguration(standard, base) { * @param {boolean} pad - Whether to pad decimal places * @param {number} round - Number of decimal places for padding * @param {string} [symbol] - Symbol to use (defaults based on bits/standard) + * @param {string|boolean} [locale=""] - Locale setting + * @param {Object} [localeOptions={}] - Locale formatting options + * @param {string} [separator=""] - Custom decimal separator * @returns {string|Array|Object|number} Formatted result */ function handleZeroValue( @@ -145,6 +148,9 @@ function handleZeroValue( pad, round, symbol, + locale = EMPTY, + localeOptions = {}, + separator = EMPTY, ) { let value; if (precision > 0) { @@ -159,6 +165,16 @@ function handleZeroValue( return 0; } + value = applyNumberFormatting( + locale === true || locale.length > 0 ? 0 : value, + locale, + localeOptions, + separator, + pad && precision <= 0, + round, + Math.round, + ); + // Set default symbol if not provided if (!symbol) { symbol = bits @@ -776,6 +792,10 @@ function filesize( spacer, pad, round, + undefined, + locale, + localeOptions, + separator, ); } diff --git a/dist/filesize.js b/dist/filesize.js index 3b42145..6fa4182 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -127,6 +127,9 @@ function getBaseConfiguration(standard, base) { * @param {boolean} pad - Whether to pad decimal places * @param {number} round - Number of decimal places for padding * @param {string} [symbol] - Symbol to use (defaults based on bits/standard) + * @param {string|boolean} [locale=""] - Locale setting + * @param {Object} [localeOptions={}] - Locale formatting options + * @param {string} [separator=""] - Custom decimal separator * @returns {string|Array|Object|number} Formatted result */ function handleZeroValue( @@ -141,6 +144,9 @@ function handleZeroValue( pad, round, symbol, + locale = EMPTY, + localeOptions = {}, + separator = EMPTY, ) { let value; if (precision > 0) { @@ -155,6 +161,16 @@ function handleZeroValue( return 0; } + value = applyNumberFormatting( + locale === true || locale.length > 0 ? 0 : value, + locale, + localeOptions, + separator, + pad && precision <= 0, + round, + Math.round, + ); + // Set default symbol if not provided if (!symbol) { symbol = bits @@ -770,6 +786,10 @@ function filesize( spacer, pad, round, + undefined, + locale, + localeOptions, + separator, ); } diff --git a/dist/filesize.min.js b/dist/filesize.min.js index e714bd7..69bd0d1 100644 --- a/dist/filesize.min.js +++ b/dist/filesize.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.25 */ -const t="Invalid number",e="Invalid precision",i="iec",n="jedec",r="si",o="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],p=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),m=Math.log(1e3),y={[r]:{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,r,o=!0){let a;a=i?p[e]:b[e];let s=t/a;return n&&(s*=8,o&&s>=r&&e<8&&(s/=r,e++)),{result:s,e:e}}function B(r,{bits:b=!1,pad:p=!1,base:B=-1,round:g=2,locale:M="",localeOptions:N={},separator:w="",spacer:x=" ",symbols:S={},standard:v="",output:E=l,fullform:I=!1,fullforms:T=[],exponent:D=-1,roundingMethod:O=c,precision:$=0}={}){let F,G=D,j=[],k=0,J="";const K="bigint"==typeof r;if(F=Number(r),isNaN(F))throw new TypeError(t);if(!isFinite(F))throw new TypeError(t);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}}(v,B),z=!0===I,C=F<0,U=Math[O];if("function"!=typeof U)throw new TypeError("Invalid rounding method");if(C&&(F=-F),0===F)return function(t,e,i,n,r,l,c,b,p,d,m){let y;return y=t>0?(0).toPrecision(t):p&&d>0?(0).toFixed(d):0,c===u?0:(m||(m=i?f.symbol[e].bits[0]:f.symbol[e].bytes[0]),n[m]&&(m=n[m]),r&&(l[0]?m=l[0]:(m=f.fullform[e][0],m+=i?"bit":o)),c===a?[y,m]:c===s?{value:y,symbol:m,exponent:0,unit:m}:y+b+m)}($,Z,b,S,z,T,E,x,p,g);const q=K?C?-BigInt(r):BigInt(r):null;let A=$;if(K){const{e:t,precision:e}=function(t,e,i,n,r){if("string"==typeof e&&(e=Number(e)),-1===e||isNaN(e))if(e=0,n)for(;e<8&&t>=10n**BigInt(3*(e+1));)e++;else for(;e<8&&t>=1024n**BigInt(e+1);)e++;else e=e<0?0:Math.floor(e);return e>8?(r>0&&(r+=8-e),{e:8,precision:r}):{e:e,precision:r}}(q,G,0,P,$);G=t,A=e}else{const{e:t,precision:e}=function(t,e,i,n,r){return"string"==typeof e&&(e=Number(e)),-1===e||isNaN(e)?(e=n?Math.floor(Math.log(t)/m):Math.floor(Math.log(t)/d))<0&&(e=0):e=e<0?0:Math.floor(e),e>8?(r>0&&(r+=8-e),{e:8,precision:r}):{e:e,precision:r}}(F,G,0,P,$);G=t,A=e}const H=-1===D||isNaN(D);let L;L=K?function(t,e,i,n,r,o=!0){const a=i?10n**BigInt(3*e):1024n**BigInt(e),s=10n**16n;let l=Number(t*s/a)/Number(s);return n&&(l*=8,o&&l>=r&&e<8&&(l/=r,e++)),{result:l,e:e}}(q,G,P,b,Y,H):h(F,G,P,b,Y,H),k=L.result,G=L.e;const Q=function(t,e,i,n,r,o){let a,s;return a=i>0&&n>0?Math.pow(10,n):1,s=1===a?r(t):r(t*a)/a,s===e&&i<8&&o&&(s=1,i++),{value:s,e:i}}(k,Y,G,g,U,H);if(j[0]=Q.value,G=Q.e,A>0){const t=function(t,i,n,r,o,a,s,l,u,c){if("string"==typeof t&&(t=parseFloat(t)),"number"!=typeof i||isNaN(i))throw new TypeError(e);if((i=Math.floor(i))<1||i>100)throw new TypeError(e);let f=t.toPrecision(i);const b=-1===c||isNaN(c);if(f.includes("e")&&n<8&&b){n++;const{result:t}=h(r,n,o,a,s);let e,c;e=u>0?Math.pow(10,u):1,c=1===e?l(t):l(t*e)/e,f=c.toPrecision(i)}return{value:f,e:n}}(j[0],A,G,F,P,b,Y,U,g,D);j[0]=t.value,G=t.e}return E===u?G:(J=function(t,e,i,n){const r=f.symbol[t][e?"bits":"bytes"];let o;return o=n&&1===i?e?"kbit":"kB":r[i],o}(Z,b,G,P),j[1]=J,function(t,e,i,n,r,a,s,l,u,c,b,p,d,m){let y;if(e&&("string"==typeof t[0]?t[0]=`-${t[0]}`:0===t[0]?t[0]="-0":t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),y="string"==typeof t[0]?parseFloat(t[0]):t[0],t[0]=function(t,e,i,n,r,o,a){let s=t;const l=r&&o>0?{minimumFractionDigits:o,maximumFractionDigits:o}:void 0;if(!0===e)s=s.toLocaleString(void 0,l);else if(e.length>0)s=s.toLocaleString(e,{...i,...l});else if(n.length>0){if(r&&o>0){const t=Math.pow(10,o);s=a(s*t)/t}s=s.toString().replace(".",n)}if("number"==typeof s&&isFinite(s)&&s.toString().includes("e")&&(s=s.toLocaleString("en-US",{useGrouping:!1})),r&&o>0&&!0!==e&&0===e.length){const t=n||".",e=s.toString().split(t),i=e[1]||"";s=`${e[0]}${t}${i.padEnd(o,"0")}`}return s}(t[0],n,r,a,s,l,m),u){let e,i;e=d?"bit":o,i=1===Math.abs(y)?"":"s",c[p]?t[1]=c[p]:t[1]=f.fullform[b][p]+e+i}}(j,C,S,M,N,w,p,g,z,T,Z,G,b,U),function(t,e,i,n,r){if(n!==a&&n!==s&&n!==l&&n!==u)throw new TypeError(`Invalid output: ${n}`);if(n===a)return t;if(n===s)return{value:t[0],symbol:t[1],exponent:e,unit:i};let o;return o=" "===r?`${t[0]} ${t[1]}`:t.join(r),o}(j,G,J,E,x))}function g({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:r="",separator:o="",spacer:a=" ",standard:s="",output:u=l,fullform:f=!1,exponent:b=-1,roundingMethod:p=c,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){function g(t){try{return"function"==typeof structuredClone?structuredClone(t):JSON.parse(JSON.stringify(t))}catch{return JSON.parse(JSON.stringify(t))}}const M={localeOptions:g(m),symbols:g(y),fullforms:g(h)};return l=>B(l,{bits:t,pad:e,base:i,round:n,locale:r,localeOptions:M.localeOptions,separator:o,spacer:a,symbols:M.symbols,standard:s,output:u,fullform:f,fullforms:M.fullforms,exponent:b,roundingMethod:p,precision:d})}export{B as filesize,g as partial};//# sourceMappingURL=filesize.min.js.map +const t="Invalid number",e="Invalid precision",i="iec",n="jedec",r="si",o="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],p=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),m=Math.log(1e3),y={[r]:{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,r,o=!0){let a;a=i?p[e]:b[e];let s=t/a;return n&&(s*=8,o&&s>=r&&e<8&&(s/=r,e++)),{result:s,e:e}}function B(t,e,i,n,r,o,a){let s=t;const l=r&&o>0?{minimumFractionDigits:o,maximumFractionDigits:o}:void 0;if(!0===e)s=s.toLocaleString(void 0,l);else if(e.length>0)s=s.toLocaleString(e,{...i,...l});else if(n.length>0){if(r&&o>0){const t=Math.pow(10,o);s=a(s*t)/t}s=s.toString().replace(".",n)}if("number"==typeof s&&isFinite(s)&&s.toString().includes("e")&&(s=s.toLocaleString("en-US",{useGrouping:!1})),r&&o>0&&!0!==e&&0===e.length){const t=n||".",e=s.toString().split(t),i=e[1]||"";s=`${e[0]}${t}${i.padEnd(o,"0")}`}return s}function g(r,{bits:b=!1,pad:p=!1,base:g=-1,round:M=2,locale:N="",localeOptions:w={},separator:x="",spacer:v=" ",symbols:S={},standard:E="",output:I=l,fullform:T=!1,fullforms:D=[],exponent:O=-1,roundingMethod:$=c,precision:F=0}={}){let G,j=O,k=[],J=0,K="";const P="bigint"==typeof r;if(G=Number(r),isNaN(G))throw new TypeError(t);if(!isFinite(G))throw new TypeError(t);const{isDecimal:Y,ceil:Z,actualStandard:z}=function(t,e){return y[t]?y[t]:2===e?{isDecimal:!1,ceil:1024,actualStandard:i}:{isDecimal:!0,ceil:1e3,actualStandard:n}}(E,g),C=!0===T,U=G<0,q=Math[$];if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(U&&(G=-G),0===G)return function(t,e,i,n,r,l,c,b,p,d,m,y="",h={},g=""){let M;return M=t>0?(0).toPrecision(t):p&&d>0?(0).toFixed(d):0,c===u?0:(M=B(!0===y||y.length>0?0:M,y,h,g,p&&t<=0,d,Math.round),m||(m=i?f.symbol[e].bits[0]:f.symbol[e].bytes[0]),n[m]&&(m=n[m]),r&&(l[0]?m=l[0]:(m=f.fullform[e][0],m+=i?"bit":o)),c===a?[M,m]:c===s?{value:M,symbol:m,exponent:0,unit:m}:M+b+m)}(F,z,b,S,C,D,I,v,p,M,void 0,N,w,x);const A=P?U?-BigInt(r):BigInt(r):null;let H=F;if(P){const{e:t,precision:e}=function(t,e,i,n,r){if("string"==typeof e&&(e=Number(e)),-1===e||isNaN(e))if(e=0,n)for(;e<8&&t>=10n**BigInt(3*(e+1));)e++;else for(;e<8&&t>=1024n**BigInt(e+1);)e++;else e=e<0?0:Math.floor(e);return e>8?(r>0&&(r+=8-e),{e:8,precision:r}):{e:e,precision:r}}(A,j,0,Y,F);j=t,H=e}else{const{e:t,precision:e}=function(t,e,i,n,r){return"string"==typeof e&&(e=Number(e)),-1===e||isNaN(e)?(e=n?Math.floor(Math.log(t)/m):Math.floor(Math.log(t)/d))<0&&(e=0):e=e<0?0:Math.floor(e),e>8?(r>0&&(r+=8-e),{e:8,precision:r}):{e:e,precision:r}}(G,j,0,Y,F);j=t,H=e}const L=-1===O||isNaN(O);let Q;Q=P?function(t,e,i,n,r,o=!0){const a=i?10n**BigInt(3*e):1024n**BigInt(e),s=10n**16n;let l=Number(t*s/a)/Number(s);return n&&(l*=8,o&&l>=r&&e<8&&(l/=r,e++)),{result:l,e:e}}(A,j,Y,b,Z,L):h(G,j,Y,b,Z,L),J=Q.result,j=Q.e;const R=function(t,e,i,n,r,o){let a,s;return a=i>0&&n>0?Math.pow(10,n):1,s=1===a?r(t):r(t*a)/a,s===e&&i<8&&o&&(s=1,i++),{value:s,e:i}}(J,Z,j,M,q,L);if(k[0]=R.value,j=R.e,H>0){const t=function(t,i,n,r,o,a,s,l,u,c){if("string"==typeof t&&(t=parseFloat(t)),"number"!=typeof i||isNaN(i))throw new TypeError(e);if((i=Math.floor(i))<1||i>100)throw new TypeError(e);let f=t.toPrecision(i);const b=-1===c||isNaN(c);if(f.includes("e")&&n<8&&b){n++;const{result:t}=h(r,n,o,a,s);let e,c;e=u>0?Math.pow(10,u):1,c=1===e?l(t):l(t*e)/e,f=c.toPrecision(i)}return{value:f,e:n}}(k[0],H,j,G,Y,b,Z,q,M,O);k[0]=t.value,j=t.e}return I===u?j:(K=function(t,e,i,n){const r=f.symbol[t][e?"bits":"bytes"];let o;return o=n&&1===i?e?"kbit":"kB":r[i],o}(z,b,j,Y),k[1]=K,function(t,e,i,n,r,a,s,l,u,c,b,p,d,m){let y;if(e&&("string"==typeof t[0]?t[0]=`-${t[0]}`:0===t[0]?t[0]="-0":t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),y="string"==typeof t[0]?parseFloat(t[0]):t[0],t[0]=B(t[0],n,r,a,s,l,m),u){let e,i;e=d?"bit":o,i=1===Math.abs(y)?"":"s",c[p]?t[1]=c[p]:t[1]=f.fullform[b][p]+e+i}}(k,U,S,N,w,x,p,M,C,D,z,j,b,q),function(t,e,i,n,r){if(n!==a&&n!==s&&n!==l&&n!==u)throw new TypeError(`Invalid output: ${n}`);if(n===a)return t;if(n===s)return{value:t[0],symbol:t[1],exponent:e,unit:i};let o;return o=" "===r?`${t[0]} ${t[1]}`:t.join(r),o}(k,j,K,I,v))}function M({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:r="",separator:o="",spacer:a=" ",standard:s="",output:u=l,fullform:f=!1,exponent:b=-1,roundingMethod:p=c,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){function B(t){try{return"function"==typeof structuredClone?structuredClone(t):JSON.parse(JSON.stringify(t))}catch{return JSON.parse(JSON.stringify(t))}}const M={localeOptions:B(m),symbols:B(y),fullforms:B(h)};return l=>g(l,{bits:t,pad:e,base:i,round:n,locale:r,localeOptions:M.localeOptions,separator:o,spacer:a,symbols:M.symbols,standard:s,output:u,fullform:f,fullforms:M.fullforms,exponent:b,roundingMethod:p,precision:d})}export{g as filesize,M as partial};//# sourceMappingURL=filesize.min.js.map diff --git a/dist/filesize.min.js.map b/dist/filesize.min.js.map index 2448cb2..ddb4a8e 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\";\nexport const INVALID_PRECISION = \"Invalid precision\";\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\tINVALID_PRECISION,\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\tSTRING,\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 {boolean} pad - Whether to pad decimal places\n * @param {number} round - Number of decimal places for padding\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\tpad,\n\tround,\n\tsymbol,\n) {\n\tlet value;\n\tif (precision > 0) {\n\t\tvalue = (0).toPrecision(precision);\n\t} else if (pad && round > 0) {\n\t\tvalue = (0).toFixed(round);\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 * Calculates the unit exponent for a bigint input using bigint comparisons\n * @param {bigint} 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 calculateBigIntExponent(num, e, exponent, isDecimal, precision) {\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\n\tif (e === -1 || isNaN(e)) {\n\t\te = 0;\n\t\tif (isDecimal) {\n\t\t\twhile (e < 8 && num >= 10n ** BigInt(3 * (e + 1))) {\n\t\t\t\te++;\n\t\t\t}\n\t\t} else {\n\t\t\twhile (e < 8 && num >= 1024n ** BigInt(e + 1)) {\n\t\t\t\te++;\n\t\t\t}\n\t\t}\n\t} else if (e < 0) {\n\t\te = 0;\n\t} else {\n\t\te = Math.floor(e);\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 * Calculates the value for a bigint input using bigint arithmetic\n * @param {bigint} num - Input file size in bytes\n * @param {number} e - Current exponent\n * @param {boolean} isDecimal - Whether using decimal base\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 calculateBigIntValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst power = isDecimal ? 10n ** BigInt(3 * e) : 1024n ** BigInt(e);\n\t// Scaled division preserves precision above Number.MAX_SAFE_INTEGER.\n\t// Multiply by 10^16 before dividing, then scale back down, so the\n\t// quotient keeps ~16 significant digits instead of collapsing to a float.\n\tconst SHIFT = 10n ** 16n;\n\tlet result = Number((num * SHIFT) / power) / Number(SHIFT);\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\t// Validate precision range. toPrecision() throws a raw RangeError for\n\t// values outside 1-100; normalize to a clean TypeError and floor any\n\t// non-integer value (which toPrecision would otherwise truncate silently).\n\tif (typeof precision !== \"number\" || isNaN(precision)) {\n\t\tthrow new TypeError(INVALID_PRECISION);\n\t}\n\tprecision = Math.floor(precision);\n\tif (precision < 1 || precision > 100) {\n\t\tthrow new TypeError(INVALID_PRECISION);\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(\n\tvalue,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\troundingFunc,\n) {\n\tlet result = value;\n\n\t// When padding alongside a locale, let the locale formatter emit the fixed\n\t// number of fraction digits. The manual string padding below cannot tell a\n\t// locale-inserted grouping separator from the decimal separator, so it\n\t// dropped digits (e.g. \"1,234,500\" became \"1,234\").\n\tconst localePad =\n\t\tpad && round > 0 ? { minimumFractionDigits: round, maximumFractionDigits: round } : undefined;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString(undefined, localePad);\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, { ...localeOptions, ...localePad });\n\t} else if (separator.length > 0) {\n\t\t// Round before separator replacement to ensure excess decimal places\n\t\t// are truncated when pad is also set (fixes padding + separator bug).\n\t\tif (pad && round > 0) {\n\t\t\tconst p = Math.pow(10, round);\n\t\t\tresult = roundingFunc(result * p) / p;\n\t\t}\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Expand scientific notation to full decimal so pathological values like\n\t// Number.MAX_VALUE don't leak \"e+284\" into the output. Only applies when\n\t// the value is a finite number whose string form uses exponent notation.\n\tif (typeof result === \"number\" && isFinite(result) && result.toString().includes(E)) {\n\t\tresult = result.toLocaleString(\"en-US\", { useGrouping: false });\n\t}\n\n\t// Apply padding for the non-locale paths, where the string has a single\n\t// decimal separator and no grouping is inserted.\n\tif (pad && round > 0 && locale !== true && locale.length === 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(round, 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\t// A string exponent (e.g. \"1\") must be coerced to a number before the\n\t// strict `e === 1` checks below; otherwise it indexes the symbol tables\n\t// with a string and misses the SI special case in resolveSymbol.\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\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} else if (e < 0) {\n\t\t// A forced exponent below the auto sentinel (-1) has no meaning and\n\t\t// would otherwise index the power-of-ten/two lookup tables out of\n\t\t// bounds (producing NaN). Clamp to 0, mirroring the e > 8 clamp below.\n\t\te = 0;\n\t} else {\n\t\t// A non-integer positive exponent (e.g. 1.5) would index the\n\t\t// power-of-ten/two lookup tables out of bounds (producing NaN).\n\t\t// Floor it to the nearest valid integer, mirroring the clamps above.\n\t\te = Math.floor(e);\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\troundingFunc,\n) {\n\tif (neg) {\n\t\t// `precision` leaves the value as a string from toPrecision (e.g. \"1.50\").\n\t\t// Negating that arithmetically coerces it back to a number and drops the\n\t\t// trailing zeros the option asked for, so prefix the sign instead.\n\t\tif (typeof result[0] === \"string\") {\n\t\t\tresult[0] = `-${result[0]}`;\n\t\t} else if (result[0] === 0) {\n\t\t\t// A negative value that rounds to zero (e.g. -0.4) becomes -0, which\n\t\t\t// stringifies to \"0\" and drops the sign. Emit the string \"-0\" so the\n\t\t\t// sign is preserved consistently with the precision path.\n\t\t\tresult[0] = \"-0\";\n\t\t} else {\n\t\t\tresult[0] = -result[0];\n\t\t}\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\t// Capture the numeric value before formatting; a comma decimal separator\n\t// (via separator or a locale such as de-DE) would otherwise make parseFloat\n\t// read \"1,5\" as 1 and select the singular unit name.\n\tlet numericValue;\n\tif (typeof result[0] === \"string\") {\n\t\tnumericValue = parseFloat(result[0]);\n\t} else {\n\t\tnumericValue = result[0];\n\t}\n\n\tresult[0] = applyNumberFormatting(\n\t\tresult[0],\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\troundingFunc,\n\t);\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\t// Determine singular/plural suffix. Use Math.abs so a negative value\n\t\t// of exactly 1 (e.g. -1) selects the singular unit name.\n\t\tlet suffix;\n\t\tif (Math.abs(numericValue) === 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\t// Validate the output option. Any value other than the supported set\n\t// (array, object, string, exponent) would silently fall through to the\n\t// string branch below and produce misleading output.\n\tif (output !== ARRAY && output !== OBJECT && output !== STRING && output !== EXPONENT) {\n\t\tthrow new TypeError(`Invalid output: ${output}`);\n\t}\n\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\tcalculateBigIntExponent,\n\tcalculateBigIntValue,\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, roundingMethod is invalid,\n * precision is out of range (1-100), or output is not a supported format\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 *\n * @remarks\n * **Input coercion:** `arg` is coerced via `Number()`. Numeric strings, hex\n * (`\"0x1F\"`), binary (`\"0b101\"`), and octal (`\"0o17\"`) literals are parsed;\n * `null`, `\"\"`, `\" \"`, `true`, `false`, and single-element arrays coerce to\n * their numeric value. `undefined`, `\"1_000\"`, and `\"1000n\"` throw `TypeError`.\n * A `bigint` that overflows `Number.MAX_SAFE_INTEGER` throws `TypeError`.\n *\n * **Option precedence:** When multiple options conflict, `standard` wins over\n * `base`; `fullform` wins over `symbols`; `locale` wins over `separator`;\n * and a missing `fullforms[e]` falls back to the default unit name.\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\tconst isBigInt = typeof arg === \"bigint\";\n\n\tnum = Number(arg);\n\n\tif (isNaN(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (!isFinite(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\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\tpad,\n\t\t\tround,\n\t\t);\n\t}\n\n\t// BigInt inputs use bigint arithmetic to preserve precision above\n\t// Number.MAX_SAFE_INTEGER and detect unit boundaries accurately.\n\tconst bigNum = isBigInt ? (neg ? -BigInt(arg) : BigInt(arg)) : null;\n\n\t// Exponent calculation + clamp + precision adjustment\n\tlet precisionAdjusted = precision;\n\tif (isBigInt) {\n\t\tconst { e: calculatedE, precision: pa } = calculateBigIntExponent(\n\t\t\tbigNum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t} else {\n\t\tconst { e: calculatedE, precision: pa } = calculateExponent(\n\t\t\tnum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t}\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tlet valueResult;\n\tif (isBigInt) {\n\t\tvalueResult = calculateBigIntValue(bigNum, e, isDecimal, bits, ceil, autoExponent);\n\t} else {\n\t\tvalueResult = calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent);\n\t}\n\tval = valueResult.result;\n\te = valueResult.e;\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\t// Return the exponent only after every adjustment that other output\n\t// modes apply (bits auto-increment, rounding overflow, precision), so\n\t// it always matches the exponent reported by object output.\n\tif (output === EXPONENT) {\n\t\treturn 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\troundingFunc,\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\t/**\n\t * Safely clone an object using structuredClone with JSON fallback.\n\t * structuredClone can throw for functions, circular refs, etc.\n\t */\n\tfunction safeClone(value) {\n\t\ttry {\n\t\t\treturn typeof structuredClone === \"function\"\n\t\t\t\t? structuredClone(value)\n\t\t\t\t: JSON.parse(JSON.stringify(value));\n\t\t} catch {\n\t\t\treturn JSON.parse(JSON.stringify(value));\n\t\t}\n\t}\n\n\tconst cloned = {\n\t\tlocaleOptions: safeClone(localeOptions),\n\t\tsymbols: safeClone(symbols),\n\t\tfullforms: safeClone(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","INVALID_PRECISION","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","isBigInt","Number","isNaN","TypeError","isFinite","getBaseConfiguration","full","neg","roundingFunc","value","toPrecision","toFixed","unit","handleZeroValue","bigNum","BigInt","precisionAdjusted","calculatedE","pa","floor","calculateBigIntExponent","calculateExponent","valueResult","power","SHIFT","calculateBigIntValue","rounded","p","r","pow","applyRounding","precisionResult","parseFloat","includes","computed","applyPrecisionHandling","symbolTable","resolveSymbol","numericValue","localePad","minimumFractionDigits","maximumFractionDigits","undefined","toLocaleString","length","toString","replace","useGrouping","x","tmp","split","s","padEnd","applyNumberFormatting","suffix","abs","decorateResult","formatted","join","formatOutput","partial","safeClone","structuredClone","JSON","parse","stringify","cloned"],"mappings":";;;;AACO,MAAM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GAAO,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKE,UACdA,EAAYF,GAAKG,OACjBA,EF9NoB,IE8NNE,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,IAKH,SAASmE,EAAUpD,GAClB,IACC,MAAkC,mBAApBqD,gBACXA,gBAAgBrD,GAChBsD,KAAKC,MAAMD,KAAKE,UAAUxD,GAC9B,CAAE,MACD,OAAOsD,KAAKC,MAAMD,KAAKE,UAAUxD,GAClC,CACD,CAEA,MAAMyD,EAAS,CACd9E,cAAeyE,EAAUzE,GACzBG,QAASsE,EAAUtE,GACnBG,UAAWmE,EAAUnE,IAGtB,OAAQZ,GACPD,EAASC,EAAK,CACbrB,OACAsB,MACAC,OACAC,QACAC,SACAE,cAAe8E,EAAO9E,cACtBC,YACAC,SACAC,QAAS2E,EAAO3E,QAChBC,WACAC,SACA7B,WACA8B,UAAWwE,EAAOxE,UAClBC,WACAC,iBACAC,aAEH,QAAAhB,cAAA+E"} +{"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\";\nexport const INVALID_PRECISION = \"Invalid precision\";\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\tINVALID_PRECISION,\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\tSTRING,\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 {boolean} pad - Whether to pad decimal places\n * @param {number} round - Number of decimal places for padding\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @param {string|boolean} [locale=\"\"] - Locale setting\n * @param {Object} [localeOptions={}] - Locale formatting options\n * @param {string} [separator=\"\"] - Custom decimal separator\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\tpad,\n\tround,\n\tsymbol,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n) {\n\tlet value;\n\tif (precision > 0) {\n\t\tvalue = (0).toPrecision(precision);\n\t} else if (pad && round > 0) {\n\t\tvalue = (0).toFixed(round);\n\t} else {\n\t\tvalue = 0;\n\t}\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\tvalue = applyNumberFormatting(\n\t\tlocale === true || locale.length > 0 ? 0 : value,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad && precision <= 0,\n\t\tround,\n\t\tMath.round,\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 * Calculates the unit exponent for a bigint input using bigint comparisons\n * @param {bigint} 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 calculateBigIntExponent(num, e, exponent, isDecimal, precision) {\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\n\tif (e === -1 || isNaN(e)) {\n\t\te = 0;\n\t\tif (isDecimal) {\n\t\t\twhile (e < 8 && num >= 10n ** BigInt(3 * (e + 1))) {\n\t\t\t\te++;\n\t\t\t}\n\t\t} else {\n\t\t\twhile (e < 8 && num >= 1024n ** BigInt(e + 1)) {\n\t\t\t\te++;\n\t\t\t}\n\t\t}\n\t} else if (e < 0) {\n\t\te = 0;\n\t} else {\n\t\te = Math.floor(e);\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 * Calculates the value for a bigint input using bigint arithmetic\n * @param {bigint} num - Input file size in bytes\n * @param {number} e - Current exponent\n * @param {boolean} isDecimal - Whether using decimal base\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 calculateBigIntValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst power = isDecimal ? 10n ** BigInt(3 * e) : 1024n ** BigInt(e);\n\t// Scaled division preserves precision above Number.MAX_SAFE_INTEGER.\n\t// Multiply by 10^16 before dividing, then scale back down, so the\n\t// quotient keeps ~16 significant digits instead of collapsing to a float.\n\tconst SHIFT = 10n ** 16n;\n\tlet result = Number((num * SHIFT) / power) / Number(SHIFT);\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\t// Validate precision range. toPrecision() throws a raw RangeError for\n\t// values outside 1-100; normalize to a clean TypeError and floor any\n\t// non-integer value (which toPrecision would otherwise truncate silently).\n\tif (typeof precision !== \"number\" || isNaN(precision)) {\n\t\tthrow new TypeError(INVALID_PRECISION);\n\t}\n\tprecision = Math.floor(precision);\n\tif (precision < 1 || precision > 100) {\n\t\tthrow new TypeError(INVALID_PRECISION);\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(\n\tvalue,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\troundingFunc,\n) {\n\tlet result = value;\n\n\t// When padding alongside a locale, let the locale formatter emit the fixed\n\t// number of fraction digits. The manual string padding below cannot tell a\n\t// locale-inserted grouping separator from the decimal separator, so it\n\t// dropped digits (e.g. \"1,234,500\" became \"1,234\").\n\tconst localePad =\n\t\tpad && round > 0 ? { minimumFractionDigits: round, maximumFractionDigits: round } : undefined;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString(undefined, localePad);\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, { ...localeOptions, ...localePad });\n\t} else if (separator.length > 0) {\n\t\t// Round before separator replacement to ensure excess decimal places\n\t\t// are truncated when pad is also set (fixes padding + separator bug).\n\t\tif (pad && round > 0) {\n\t\t\tconst p = Math.pow(10, round);\n\t\t\tresult = roundingFunc(result * p) / p;\n\t\t}\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Expand scientific notation to full decimal so pathological values like\n\t// Number.MAX_VALUE don't leak \"e+284\" into the output. Only applies when\n\t// the value is a finite number whose string form uses exponent notation.\n\tif (typeof result === \"number\" && isFinite(result) && result.toString().includes(E)) {\n\t\tresult = result.toLocaleString(\"en-US\", { useGrouping: false });\n\t}\n\n\t// Apply padding for the non-locale paths, where the string has a single\n\t// decimal separator and no grouping is inserted.\n\tif (pad && round > 0 && locale !== true && locale.length === 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(round, 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\t// A string exponent (e.g. \"1\") must be coerced to a number before the\n\t// strict `e === 1` checks below; otherwise it indexes the symbol tables\n\t// with a string and misses the SI special case in resolveSymbol.\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\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} else if (e < 0) {\n\t\t// A forced exponent below the auto sentinel (-1) has no meaning and\n\t\t// would otherwise index the power-of-ten/two lookup tables out of\n\t\t// bounds (producing NaN). Clamp to 0, mirroring the e > 8 clamp below.\n\t\te = 0;\n\t} else {\n\t\t// A non-integer positive exponent (e.g. 1.5) would index the\n\t\t// power-of-ten/two lookup tables out of bounds (producing NaN).\n\t\t// Floor it to the nearest valid integer, mirroring the clamps above.\n\t\te = Math.floor(e);\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\troundingFunc,\n) {\n\tif (neg) {\n\t\t// `precision` leaves the value as a string from toPrecision (e.g. \"1.50\").\n\t\t// Negating that arithmetically coerces it back to a number and drops the\n\t\t// trailing zeros the option asked for, so prefix the sign instead.\n\t\tif (typeof result[0] === \"string\") {\n\t\t\tresult[0] = `-${result[0]}`;\n\t\t} else if (result[0] === 0) {\n\t\t\t// A negative value that rounds to zero (e.g. -0.4) becomes -0, which\n\t\t\t// stringifies to \"0\" and drops the sign. Emit the string \"-0\" so the\n\t\t\t// sign is preserved consistently with the precision path.\n\t\t\tresult[0] = \"-0\";\n\t\t} else {\n\t\t\tresult[0] = -result[0];\n\t\t}\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\t// Capture the numeric value before formatting; a comma decimal separator\n\t// (via separator or a locale such as de-DE) would otherwise make parseFloat\n\t// read \"1,5\" as 1 and select the singular unit name.\n\tlet numericValue;\n\tif (typeof result[0] === \"string\") {\n\t\tnumericValue = parseFloat(result[0]);\n\t} else {\n\t\tnumericValue = result[0];\n\t}\n\n\tresult[0] = applyNumberFormatting(\n\t\tresult[0],\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\troundingFunc,\n\t);\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\t// Determine singular/plural suffix. Use Math.abs so a negative value\n\t\t// of exactly 1 (e.g. -1) selects the singular unit name.\n\t\tlet suffix;\n\t\tif (Math.abs(numericValue) === 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\t// Validate the output option. Any value other than the supported set\n\t// (array, object, string, exponent) would silently fall through to the\n\t// string branch below and produce misleading output.\n\tif (output !== ARRAY && output !== OBJECT && output !== STRING && output !== EXPONENT) {\n\t\tthrow new TypeError(`Invalid output: ${output}`);\n\t}\n\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\tcalculateBigIntExponent,\n\tcalculateBigIntValue,\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, roundingMethod is invalid,\n * precision is out of range (1-100), or output is not a supported format\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 *\n * @remarks\n * **Input coercion:** `arg` is coerced via `Number()`. Numeric strings, hex\n * (`\"0x1F\"`), binary (`\"0b101\"`), and octal (`\"0o17\"`) literals are parsed;\n * `null`, `\"\"`, `\" \"`, `true`, `false`, and single-element arrays coerce to\n * their numeric value. `undefined`, `\"1_000\"`, and `\"1000n\"` throw `TypeError`.\n * A `bigint` that overflows `Number.MAX_SAFE_INTEGER` throws `TypeError`.\n *\n * **Option precedence:** When multiple options conflict, `standard` wins over\n * `base`; `fullform` wins over `symbols`; `locale` wins over `separator`;\n * and a missing `fullforms[e]` falls back to the default unit name.\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\tconst isBigInt = typeof arg === \"bigint\";\n\n\tnum = Number(arg);\n\n\tif (isNaN(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (!isFinite(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\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\tpad,\n\t\t\tround,\n\t\t\tundefined,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t);\n\t}\n\n\t// BigInt inputs use bigint arithmetic to preserve precision above\n\t// Number.MAX_SAFE_INTEGER and detect unit boundaries accurately.\n\tconst bigNum = isBigInt ? (neg ? -BigInt(arg) : BigInt(arg)) : null;\n\n\t// Exponent calculation + clamp + precision adjustment\n\tlet precisionAdjusted = precision;\n\tif (isBigInt) {\n\t\tconst { e: calculatedE, precision: pa } = calculateBigIntExponent(\n\t\t\tbigNum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t} else {\n\t\tconst { e: calculatedE, precision: pa } = calculateExponent(\n\t\t\tnum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t}\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tlet valueResult;\n\tif (isBigInt) {\n\t\tvalueResult = calculateBigIntValue(bigNum, e, isDecimal, bits, ceil, autoExponent);\n\t} else {\n\t\tvalueResult = calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent);\n\t}\n\tval = valueResult.result;\n\te = valueResult.e;\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\t// Return the exponent only after every adjustment that other output\n\t// modes apply (bits auto-increment, rounding overflow, precision), so\n\t// it always matches the exponent reported by object output.\n\tif (output === EXPONENT) {\n\t\treturn 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\troundingFunc,\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\t/**\n\t * Safely clone an object using structuredClone with JSON fallback.\n\t * structuredClone can throw for functions, circular refs, etc.\n\t */\n\tfunction safeClone(value) {\n\t\ttry {\n\t\t\treturn typeof structuredClone === \"function\"\n\t\t\t\t? structuredClone(value)\n\t\t\t\t: JSON.parse(JSON.stringify(value));\n\t\t} catch {\n\t\t\treturn JSON.parse(JSON.stringify(value));\n\t\t}\n\t}\n\n\tconst cloned = {\n\t\tlocaleOptions: safeClone(localeOptions),\n\t\tsymbols: safeClone(symbols),\n\t\tfullforms: safeClone(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","INVALID_PRECISION","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","applyNumberFormatting","value","locale","localeOptions","separator","pad","round","roundingFunc","localePad","minimumFractionDigits","maximumFractionDigits","undefined","toLocaleString","length","p","pow","toString","replace","isFinite","includes","useGrouping","x","tmp","split","s","padEnd","filesize","arg","base","EMPTY","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","isBigInt","Number","isNaN","TypeError","getBaseConfiguration","full","neg","toPrecision","toFixed","unit","handleZeroValue","bigNum","BigInt","precisionAdjusted","calculatedE","pa","floor","calculateBigIntExponent","calculateExponent","valueResult","power","SHIFT","calculateBigIntValue","rounded","r","applyRounding","precisionResult","parseFloat","computed","applyPrecisionHandling","symbolTable","resolveSymbol","numericValue","suffix","abs","decorateResult","formatted","join","formatOutput","partial","safeClone","structuredClone","JSON","parse","stringify","cloned"],"mappings":";;;;AACO,MAAMA,EAAiB,iBAEjBC,EAAoB,oBAGpBC,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,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AS8C,EAAU/E,GAClB,IACC,MAAkC,mBAApBgF,gBACXA,gBAAgBhF,GAChBiF,KAAKC,MAAMD,KAAKE,UAAUnF,GAC9B,CAAE,MACD,OAAOiF,KAAKC,MAAMD,KAAKE,UAAUnF,GAClC,CACD,CAEA,MAAMoF,EAAS,CACdlF,cAAe6E,EAAU7E,GACzB4B,QAASiD,EAAUjD,GACnBG,UAAW8C,EAAU9C,IAGtB,OAAQP,GACPD,EAASC,EAAK,CACb/C,OACAyB,MACAuB,OACAtB,QACAJ,SACAC,cAAekF,EAAOlF,cACtBC,YACA0B,SACAC,QAASsD,EAAOtD,QAChBC,WACAC,SACAlD,WACAmD,UAAWmD,EAAOnD,UAClBC,WACAC,iBACAC,aAEH,QAAAX,cAAAqD"} diff --git a/dist/filesize.umd.js b/dist/filesize.umd.js index 1e8d257..41609dd 100644 --- a/dist/filesize.umd.js +++ b/dist/filesize.umd.js @@ -127,6 +127,9 @@ function getBaseConfiguration(standard, base) { * @param {boolean} pad - Whether to pad decimal places * @param {number} round - Number of decimal places for padding * @param {string} [symbol] - Symbol to use (defaults based on bits/standard) + * @param {string|boolean} [locale=""] - Locale setting + * @param {Object} [localeOptions={}] - Locale formatting options + * @param {string} [separator=""] - Custom decimal separator * @returns {string|Array|Object|number} Formatted result */ function handleZeroValue( @@ -141,6 +144,9 @@ function handleZeroValue( pad, round, symbol, + locale = EMPTY, + localeOptions = {}, + separator = EMPTY, ) { let value; if (precision > 0) { @@ -155,6 +161,16 @@ function handleZeroValue( return 0; } + value = applyNumberFormatting( + locale === true || locale.length > 0 ? 0 : value, + locale, + localeOptions, + separator, + pad && precision <= 0, + round, + Math.round, + ); + // Set default symbol if not provided if (!symbol) { symbol = bits @@ -770,6 +786,10 @@ function filesize( spacer, pad, round, + undefined, + locale, + localeOptions, + separator, ); } diff --git a/dist/filesize.umd.min.js b/dist/filesize.umd.min.js index 01df871..7a150c2 100644 --- a/dist/filesize.umd.min.js +++ b/dist/filesize.umd.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.25 */ -!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="Invalid precision",n="iec",o="jedec",r="si",s="byte",a="array",l="object",u="string",c="exponent",f="round",p={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],m=Math.log(1024),y=Math.log(1e3),h={[r]:{isDecimal:!0,ceil:1e3,actualStandard:o},[n]:{isDecimal:!1,ceil:1024,actualStandard:n},[o]:{isDecimal:!1,ceil:1024,actualStandard:o}};function g(t,e,i,n,o,r=!0){let s;s=i?d[e]:b[e];let a=t/s;return n&&(a*=8,r&&a>=o&&e<8&&(a/=o,e++)),{result:a,e:e}}function B(t,{bits:r=!1,pad:b=!1,base:d=-1,round:B=2,locale:M="",localeOptions:N={},separator:x="",spacer:w=" ",symbols:T={},standard:S="",output:v=u,fullform:E=!1,fullforms:I=[],exponent:D=-1,roundingMethod:O=f,precision:$=0}={}){let F,j=D,G=[],k=0,J="";const K="bigint"==typeof t;if(F=Number(t),isNaN(F))throw new TypeError(e);if(!isFinite(F))throw new TypeError(e);const{isDecimal:P,ceil:Y,actualStandard:Z}=function(t,e){return h[t]?h[t]:2===e?{isDecimal:!1,ceil:1024,actualStandard:n}:{isDecimal:!0,ceil:1e3,actualStandard:o}}(S,d),z=!0===E,C=F<0,U=Math[O];if("function"!=typeof U)throw new TypeError("Invalid rounding method");if(C&&(F=-F),0===F)return function(t,e,i,n,o,r,u,f,b,d,m){let y;return y=t>0?(0).toPrecision(t):b&&d>0?(0).toFixed(d):0,u===c?0:(m||(m=i?p.symbol[e].bits[0]:p.symbol[e].bytes[0]),n[m]&&(m=n[m]),o&&(r[0]?m=r[0]:(m=p.fullform[e][0],m+=i?"bit":s)),u===a?[y,m]:u===l?{value:y,symbol:m,exponent:0,unit:m}:y+f+m)}($,Z,r,T,z,I,v,w,b,B);const q=K?C?-BigInt(t):BigInt(t):null;let A=$;if(K){const{e:t,precision:e}=function(t,e,i,n,o){if("string"==typeof e&&(e=Number(e)),-1===e||isNaN(e))if(e=0,n)for(;e<8&&t>=10n**BigInt(3*(e+1));)e++;else for(;e<8&&t>=1024n**BigInt(e+1);)e++;else e=e<0?0:Math.floor(e);return e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(q,j,0,P,$);j=t,A=e}else{const{e:t,precision:e}=function(t,e,i,n,o){return"string"==typeof e&&(e=Number(e)),-1===e||isNaN(e)?(e=n?Math.floor(Math.log(t)/y):Math.floor(Math.log(t)/m))<0&&(e=0):e=e<0?0:Math.floor(e),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(F,j,0,P,$);j=t,A=e}const H=-1===D||isNaN(D);let L;L=K?function(t,e,i,n,o,r=!0){const s=i?10n**BigInt(3*e):1024n**BigInt(e),a=10n**16n;let l=Number(t*a/s)/Number(a);return n&&(l*=8,r&&l>=o&&e<8&&(l/=o,e++)),{result:l,e:e}}(q,j,P,r,Y,H):g(F,j,P,r,Y,H),k=L.result,j=L.e;const Q=function(t,e,i,n,o,r){let s,a;return s=i>0&&n>0?Math.pow(10,n):1,a=1===s?o(t):o(t*s)/s,a===e&&i<8&&r&&(a=1,i++),{value:a,e:i}}(k,Y,j,B,U,H);if(G[0]=Q.value,j=Q.e,A>0){const t=function(t,e,n,o,r,s,a,l,u,c){if("string"==typeof t&&(t=parseFloat(t)),"number"!=typeof e||isNaN(e))throw new TypeError(i);if((e=Math.floor(e))<1||e>100)throw new TypeError(i);let f=t.toPrecision(e);const p=-1===c||isNaN(c);if(f.includes("e")&&n<8&&p){n++;const{result:t}=g(o,n,r,s,a);let i,c;i=u>0?Math.pow(10,u):1,c=1===i?l(t):l(t*i)/i,f=c.toPrecision(e)}return{value:f,e:n}}(G[0],A,j,F,P,r,Y,U,B,D);G[0]=t.value,j=t.e}return v===c?j:(J=function(t,e,i,n){const o=p.symbol[t][e?"bits":"bytes"];let r;return r=n&&1===i?e?"kbit":"kB":o[i],r}(Z,r,j,P),G[1]=J,function(t,e,i,n,o,r,a,l,u,c,f,b,d,m){let y;if(e&&("string"==typeof t[0]?t[0]=`-${t[0]}`:0===t[0]?t[0]="-0":t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),y="string"==typeof t[0]?parseFloat(t[0]):t[0],t[0]=function(t,e,i,n,o,r,s){let a=t;const l=o&&r>0?{minimumFractionDigits:r,maximumFractionDigits:r}:void 0;if(!0===e)a=a.toLocaleString(void 0,l);else if(e.length>0)a=a.toLocaleString(e,{...i,...l});else if(n.length>0){if(o&&r>0){const t=Math.pow(10,r);a=s(a*t)/t}a=a.toString().replace(".",n)}if("number"==typeof a&&isFinite(a)&&a.toString().includes("e")&&(a=a.toLocaleString("en-US",{useGrouping:!1})),o&&r>0&&!0!==e&&0===e.length){const t=n||".",e=a.toString().split(t),i=e[1]||"";a=`${e[0]}${t}${i.padEnd(r,"0")}`}return a}(t[0],n,o,r,a,l,m),u){let e,i;e=d?"bit":s,i=1===Math.abs(y)?"":"s",c[b]?t[1]=c[b]:t[1]=p.fullform[f][b]+e+i}}(G,C,T,M,N,x,b,B,z,I,Z,j,r,U),function(t,e,i,n,o){if(n!==a&&n!==l&&n!==u&&n!==c)throw new TypeError(`Invalid output: ${n}`);if(n===a)return t;if(n===l)return{value:t[0],symbol:t[1],exponent:e,unit:i};let r;return r=" "===o?`${t[0]} ${t[1]}`:t.join(o),r}(G,j,J,v,w))}t.filesize=B,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",separator:r="",spacer:s=" ",standard:a="",output:l=u,fullform:c=!1,exponent:p=-1,roundingMethod:b=f,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){function g(t){try{return"function"==typeof structuredClone?structuredClone(t):JSON.parse(JSON.stringify(t))}catch{return JSON.parse(JSON.stringify(t))}}const M={localeOptions:g(m),symbols:g(y),fullforms:g(h)};return u=>B(u,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:M.localeOptions,separator:r,spacer:s,symbols:M.symbols,standard:a,output:l,fullform:c,fullforms:M.fullforms,exponent:p,roundingMethod:b,precision:d})}});//# 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="Invalid precision",n="iec",o="jedec",r="si",s="byte",a="array",l="object",u="string",c="exponent",f="round",p={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],m=Math.log(1024),y=Math.log(1e3),h={[r]:{isDecimal:!0,ceil:1e3,actualStandard:o},[n]:{isDecimal:!1,ceil:1024,actualStandard:n},[o]:{isDecimal:!1,ceil:1024,actualStandard:o}};function g(t,e,i,n,o,r=!0){let s;s=i?d[e]:b[e];let a=t/s;return n&&(a*=8,r&&a>=o&&e<8&&(a/=o,e++)),{result:a,e:e}}function B(t,e,i,n,o,r,s){let a=t;const l=o&&r>0?{minimumFractionDigits:r,maximumFractionDigits:r}:void 0;if(!0===e)a=a.toLocaleString(void 0,l);else if(e.length>0)a=a.toLocaleString(e,{...i,...l});else if(n.length>0){if(o&&r>0){const t=Math.pow(10,r);a=s(a*t)/t}a=a.toString().replace(".",n)}if("number"==typeof a&&isFinite(a)&&a.toString().includes("e")&&(a=a.toLocaleString("en-US",{useGrouping:!1})),o&&r>0&&!0!==e&&0===e.length){const t=n||".",e=a.toString().split(t),i=e[1]||"";a=`${e[0]}${t}${i.padEnd(r,"0")}`}return a}function M(t,{bits:r=!1,pad:b=!1,base:d=-1,round:M=2,locale:N="",localeOptions:x={},separator:w="",spacer:T=" ",symbols:v={},standard:S="",output:E=u,fullform:I=!1,fullforms:D=[],exponent:O=-1,roundingMethod:$=f,precision:F=0}={}){let j,G=O,k=[],J=0,K="";const P="bigint"==typeof t;if(j=Number(t),isNaN(j))throw new TypeError(e);if(!isFinite(j))throw new TypeError(e);const{isDecimal:Y,ceil:Z,actualStandard:z}=function(t,e){return h[t]?h[t]:2===e?{isDecimal:!1,ceil:1024,actualStandard:n}:{isDecimal:!0,ceil:1e3,actualStandard:o}}(S,d),C=!0===I,U=j<0,q=Math[$];if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(U&&(j=-j),0===j)return function(t,e,i,n,o,r,u,f,b,d,m,y="",h={},g=""){let M;return M=t>0?(0).toPrecision(t):b&&d>0?(0).toFixed(d):0,u===c?0:(M=B(!0===y||y.length>0?0:M,y,h,g,b&&t<=0,d,Math.round),m||(m=i?p.symbol[e].bits[0]:p.symbol[e].bytes[0]),n[m]&&(m=n[m]),o&&(r[0]?m=r[0]:(m=p.fullform[e][0],m+=i?"bit":s)),u===a?[M,m]:u===l?{value:M,symbol:m,exponent:0,unit:m}:M+f+m)}(F,z,r,v,C,D,E,T,b,M,void 0,N,x,w);const A=P?U?-BigInt(t):BigInt(t):null;let H=F;if(P){const{e:t,precision:e}=function(t,e,i,n,o){if("string"==typeof e&&(e=Number(e)),-1===e||isNaN(e))if(e=0,n)for(;e<8&&t>=10n**BigInt(3*(e+1));)e++;else for(;e<8&&t>=1024n**BigInt(e+1);)e++;else e=e<0?0:Math.floor(e);return e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(A,G,0,Y,F);G=t,H=e}else{const{e:t,precision:e}=function(t,e,i,n,o){return"string"==typeof e&&(e=Number(e)),-1===e||isNaN(e)?(e=n?Math.floor(Math.log(t)/y):Math.floor(Math.log(t)/m))<0&&(e=0):e=e<0?0:Math.floor(e),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(j,G,0,Y,F);G=t,H=e}const L=-1===O||isNaN(O);let Q;Q=P?function(t,e,i,n,o,r=!0){const s=i?10n**BigInt(3*e):1024n**BigInt(e),a=10n**16n;let l=Number(t*a/s)/Number(a);return n&&(l*=8,r&&l>=o&&e<8&&(l/=o,e++)),{result:l,e:e}}(A,G,Y,r,Z,L):g(j,G,Y,r,Z,L),J=Q.result,G=Q.e;const R=function(t,e,i,n,o,r){let s,a;return s=i>0&&n>0?Math.pow(10,n):1,a=1===s?o(t):o(t*s)/s,a===e&&i<8&&r&&(a=1,i++),{value:a,e:i}}(J,Z,G,M,q,L);if(k[0]=R.value,G=R.e,H>0){const t=function(t,e,n,o,r,s,a,l,u,c){if("string"==typeof t&&(t=parseFloat(t)),"number"!=typeof e||isNaN(e))throw new TypeError(i);if((e=Math.floor(e))<1||e>100)throw new TypeError(i);let f=t.toPrecision(e);const p=-1===c||isNaN(c);if(f.includes("e")&&n<8&&p){n++;const{result:t}=g(o,n,r,s,a);let i,c;i=u>0?Math.pow(10,u):1,c=1===i?l(t):l(t*i)/i,f=c.toPrecision(e)}return{value:f,e:n}}(k[0],H,G,j,Y,r,Z,q,M,O);k[0]=t.value,G=t.e}return E===c?G:(K=function(t,e,i,n){const o=p.symbol[t][e?"bits":"bytes"];let r;return r=n&&1===i?e?"kbit":"kB":o[i],r}(z,r,G,Y),k[1]=K,function(t,e,i,n,o,r,a,l,u,c,f,b,d,m){let y;if(e&&("string"==typeof t[0]?t[0]=`-${t[0]}`:0===t[0]?t[0]="-0":t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),y="string"==typeof t[0]?parseFloat(t[0]):t[0],t[0]=B(t[0],n,o,r,a,l,m),u){let e,i;e=d?"bit":s,i=1===Math.abs(y)?"":"s",c[b]?t[1]=c[b]:t[1]=p.fullform[f][b]+e+i}}(k,U,v,N,x,w,b,M,C,D,z,G,r,q),function(t,e,i,n,o){if(n!==a&&n!==l&&n!==u&&n!==c)throw new TypeError(`Invalid output: ${n}`);if(n===a)return t;if(n===l)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,G,K,E,T))}t.filesize=M,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",separator:r="",spacer:s=" ",standard:a="",output:l=u,fullform:c=!1,exponent:p=-1,roundingMethod:b=f,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){function g(t){try{return"function"==typeof structuredClone?structuredClone(t):JSON.parse(JSON.stringify(t))}catch{return JSON.parse(JSON.stringify(t))}}const B={localeOptions:g(m),symbols:g(y),fullforms:g(h)};return u=>M(u,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:B.localeOptions,separator:r,spacer:s,symbols:B.symbols,standard:a,output:l,fullform:c,fullforms:B.fullforms,exponent:p,roundingMethod:b,precision:d})}});//# sourceMappingURL=filesize.umd.min.js.map diff --git a/dist/filesize.umd.min.js.map b/dist/filesize.umd.min.js.map index a2ef8f0..89c6ee8 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\";\nexport const INVALID_PRECISION = \"Invalid precision\";\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\tINVALID_PRECISION,\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\tSTRING,\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 {boolean} pad - Whether to pad decimal places\n * @param {number} round - Number of decimal places for padding\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\tpad,\n\tround,\n\tsymbol,\n) {\n\tlet value;\n\tif (precision > 0) {\n\t\tvalue = (0).toPrecision(precision);\n\t} else if (pad && round > 0) {\n\t\tvalue = (0).toFixed(round);\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 * Calculates the unit exponent for a bigint input using bigint comparisons\n * @param {bigint} 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 calculateBigIntExponent(num, e, exponent, isDecimal, precision) {\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\n\tif (e === -1 || isNaN(e)) {\n\t\te = 0;\n\t\tif (isDecimal) {\n\t\t\twhile (e < 8 && num >= 10n ** BigInt(3 * (e + 1))) {\n\t\t\t\te++;\n\t\t\t}\n\t\t} else {\n\t\t\twhile (e < 8 && num >= 1024n ** BigInt(e + 1)) {\n\t\t\t\te++;\n\t\t\t}\n\t\t}\n\t} else if (e < 0) {\n\t\te = 0;\n\t} else {\n\t\te = Math.floor(e);\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 * Calculates the value for a bigint input using bigint arithmetic\n * @param {bigint} num - Input file size in bytes\n * @param {number} e - Current exponent\n * @param {boolean} isDecimal - Whether using decimal base\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 calculateBigIntValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst power = isDecimal ? 10n ** BigInt(3 * e) : 1024n ** BigInt(e);\n\t// Scaled division preserves precision above Number.MAX_SAFE_INTEGER.\n\t// Multiply by 10^16 before dividing, then scale back down, so the\n\t// quotient keeps ~16 significant digits instead of collapsing to a float.\n\tconst SHIFT = 10n ** 16n;\n\tlet result = Number((num * SHIFT) / power) / Number(SHIFT);\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\t// Validate precision range. toPrecision() throws a raw RangeError for\n\t// values outside 1-100; normalize to a clean TypeError and floor any\n\t// non-integer value (which toPrecision would otherwise truncate silently).\n\tif (typeof precision !== \"number\" || isNaN(precision)) {\n\t\tthrow new TypeError(INVALID_PRECISION);\n\t}\n\tprecision = Math.floor(precision);\n\tif (precision < 1 || precision > 100) {\n\t\tthrow new TypeError(INVALID_PRECISION);\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(\n\tvalue,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\troundingFunc,\n) {\n\tlet result = value;\n\n\t// When padding alongside a locale, let the locale formatter emit the fixed\n\t// number of fraction digits. The manual string padding below cannot tell a\n\t// locale-inserted grouping separator from the decimal separator, so it\n\t// dropped digits (e.g. \"1,234,500\" became \"1,234\").\n\tconst localePad =\n\t\tpad && round > 0 ? { minimumFractionDigits: round, maximumFractionDigits: round } : undefined;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString(undefined, localePad);\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, { ...localeOptions, ...localePad });\n\t} else if (separator.length > 0) {\n\t\t// Round before separator replacement to ensure excess decimal places\n\t\t// are truncated when pad is also set (fixes padding + separator bug).\n\t\tif (pad && round > 0) {\n\t\t\tconst p = Math.pow(10, round);\n\t\t\tresult = roundingFunc(result * p) / p;\n\t\t}\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Expand scientific notation to full decimal so pathological values like\n\t// Number.MAX_VALUE don't leak \"e+284\" into the output. Only applies when\n\t// the value is a finite number whose string form uses exponent notation.\n\tif (typeof result === \"number\" && isFinite(result) && result.toString().includes(E)) {\n\t\tresult = result.toLocaleString(\"en-US\", { useGrouping: false });\n\t}\n\n\t// Apply padding for the non-locale paths, where the string has a single\n\t// decimal separator and no grouping is inserted.\n\tif (pad && round > 0 && locale !== true && locale.length === 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(round, 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\t// A string exponent (e.g. \"1\") must be coerced to a number before the\n\t// strict `e === 1` checks below; otherwise it indexes the symbol tables\n\t// with a string and misses the SI special case in resolveSymbol.\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\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} else if (e < 0) {\n\t\t// A forced exponent below the auto sentinel (-1) has no meaning and\n\t\t// would otherwise index the power-of-ten/two lookup tables out of\n\t\t// bounds (producing NaN). Clamp to 0, mirroring the e > 8 clamp below.\n\t\te = 0;\n\t} else {\n\t\t// A non-integer positive exponent (e.g. 1.5) would index the\n\t\t// power-of-ten/two lookup tables out of bounds (producing NaN).\n\t\t// Floor it to the nearest valid integer, mirroring the clamps above.\n\t\te = Math.floor(e);\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\troundingFunc,\n) {\n\tif (neg) {\n\t\t// `precision` leaves the value as a string from toPrecision (e.g. \"1.50\").\n\t\t// Negating that arithmetically coerces it back to a number and drops the\n\t\t// trailing zeros the option asked for, so prefix the sign instead.\n\t\tif (typeof result[0] === \"string\") {\n\t\t\tresult[0] = `-${result[0]}`;\n\t\t} else if (result[0] === 0) {\n\t\t\t// A negative value that rounds to zero (e.g. -0.4) becomes -0, which\n\t\t\t// stringifies to \"0\" and drops the sign. Emit the string \"-0\" so the\n\t\t\t// sign is preserved consistently with the precision path.\n\t\t\tresult[0] = \"-0\";\n\t\t} else {\n\t\t\tresult[0] = -result[0];\n\t\t}\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\t// Capture the numeric value before formatting; a comma decimal separator\n\t// (via separator or a locale such as de-DE) would otherwise make parseFloat\n\t// read \"1,5\" as 1 and select the singular unit name.\n\tlet numericValue;\n\tif (typeof result[0] === \"string\") {\n\t\tnumericValue = parseFloat(result[0]);\n\t} else {\n\t\tnumericValue = result[0];\n\t}\n\n\tresult[0] = applyNumberFormatting(\n\t\tresult[0],\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\troundingFunc,\n\t);\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\t// Determine singular/plural suffix. Use Math.abs so a negative value\n\t\t// of exactly 1 (e.g. -1) selects the singular unit name.\n\t\tlet suffix;\n\t\tif (Math.abs(numericValue) === 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\t// Validate the output option. Any value other than the supported set\n\t// (array, object, string, exponent) would silently fall through to the\n\t// string branch below and produce misleading output.\n\tif (output !== ARRAY && output !== OBJECT && output !== STRING && output !== EXPONENT) {\n\t\tthrow new TypeError(`Invalid output: ${output}`);\n\t}\n\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\tcalculateBigIntExponent,\n\tcalculateBigIntValue,\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, roundingMethod is invalid,\n * precision is out of range (1-100), or output is not a supported format\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 *\n * @remarks\n * **Input coercion:** `arg` is coerced via `Number()`. Numeric strings, hex\n * (`\"0x1F\"`), binary (`\"0b101\"`), and octal (`\"0o17\"`) literals are parsed;\n * `null`, `\"\"`, `\" \"`, `true`, `false`, and single-element arrays coerce to\n * their numeric value. `undefined`, `\"1_000\"`, and `\"1000n\"` throw `TypeError`.\n * A `bigint` that overflows `Number.MAX_SAFE_INTEGER` throws `TypeError`.\n *\n * **Option precedence:** When multiple options conflict, `standard` wins over\n * `base`; `fullform` wins over `symbols`; `locale` wins over `separator`;\n * and a missing `fullforms[e]` falls back to the default unit name.\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\tconst isBigInt = typeof arg === \"bigint\";\n\n\tnum = Number(arg);\n\n\tif (isNaN(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (!isFinite(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\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\tpad,\n\t\t\tround,\n\t\t);\n\t}\n\n\t// BigInt inputs use bigint arithmetic to preserve precision above\n\t// Number.MAX_SAFE_INTEGER and detect unit boundaries accurately.\n\tconst bigNum = isBigInt ? (neg ? -BigInt(arg) : BigInt(arg)) : null;\n\n\t// Exponent calculation + clamp + precision adjustment\n\tlet precisionAdjusted = precision;\n\tif (isBigInt) {\n\t\tconst { e: calculatedE, precision: pa } = calculateBigIntExponent(\n\t\t\tbigNum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t} else {\n\t\tconst { e: calculatedE, precision: pa } = calculateExponent(\n\t\t\tnum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t}\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tlet valueResult;\n\tif (isBigInt) {\n\t\tvalueResult = calculateBigIntValue(bigNum, e, isDecimal, bits, ceil, autoExponent);\n\t} else {\n\t\tvalueResult = calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent);\n\t}\n\tval = valueResult.result;\n\te = valueResult.e;\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\t// Return the exponent only after every adjustment that other output\n\t// modes apply (bits auto-increment, rounding overflow, precision), so\n\t// it always matches the exponent reported by object output.\n\tif (output === EXPONENT) {\n\t\treturn 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\troundingFunc,\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\t/**\n\t * Safely clone an object using structuredClone with JSON fallback.\n\t * structuredClone can throw for functions, circular refs, etc.\n\t */\n\tfunction safeClone(value) {\n\t\ttry {\n\t\t\treturn typeof structuredClone === \"function\"\n\t\t\t\t? structuredClone(value)\n\t\t\t\t: JSON.parse(JSON.stringify(value));\n\t\t} catch {\n\t\t\treturn JSON.parse(JSON.stringify(value));\n\t\t}\n\t}\n\n\tconst cloned = {\n\t\tlocaleOptions: safeClone(localeOptions),\n\t\tsymbols: safeClone(symbols),\n\t\tfullforms: safeClone(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","INVALID_PRECISION","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","isBigInt","Number","isNaN","TypeError","isFinite","getBaseConfiguration","full","neg","roundingFunc","value","toPrecision","toFixed","unit","handleZeroValue","bigNum","BigInt","precisionAdjusted","calculatedE","pa","floor","calculateBigIntExponent","calculateExponent","valueResult","power","SHIFT","calculateBigIntValue","rounded","p","r","pow","applyRounding","precisionResult","parseFloat","includes","computed","applyPrecisionHandling","symbolTable","resolveSymbol","numericValue","localePad","minimumFractionDigits","maximumFractionDigits","undefined","toLocaleString","length","toString","replace","useGrouping","x","tmp","split","s","padEnd","applyNumberFormatting","suffix","abs","decorateResult","formatted","join","formatOutput","partial","safeClone","structuredClone","JSON","parse","stringify","cloned"],"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,iBAEjBC,EAAoB,oBAGpBC,EAA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,EAAEC,MACTA,EAAQ,EAACC,OACTA,EAASC,GAAKE,UACdA,EAAYF,GAAKG,OACjBA,EF9NoB,IE8NNE,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,IAKH,SAASmE,EAAUpD,GAClB,IACC,MAAkC,mBAApBqD,gBACXA,gBAAgBrD,GAChBsD,KAAKC,MAAMD,KAAKE,UAAUxD,GAC9B,CAAE,MACD,OAAOsD,KAAKC,MAAMD,KAAKE,UAAUxD,GAClC,CACD,CAEA,MAAMyD,EAAS,CACd9E,cAAeyE,EAAUzE,GACzBG,QAASsE,EAAUtE,GACnBG,UAAWmE,EAAUnE,IAGtB,OAAQZ,GACPpC,EAASoC,EAAK,CACbpB,OACAqB,MACAC,OACAC,QACAC,SACAE,cAAe8E,EAAO9E,cACtBC,YACAC,SACAC,QAAS2E,EAAO3E,QAChBC,WACAC,SACA5B,WACA6B,UAAWwE,EAAOxE,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\";\nexport const INVALID_PRECISION = \"Invalid precision\";\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\tINVALID_PRECISION,\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\tSTRING,\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 {boolean} pad - Whether to pad decimal places\n * @param {number} round - Number of decimal places for padding\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @param {string|boolean} [locale=\"\"] - Locale setting\n * @param {Object} [localeOptions={}] - Locale formatting options\n * @param {string} [separator=\"\"] - Custom decimal separator\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\tpad,\n\tround,\n\tsymbol,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n) {\n\tlet value;\n\tif (precision > 0) {\n\t\tvalue = (0).toPrecision(precision);\n\t} else if (pad && round > 0) {\n\t\tvalue = (0).toFixed(round);\n\t} else {\n\t\tvalue = 0;\n\t}\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\tvalue = applyNumberFormatting(\n\t\tlocale === true || locale.length > 0 ? 0 : value,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad && precision <= 0,\n\t\tround,\n\t\tMath.round,\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 * Calculates the unit exponent for a bigint input using bigint comparisons\n * @param {bigint} 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 calculateBigIntExponent(num, e, exponent, isDecimal, precision) {\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\n\tif (e === -1 || isNaN(e)) {\n\t\te = 0;\n\t\tif (isDecimal) {\n\t\t\twhile (e < 8 && num >= 10n ** BigInt(3 * (e + 1))) {\n\t\t\t\te++;\n\t\t\t}\n\t\t} else {\n\t\t\twhile (e < 8 && num >= 1024n ** BigInt(e + 1)) {\n\t\t\t\te++;\n\t\t\t}\n\t\t}\n\t} else if (e < 0) {\n\t\te = 0;\n\t} else {\n\t\te = Math.floor(e);\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 * Calculates the value for a bigint input using bigint arithmetic\n * @param {bigint} num - Input file size in bytes\n * @param {number} e - Current exponent\n * @param {boolean} isDecimal - Whether using decimal base\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 calculateBigIntValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst power = isDecimal ? 10n ** BigInt(3 * e) : 1024n ** BigInt(e);\n\t// Scaled division preserves precision above Number.MAX_SAFE_INTEGER.\n\t// Multiply by 10^16 before dividing, then scale back down, so the\n\t// quotient keeps ~16 significant digits instead of collapsing to a float.\n\tconst SHIFT = 10n ** 16n;\n\tlet result = Number((num * SHIFT) / power) / Number(SHIFT);\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\t// Validate precision range. toPrecision() throws a raw RangeError for\n\t// values outside 1-100; normalize to a clean TypeError and floor any\n\t// non-integer value (which toPrecision would otherwise truncate silently).\n\tif (typeof precision !== \"number\" || isNaN(precision)) {\n\t\tthrow new TypeError(INVALID_PRECISION);\n\t}\n\tprecision = Math.floor(precision);\n\tif (precision < 1 || precision > 100) {\n\t\tthrow new TypeError(INVALID_PRECISION);\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(\n\tvalue,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\troundingFunc,\n) {\n\tlet result = value;\n\n\t// When padding alongside a locale, let the locale formatter emit the fixed\n\t// number of fraction digits. The manual string padding below cannot tell a\n\t// locale-inserted grouping separator from the decimal separator, so it\n\t// dropped digits (e.g. \"1,234,500\" became \"1,234\").\n\tconst localePad =\n\t\tpad && round > 0 ? { minimumFractionDigits: round, maximumFractionDigits: round } : undefined;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString(undefined, localePad);\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, { ...localeOptions, ...localePad });\n\t} else if (separator.length > 0) {\n\t\t// Round before separator replacement to ensure excess decimal places\n\t\t// are truncated when pad is also set (fixes padding + separator bug).\n\t\tif (pad && round > 0) {\n\t\t\tconst p = Math.pow(10, round);\n\t\t\tresult = roundingFunc(result * p) / p;\n\t\t}\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Expand scientific notation to full decimal so pathological values like\n\t// Number.MAX_VALUE don't leak \"e+284\" into the output. Only applies when\n\t// the value is a finite number whose string form uses exponent notation.\n\tif (typeof result === \"number\" && isFinite(result) && result.toString().includes(E)) {\n\t\tresult = result.toLocaleString(\"en-US\", { useGrouping: false });\n\t}\n\n\t// Apply padding for the non-locale paths, where the string has a single\n\t// decimal separator and no grouping is inserted.\n\tif (pad && round > 0 && locale !== true && locale.length === 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(round, 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\t// A string exponent (e.g. \"1\") must be coerced to a number before the\n\t// strict `e === 1` checks below; otherwise it indexes the symbol tables\n\t// with a string and misses the SI special case in resolveSymbol.\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\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} else if (e < 0) {\n\t\t// A forced exponent below the auto sentinel (-1) has no meaning and\n\t\t// would otherwise index the power-of-ten/two lookup tables out of\n\t\t// bounds (producing NaN). Clamp to 0, mirroring the e > 8 clamp below.\n\t\te = 0;\n\t} else {\n\t\t// A non-integer positive exponent (e.g. 1.5) would index the\n\t\t// power-of-ten/two lookup tables out of bounds (producing NaN).\n\t\t// Floor it to the nearest valid integer, mirroring the clamps above.\n\t\te = Math.floor(e);\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\troundingFunc,\n) {\n\tif (neg) {\n\t\t// `precision` leaves the value as a string from toPrecision (e.g. \"1.50\").\n\t\t// Negating that arithmetically coerces it back to a number and drops the\n\t\t// trailing zeros the option asked for, so prefix the sign instead.\n\t\tif (typeof result[0] === \"string\") {\n\t\t\tresult[0] = `-${result[0]}`;\n\t\t} else if (result[0] === 0) {\n\t\t\t// A negative value that rounds to zero (e.g. -0.4) becomes -0, which\n\t\t\t// stringifies to \"0\" and drops the sign. Emit the string \"-0\" so the\n\t\t\t// sign is preserved consistently with the precision path.\n\t\t\tresult[0] = \"-0\";\n\t\t} else {\n\t\t\tresult[0] = -result[0];\n\t\t}\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\t// Capture the numeric value before formatting; a comma decimal separator\n\t// (via separator or a locale such as de-DE) would otherwise make parseFloat\n\t// read \"1,5\" as 1 and select the singular unit name.\n\tlet numericValue;\n\tif (typeof result[0] === \"string\") {\n\t\tnumericValue = parseFloat(result[0]);\n\t} else {\n\t\tnumericValue = result[0];\n\t}\n\n\tresult[0] = applyNumberFormatting(\n\t\tresult[0],\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\troundingFunc,\n\t);\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\t// Determine singular/plural suffix. Use Math.abs so a negative value\n\t\t// of exactly 1 (e.g. -1) selects the singular unit name.\n\t\tlet suffix;\n\t\tif (Math.abs(numericValue) === 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\t// Validate the output option. Any value other than the supported set\n\t// (array, object, string, exponent) would silently fall through to the\n\t// string branch below and produce misleading output.\n\tif (output !== ARRAY && output !== OBJECT && output !== STRING && output !== EXPONENT) {\n\t\tthrow new TypeError(`Invalid output: ${output}`);\n\t}\n\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\tcalculateBigIntExponent,\n\tcalculateBigIntValue,\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, roundingMethod is invalid,\n * precision is out of range (1-100), or output is not a supported format\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 *\n * @remarks\n * **Input coercion:** `arg` is coerced via `Number()`. Numeric strings, hex\n * (`\"0x1F\"`), binary (`\"0b101\"`), and octal (`\"0o17\"`) literals are parsed;\n * `null`, `\"\"`, `\" \"`, `true`, `false`, and single-element arrays coerce to\n * their numeric value. `undefined`, `\"1_000\"`, and `\"1000n\"` throw `TypeError`.\n * A `bigint` that overflows `Number.MAX_SAFE_INTEGER` throws `TypeError`.\n *\n * **Option precedence:** When multiple options conflict, `standard` wins over\n * `base`; `fullform` wins over `symbols`; `locale` wins over `separator`;\n * and a missing `fullforms[e]` falls back to the default unit name.\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\tconst isBigInt = typeof arg === \"bigint\";\n\n\tnum = Number(arg);\n\n\tif (isNaN(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (!isFinite(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\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\tpad,\n\t\t\tround,\n\t\t\tundefined,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t);\n\t}\n\n\t// BigInt inputs use bigint arithmetic to preserve precision above\n\t// Number.MAX_SAFE_INTEGER and detect unit boundaries accurately.\n\tconst bigNum = isBigInt ? (neg ? -BigInt(arg) : BigInt(arg)) : null;\n\n\t// Exponent calculation + clamp + precision adjustment\n\tlet precisionAdjusted = precision;\n\tif (isBigInt) {\n\t\tconst { e: calculatedE, precision: pa } = calculateBigIntExponent(\n\t\t\tbigNum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t} else {\n\t\tconst { e: calculatedE, precision: pa } = calculateExponent(\n\t\t\tnum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t}\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tlet valueResult;\n\tif (isBigInt) {\n\t\tvalueResult = calculateBigIntValue(bigNum, e, isDecimal, bits, ceil, autoExponent);\n\t} else {\n\t\tvalueResult = calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent);\n\t}\n\tval = valueResult.result;\n\te = valueResult.e;\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\t// Return the exponent only after every adjustment that other output\n\t// modes apply (bits auto-increment, rounding overflow, precision), so\n\t// it always matches the exponent reported by object output.\n\tif (output === EXPONENT) {\n\t\treturn 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\troundingFunc,\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\t/**\n\t * Safely clone an object using structuredClone with JSON fallback.\n\t * structuredClone can throw for functions, circular refs, etc.\n\t */\n\tfunction safeClone(value) {\n\t\ttry {\n\t\t\treturn typeof structuredClone === \"function\"\n\t\t\t\t? structuredClone(value)\n\t\t\t\t: JSON.parse(JSON.stringify(value));\n\t\t} catch {\n\t\t\treturn JSON.parse(JSON.stringify(value));\n\t\t}\n\t}\n\n\tconst cloned = {\n\t\tlocaleOptions: safeClone(localeOptions),\n\t\tsymbols: safeClone(symbols),\n\t\tfullforms: safeClone(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","INVALID_PRECISION","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","applyNumberFormatting","value","locale","localeOptions","separator","pad","round","roundingFunc","localePad","minimumFractionDigits","maximumFractionDigits","undefined","toLocaleString","length","p","pow","toString","replace","isFinite","includes","useGrouping","x","tmp","split","s","padEnd","arg","base","EMPTY","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","isBigInt","Number","isNaN","TypeError","getBaseConfiguration","full","neg","toPrecision","toFixed","unit","handleZeroValue","bigNum","BigInt","precisionAdjusted","calculatedE","pa","floor","calculateBigIntExponent","calculateExponent","valueResult","power","SHIFT","calculateBigIntValue","rounded","r","applyRounding","precisionResult","parseFloat","computed","applyPrecisionHandling","symbolTable","resolveSymbol","numericValue","suffix","abs","decorateResult","formatted","join","formatOutput","partial","safeClone","structuredClone","JSON","parse","stringify","cloned"],"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,iBAEjBC,EAAoB,oBAGpBC,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,CAA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TA,EAAS0B,GAAKxB,UACdA,EAAYwB,GAAKC,OACjBA,EFlOoB,IEkONE,SACdA,EAAWH,GAAKI,OAChBA,EAAS1D,EAAMS,SACfA,GAAW,EAAKmD,SAChBA,GAAW,EAAEC,eACbA,EAAiB3D,EAAK4D,UACtBA,EAAY,EAACjC,cACbA,EAAgB,CAAA,EAAE2B,QAClBA,EAAU,CAAA,EAAEG,UACZA,EAAY,IACT,IAKH,SAAS8C,EAAU9E,GAClB,IACC,MAAkC,mBAApB+E,gBACXA,gBAAgB/E,GAChBgF,KAAKC,MAAMD,KAAKE,UAAUlF,GAC9B,CAAE,MACD,OAAOgF,KAAKC,MAAMD,KAAKE,UAAUlF,GAClC,CACD,CAEA,MAAMmF,EAAS,CACdjF,cAAe4E,EAAU5E,GACzB2B,QAASiD,EAAUjD,GACnBG,UAAW8C,EAAU9C,IAGtB,OAAQP,GACP9D,EAAS8D,EAAK,CACb9C,OACAyB,MACAsB,OACArB,QACAJ,SACAC,cAAeiF,EAAOjF,cACtBC,YACAyB,SACAC,QAASsD,EAAOtD,QAChBC,WACAC,SACAjD,WACAkD,UAAWmD,EAAOnD,UAClBC,WACAC,iBACAC,aAEH,CAAA"} diff --git a/src/filesize.js b/src/filesize.js index 85e105c..094ca71 100644 --- a/src/filesize.js +++ b/src/filesize.js @@ -126,6 +126,10 @@ export function filesize( spacer, pad, round, + undefined, + locale, + localeOptions, + separator, ); } diff --git a/src/helpers.js b/src/helpers.js index f5ab8b2..00fbba3 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -67,6 +67,9 @@ export function getBaseConfiguration(standard, base) { * @param {boolean} pad - Whether to pad decimal places * @param {number} round - Number of decimal places for padding * @param {string} [symbol] - Symbol to use (defaults based on bits/standard) + * @param {string|boolean} [locale=""] - Locale setting + * @param {Object} [localeOptions={}] - Locale formatting options + * @param {string} [separator=""] - Custom decimal separator * @returns {string|Array|Object|number} Formatted result */ export function handleZeroValue( @@ -81,6 +84,9 @@ export function handleZeroValue( pad, round, symbol, + locale = EMPTY, + localeOptions = {}, + separator = EMPTY, ) { let value; if (precision > 0) { @@ -95,6 +101,16 @@ export function handleZeroValue( return 0; } + value = applyNumberFormatting( + locale === true || locale.length > 0 ? 0 : value, + locale, + localeOptions, + separator, + pad && precision <= 0, + round, + Math.round, + ); + // Set default symbol if not provided if (!symbol) { symbol = bits diff --git a/tests/unit/filesize.test.js b/tests/unit/filesize.test.js index 6a274a1..0a97e9e 100644 --- a/tests/unit/filesize.test.js +++ b/tests/unit/filesize.test.js @@ -19,6 +19,25 @@ describe("filesize", () => { assert.strictEqual(filesize(0), "0 B"); }); + it("should format zero using locale and separator options", () => { + assert.strictEqual(filesize(0, { locale: "de-DE", pad: true }), "0,00 B"); + assert.strictEqual(filesize(0n, { separator: ",", pad: true }), "0,00 B"); + assert.strictEqual(filesize(0, { separator: ",", precision: 3 }), "0,00 B"); + assert.deepStrictEqual( + filesize(0, { + locale: "en-US", + localeOptions: { minimumFractionDigits: 3 }, + output: "array", + }), + ["0.000", "B"], + ); + assert.strictEqual( + filesize(0, { locale: true, pad: true, output: "object" }).value, + (0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 }), + ); + assert.strictEqual(filesize(0, { locale: "de-DE", output: "exponent" }), 0); + }); + it("should handle small numbers", () => { assert.strictEqual(filesize(1), "1 B"); assert.strictEqual(filesize(512), "512 B"); From c22c6b8ae0d62d78c3b6521b10de2d93172befb1 Mon Sep 17 00:00:00 2001 From: Ferit Date: Fri, 9 Oct 2026 23:15:18 +0300 Subject: [PATCH 2/2] fix: preserve explicit precision with zero locales --- dist/filesize.cjs | 2 +- dist/filesize.js | 2 +- dist/filesize.min.js | 2 +- dist/filesize.min.js.map | 2 +- dist/filesize.umd.js | 2 +- dist/filesize.umd.min.js | 2 +- dist/filesize.umd.min.js.map | 2 +- src/helpers.js | 2 +- tests/unit/filesize.test.js | 7 +++++++ 9 files changed, 15 insertions(+), 8 deletions(-) diff --git a/dist/filesize.cjs b/dist/filesize.cjs index 87309d2..407640f 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -166,7 +166,7 @@ function handleZeroValue( } value = applyNumberFormatting( - locale === true || locale.length > 0 ? 0 : value, + precision <= 0 && (locale === true || locale.length > 0) ? 0 : value, locale, localeOptions, separator, diff --git a/dist/filesize.js b/dist/filesize.js index 6fa4182..0b270ad 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -162,7 +162,7 @@ function handleZeroValue( } value = applyNumberFormatting( - locale === true || locale.length > 0 ? 0 : value, + precision <= 0 && (locale === true || locale.length > 0) ? 0 : value, locale, localeOptions, separator, diff --git a/dist/filesize.min.js b/dist/filesize.min.js index 69bd0d1..79a191f 100644 --- a/dist/filesize.min.js +++ b/dist/filesize.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.25 */ -const t="Invalid number",e="Invalid precision",i="iec",n="jedec",r="si",o="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],p=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),m=Math.log(1e3),y={[r]:{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,r,o=!0){let a;a=i?p[e]:b[e];let s=t/a;return n&&(s*=8,o&&s>=r&&e<8&&(s/=r,e++)),{result:s,e:e}}function B(t,e,i,n,r,o,a){let s=t;const l=r&&o>0?{minimumFractionDigits:o,maximumFractionDigits:o}:void 0;if(!0===e)s=s.toLocaleString(void 0,l);else if(e.length>0)s=s.toLocaleString(e,{...i,...l});else if(n.length>0){if(r&&o>0){const t=Math.pow(10,o);s=a(s*t)/t}s=s.toString().replace(".",n)}if("number"==typeof s&&isFinite(s)&&s.toString().includes("e")&&(s=s.toLocaleString("en-US",{useGrouping:!1})),r&&o>0&&!0!==e&&0===e.length){const t=n||".",e=s.toString().split(t),i=e[1]||"";s=`${e[0]}${t}${i.padEnd(o,"0")}`}return s}function g(r,{bits:b=!1,pad:p=!1,base:g=-1,round:M=2,locale:N="",localeOptions:w={},separator:x="",spacer:v=" ",symbols:S={},standard:E="",output:I=l,fullform:T=!1,fullforms:D=[],exponent:O=-1,roundingMethod:$=c,precision:F=0}={}){let G,j=O,k=[],J=0,K="";const P="bigint"==typeof r;if(G=Number(r),isNaN(G))throw new TypeError(t);if(!isFinite(G))throw new TypeError(t);const{isDecimal:Y,ceil:Z,actualStandard:z}=function(t,e){return y[t]?y[t]:2===e?{isDecimal:!1,ceil:1024,actualStandard:i}:{isDecimal:!0,ceil:1e3,actualStandard:n}}(E,g),C=!0===T,U=G<0,q=Math[$];if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(U&&(G=-G),0===G)return function(t,e,i,n,r,l,c,b,p,d,m,y="",h={},g=""){let M;return M=t>0?(0).toPrecision(t):p&&d>0?(0).toFixed(d):0,c===u?0:(M=B(!0===y||y.length>0?0:M,y,h,g,p&&t<=0,d,Math.round),m||(m=i?f.symbol[e].bits[0]:f.symbol[e].bytes[0]),n[m]&&(m=n[m]),r&&(l[0]?m=l[0]:(m=f.fullform[e][0],m+=i?"bit":o)),c===a?[M,m]:c===s?{value:M,symbol:m,exponent:0,unit:m}:M+b+m)}(F,z,b,S,C,D,I,v,p,M,void 0,N,w,x);const A=P?U?-BigInt(r):BigInt(r):null;let H=F;if(P){const{e:t,precision:e}=function(t,e,i,n,r){if("string"==typeof e&&(e=Number(e)),-1===e||isNaN(e))if(e=0,n)for(;e<8&&t>=10n**BigInt(3*(e+1));)e++;else for(;e<8&&t>=1024n**BigInt(e+1);)e++;else e=e<0?0:Math.floor(e);return e>8?(r>0&&(r+=8-e),{e:8,precision:r}):{e:e,precision:r}}(A,j,0,Y,F);j=t,H=e}else{const{e:t,precision:e}=function(t,e,i,n,r){return"string"==typeof e&&(e=Number(e)),-1===e||isNaN(e)?(e=n?Math.floor(Math.log(t)/m):Math.floor(Math.log(t)/d))<0&&(e=0):e=e<0?0:Math.floor(e),e>8?(r>0&&(r+=8-e),{e:8,precision:r}):{e:e,precision:r}}(G,j,0,Y,F);j=t,H=e}const L=-1===O||isNaN(O);let Q;Q=P?function(t,e,i,n,r,o=!0){const a=i?10n**BigInt(3*e):1024n**BigInt(e),s=10n**16n;let l=Number(t*s/a)/Number(s);return n&&(l*=8,o&&l>=r&&e<8&&(l/=r,e++)),{result:l,e:e}}(A,j,Y,b,Z,L):h(G,j,Y,b,Z,L),J=Q.result,j=Q.e;const R=function(t,e,i,n,r,o){let a,s;return a=i>0&&n>0?Math.pow(10,n):1,s=1===a?r(t):r(t*a)/a,s===e&&i<8&&o&&(s=1,i++),{value:s,e:i}}(J,Z,j,M,q,L);if(k[0]=R.value,j=R.e,H>0){const t=function(t,i,n,r,o,a,s,l,u,c){if("string"==typeof t&&(t=parseFloat(t)),"number"!=typeof i||isNaN(i))throw new TypeError(e);if((i=Math.floor(i))<1||i>100)throw new TypeError(e);let f=t.toPrecision(i);const b=-1===c||isNaN(c);if(f.includes("e")&&n<8&&b){n++;const{result:t}=h(r,n,o,a,s);let e,c;e=u>0?Math.pow(10,u):1,c=1===e?l(t):l(t*e)/e,f=c.toPrecision(i)}return{value:f,e:n}}(k[0],H,j,G,Y,b,Z,q,M,O);k[0]=t.value,j=t.e}return I===u?j:(K=function(t,e,i,n){const r=f.symbol[t][e?"bits":"bytes"];let o;return o=n&&1===i?e?"kbit":"kB":r[i],o}(z,b,j,Y),k[1]=K,function(t,e,i,n,r,a,s,l,u,c,b,p,d,m){let y;if(e&&("string"==typeof t[0]?t[0]=`-${t[0]}`:0===t[0]?t[0]="-0":t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),y="string"==typeof t[0]?parseFloat(t[0]):t[0],t[0]=B(t[0],n,r,a,s,l,m),u){let e,i;e=d?"bit":o,i=1===Math.abs(y)?"":"s",c[p]?t[1]=c[p]:t[1]=f.fullform[b][p]+e+i}}(k,U,S,N,w,x,p,M,C,D,z,j,b,q),function(t,e,i,n,r){if(n!==a&&n!==s&&n!==l&&n!==u)throw new TypeError(`Invalid output: ${n}`);if(n===a)return t;if(n===s)return{value:t[0],symbol:t[1],exponent:e,unit:i};let o;return o=" "===r?`${t[0]} ${t[1]}`:t.join(r),o}(k,j,K,I,v))}function M({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:r="",separator:o="",spacer:a=" ",standard:s="",output:u=l,fullform:f=!1,exponent:b=-1,roundingMethod:p=c,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){function B(t){try{return"function"==typeof structuredClone?structuredClone(t):JSON.parse(JSON.stringify(t))}catch{return JSON.parse(JSON.stringify(t))}}const M={localeOptions:B(m),symbols:B(y),fullforms:B(h)};return l=>g(l,{bits:t,pad:e,base:i,round:n,locale:r,localeOptions:M.localeOptions,separator:o,spacer:a,symbols:M.symbols,standard:s,output:u,fullform:f,fullforms:M.fullforms,exponent:b,roundingMethod:p,precision:d})}export{g as filesize,M as partial};//# sourceMappingURL=filesize.min.js.map +const t="Invalid number",e="Invalid precision",i="iec",n="jedec",r="si",o="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],p=[1,1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24],d=Math.log(1024),m=Math.log(1e3),y={[r]:{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,r,o=!0){let a;a=i?p[e]:b[e];let s=t/a;return n&&(s*=8,o&&s>=r&&e<8&&(s/=r,e++)),{result:s,e:e}}function B(t,e,i,n,r,o,a){let s=t;const l=r&&o>0?{minimumFractionDigits:o,maximumFractionDigits:o}:void 0;if(!0===e)s=s.toLocaleString(void 0,l);else if(e.length>0)s=s.toLocaleString(e,{...i,...l});else if(n.length>0){if(r&&o>0){const t=Math.pow(10,o);s=a(s*t)/t}s=s.toString().replace(".",n)}if("number"==typeof s&&isFinite(s)&&s.toString().includes("e")&&(s=s.toLocaleString("en-US",{useGrouping:!1})),r&&o>0&&!0!==e&&0===e.length){const t=n||".",e=s.toString().split(t),i=e[1]||"";s=`${e[0]}${t}${i.padEnd(o,"0")}`}return s}function g(r,{bits:b=!1,pad:p=!1,base:g=-1,round:M=2,locale:N="",localeOptions:w={},separator:x="",spacer:v=" ",symbols:S={},standard:E="",output:I=l,fullform:T=!1,fullforms:D=[],exponent:O=-1,roundingMethod:$=c,precision:F=0}={}){let G,j=O,k=[],J=0,K="";const P="bigint"==typeof r;if(G=Number(r),isNaN(G))throw new TypeError(t);if(!isFinite(G))throw new TypeError(t);const{isDecimal:Y,ceil:Z,actualStandard:z}=function(t,e){return y[t]?y[t]:2===e?{isDecimal:!1,ceil:1024,actualStandard:i}:{isDecimal:!0,ceil:1e3,actualStandard:n}}(E,g),C=!0===T,U=G<0,q=Math[$];if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(U&&(G=-G),0===G)return function(t,e,i,n,r,l,c,b,p,d,m,y="",h={},g=""){let M;return M=t>0?(0).toPrecision(t):p&&d>0?(0).toFixed(d):0,c===u?0:(M=B(t<=0&&(!0===y||y.length>0)?0:M,y,h,g,p&&t<=0,d,Math.round),m||(m=i?f.symbol[e].bits[0]:f.symbol[e].bytes[0]),n[m]&&(m=n[m]),r&&(l[0]?m=l[0]:(m=f.fullform[e][0],m+=i?"bit":o)),c===a?[M,m]:c===s?{value:M,symbol:m,exponent:0,unit:m}:M+b+m)}(F,z,b,S,C,D,I,v,p,M,void 0,N,w,x);const A=P?U?-BigInt(r):BigInt(r):null;let H=F;if(P){const{e:t,precision:e}=function(t,e,i,n,r){if("string"==typeof e&&(e=Number(e)),-1===e||isNaN(e))if(e=0,n)for(;e<8&&t>=10n**BigInt(3*(e+1));)e++;else for(;e<8&&t>=1024n**BigInt(e+1);)e++;else e=e<0?0:Math.floor(e);return e>8?(r>0&&(r+=8-e),{e:8,precision:r}):{e:e,precision:r}}(A,j,0,Y,F);j=t,H=e}else{const{e:t,precision:e}=function(t,e,i,n,r){return"string"==typeof e&&(e=Number(e)),-1===e||isNaN(e)?(e=n?Math.floor(Math.log(t)/m):Math.floor(Math.log(t)/d))<0&&(e=0):e=e<0?0:Math.floor(e),e>8?(r>0&&(r+=8-e),{e:8,precision:r}):{e:e,precision:r}}(G,j,0,Y,F);j=t,H=e}const L=-1===O||isNaN(O);let Q;Q=P?function(t,e,i,n,r,o=!0){const a=i?10n**BigInt(3*e):1024n**BigInt(e),s=10n**16n;let l=Number(t*s/a)/Number(s);return n&&(l*=8,o&&l>=r&&e<8&&(l/=r,e++)),{result:l,e:e}}(A,j,Y,b,Z,L):h(G,j,Y,b,Z,L),J=Q.result,j=Q.e;const R=function(t,e,i,n,r,o){let a,s;return a=i>0&&n>0?Math.pow(10,n):1,s=1===a?r(t):r(t*a)/a,s===e&&i<8&&o&&(s=1,i++),{value:s,e:i}}(J,Z,j,M,q,L);if(k[0]=R.value,j=R.e,H>0){const t=function(t,i,n,r,o,a,s,l,u,c){if("string"==typeof t&&(t=parseFloat(t)),"number"!=typeof i||isNaN(i))throw new TypeError(e);if((i=Math.floor(i))<1||i>100)throw new TypeError(e);let f=t.toPrecision(i);const b=-1===c||isNaN(c);if(f.includes("e")&&n<8&&b){n++;const{result:t}=h(r,n,o,a,s);let e,c;e=u>0?Math.pow(10,u):1,c=1===e?l(t):l(t*e)/e,f=c.toPrecision(i)}return{value:f,e:n}}(k[0],H,j,G,Y,b,Z,q,M,O);k[0]=t.value,j=t.e}return I===u?j:(K=function(t,e,i,n){const r=f.symbol[t][e?"bits":"bytes"];let o;return o=n&&1===i?e?"kbit":"kB":r[i],o}(z,b,j,Y),k[1]=K,function(t,e,i,n,r,a,s,l,u,c,b,p,d,m){let y;if(e&&("string"==typeof t[0]?t[0]=`-${t[0]}`:0===t[0]?t[0]="-0":t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),y="string"==typeof t[0]?parseFloat(t[0]):t[0],t[0]=B(t[0],n,r,a,s,l,m),u){let e,i;e=d?"bit":o,i=1===Math.abs(y)?"":"s",c[p]?t[1]=c[p]:t[1]=f.fullform[b][p]+e+i}}(k,U,S,N,w,x,p,M,C,D,z,j,b,q),function(t,e,i,n,r){if(n!==a&&n!==s&&n!==l&&n!==u)throw new TypeError(`Invalid output: ${n}`);if(n===a)return t;if(n===s)return{value:t[0],symbol:t[1],exponent:e,unit:i};let o;return o=" "===r?`${t[0]} ${t[1]}`:t.join(r),o}(k,j,K,I,v))}function M({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:r="",separator:o="",spacer:a=" ",standard:s="",output:u=l,fullform:f=!1,exponent:b=-1,roundingMethod:p=c,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){function B(t){try{return"function"==typeof structuredClone?structuredClone(t):JSON.parse(JSON.stringify(t))}catch{return JSON.parse(JSON.stringify(t))}}const M={localeOptions:B(m),symbols:B(y),fullforms:B(h)};return l=>g(l,{bits:t,pad:e,base:i,round:n,locale:r,localeOptions:M.localeOptions,separator:o,spacer:a,symbols:M.symbols,standard:s,output:u,fullform:f,fullforms:M.fullforms,exponent:b,roundingMethod:p,precision:d})}export{g as filesize,M as partial};//# sourceMappingURL=filesize.min.js.map diff --git a/dist/filesize.min.js.map b/dist/filesize.min.js.map index ddb4a8e..46512c9 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\";\nexport const INVALID_PRECISION = \"Invalid precision\";\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\tINVALID_PRECISION,\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\tSTRING,\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 {boolean} pad - Whether to pad decimal places\n * @param {number} round - Number of decimal places for padding\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @param {string|boolean} [locale=\"\"] - Locale setting\n * @param {Object} [localeOptions={}] - Locale formatting options\n * @param {string} [separator=\"\"] - Custom decimal separator\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\tpad,\n\tround,\n\tsymbol,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n) {\n\tlet value;\n\tif (precision > 0) {\n\t\tvalue = (0).toPrecision(precision);\n\t} else if (pad && round > 0) {\n\t\tvalue = (0).toFixed(round);\n\t} else {\n\t\tvalue = 0;\n\t}\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\tvalue = applyNumberFormatting(\n\t\tlocale === true || locale.length > 0 ? 0 : value,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad && precision <= 0,\n\t\tround,\n\t\tMath.round,\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 * Calculates the unit exponent for a bigint input using bigint comparisons\n * @param {bigint} 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 calculateBigIntExponent(num, e, exponent, isDecimal, precision) {\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\n\tif (e === -1 || isNaN(e)) {\n\t\te = 0;\n\t\tif (isDecimal) {\n\t\t\twhile (e < 8 && num >= 10n ** BigInt(3 * (e + 1))) {\n\t\t\t\te++;\n\t\t\t}\n\t\t} else {\n\t\t\twhile (e < 8 && num >= 1024n ** BigInt(e + 1)) {\n\t\t\t\te++;\n\t\t\t}\n\t\t}\n\t} else if (e < 0) {\n\t\te = 0;\n\t} else {\n\t\te = Math.floor(e);\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 * Calculates the value for a bigint input using bigint arithmetic\n * @param {bigint} num - Input file size in bytes\n * @param {number} e - Current exponent\n * @param {boolean} isDecimal - Whether using decimal base\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 calculateBigIntValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst power = isDecimal ? 10n ** BigInt(3 * e) : 1024n ** BigInt(e);\n\t// Scaled division preserves precision above Number.MAX_SAFE_INTEGER.\n\t// Multiply by 10^16 before dividing, then scale back down, so the\n\t// quotient keeps ~16 significant digits instead of collapsing to a float.\n\tconst SHIFT = 10n ** 16n;\n\tlet result = Number((num * SHIFT) / power) / Number(SHIFT);\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\t// Validate precision range. toPrecision() throws a raw RangeError for\n\t// values outside 1-100; normalize to a clean TypeError and floor any\n\t// non-integer value (which toPrecision would otherwise truncate silently).\n\tif (typeof precision !== \"number\" || isNaN(precision)) {\n\t\tthrow new TypeError(INVALID_PRECISION);\n\t}\n\tprecision = Math.floor(precision);\n\tif (precision < 1 || precision > 100) {\n\t\tthrow new TypeError(INVALID_PRECISION);\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(\n\tvalue,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\troundingFunc,\n) {\n\tlet result = value;\n\n\t// When padding alongside a locale, let the locale formatter emit the fixed\n\t// number of fraction digits. The manual string padding below cannot tell a\n\t// locale-inserted grouping separator from the decimal separator, so it\n\t// dropped digits (e.g. \"1,234,500\" became \"1,234\").\n\tconst localePad =\n\t\tpad && round > 0 ? { minimumFractionDigits: round, maximumFractionDigits: round } : undefined;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString(undefined, localePad);\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, { ...localeOptions, ...localePad });\n\t} else if (separator.length > 0) {\n\t\t// Round before separator replacement to ensure excess decimal places\n\t\t// are truncated when pad is also set (fixes padding + separator bug).\n\t\tif (pad && round > 0) {\n\t\t\tconst p = Math.pow(10, round);\n\t\t\tresult = roundingFunc(result * p) / p;\n\t\t}\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Expand scientific notation to full decimal so pathological values like\n\t// Number.MAX_VALUE don't leak \"e+284\" into the output. Only applies when\n\t// the value is a finite number whose string form uses exponent notation.\n\tif (typeof result === \"number\" && isFinite(result) && result.toString().includes(E)) {\n\t\tresult = result.toLocaleString(\"en-US\", { useGrouping: false });\n\t}\n\n\t// Apply padding for the non-locale paths, where the string has a single\n\t// decimal separator and no grouping is inserted.\n\tif (pad && round > 0 && locale !== true && locale.length === 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(round, 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\t// A string exponent (e.g. \"1\") must be coerced to a number before the\n\t// strict `e === 1` checks below; otherwise it indexes the symbol tables\n\t// with a string and misses the SI special case in resolveSymbol.\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\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} else if (e < 0) {\n\t\t// A forced exponent below the auto sentinel (-1) has no meaning and\n\t\t// would otherwise index the power-of-ten/two lookup tables out of\n\t\t// bounds (producing NaN). Clamp to 0, mirroring the e > 8 clamp below.\n\t\te = 0;\n\t} else {\n\t\t// A non-integer positive exponent (e.g. 1.5) would index the\n\t\t// power-of-ten/two lookup tables out of bounds (producing NaN).\n\t\t// Floor it to the nearest valid integer, mirroring the clamps above.\n\t\te = Math.floor(e);\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\troundingFunc,\n) {\n\tif (neg) {\n\t\t// `precision` leaves the value as a string from toPrecision (e.g. \"1.50\").\n\t\t// Negating that arithmetically coerces it back to a number and drops the\n\t\t// trailing zeros the option asked for, so prefix the sign instead.\n\t\tif (typeof result[0] === \"string\") {\n\t\t\tresult[0] = `-${result[0]}`;\n\t\t} else if (result[0] === 0) {\n\t\t\t// A negative value that rounds to zero (e.g. -0.4) becomes -0, which\n\t\t\t// stringifies to \"0\" and drops the sign. Emit the string \"-0\" so the\n\t\t\t// sign is preserved consistently with the precision path.\n\t\t\tresult[0] = \"-0\";\n\t\t} else {\n\t\t\tresult[0] = -result[0];\n\t\t}\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\t// Capture the numeric value before formatting; a comma decimal separator\n\t// (via separator or a locale such as de-DE) would otherwise make parseFloat\n\t// read \"1,5\" as 1 and select the singular unit name.\n\tlet numericValue;\n\tif (typeof result[0] === \"string\") {\n\t\tnumericValue = parseFloat(result[0]);\n\t} else {\n\t\tnumericValue = result[0];\n\t}\n\n\tresult[0] = applyNumberFormatting(\n\t\tresult[0],\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\troundingFunc,\n\t);\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\t// Determine singular/plural suffix. Use Math.abs so a negative value\n\t\t// of exactly 1 (e.g. -1) selects the singular unit name.\n\t\tlet suffix;\n\t\tif (Math.abs(numericValue) === 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\t// Validate the output option. Any value other than the supported set\n\t// (array, object, string, exponent) would silently fall through to the\n\t// string branch below and produce misleading output.\n\tif (output !== ARRAY && output !== OBJECT && output !== STRING && output !== EXPONENT) {\n\t\tthrow new TypeError(`Invalid output: ${output}`);\n\t}\n\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\tcalculateBigIntExponent,\n\tcalculateBigIntValue,\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, roundingMethod is invalid,\n * precision is out of range (1-100), or output is not a supported format\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 *\n * @remarks\n * **Input coercion:** `arg` is coerced via `Number()`. Numeric strings, hex\n * (`\"0x1F\"`), binary (`\"0b101\"`), and octal (`\"0o17\"`) literals are parsed;\n * `null`, `\"\"`, `\" \"`, `true`, `false`, and single-element arrays coerce to\n * their numeric value. `undefined`, `\"1_000\"`, and `\"1000n\"` throw `TypeError`.\n * A `bigint` that overflows `Number.MAX_SAFE_INTEGER` throws `TypeError`.\n *\n * **Option precedence:** When multiple options conflict, `standard` wins over\n * `base`; `fullform` wins over `symbols`; `locale` wins over `separator`;\n * and a missing `fullforms[e]` falls back to the default unit name.\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\tconst isBigInt = typeof arg === \"bigint\";\n\n\tnum = Number(arg);\n\n\tif (isNaN(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (!isFinite(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\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\tpad,\n\t\t\tround,\n\t\t\tundefined,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t);\n\t}\n\n\t// BigInt inputs use bigint arithmetic to preserve precision above\n\t// Number.MAX_SAFE_INTEGER and detect unit boundaries accurately.\n\tconst bigNum = isBigInt ? (neg ? -BigInt(arg) : BigInt(arg)) : null;\n\n\t// Exponent calculation + clamp + precision adjustment\n\tlet precisionAdjusted = precision;\n\tif (isBigInt) {\n\t\tconst { e: calculatedE, precision: pa } = calculateBigIntExponent(\n\t\t\tbigNum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t} else {\n\t\tconst { e: calculatedE, precision: pa } = calculateExponent(\n\t\t\tnum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t}\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tlet valueResult;\n\tif (isBigInt) {\n\t\tvalueResult = calculateBigIntValue(bigNum, e, isDecimal, bits, ceil, autoExponent);\n\t} else {\n\t\tvalueResult = calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent);\n\t}\n\tval = valueResult.result;\n\te = valueResult.e;\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\t// Return the exponent only after every adjustment that other output\n\t// modes apply (bits auto-increment, rounding overflow, precision), so\n\t// it always matches the exponent reported by object output.\n\tif (output === EXPONENT) {\n\t\treturn 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\troundingFunc,\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\t/**\n\t * Safely clone an object using structuredClone with JSON fallback.\n\t * structuredClone can throw for functions, circular refs, etc.\n\t */\n\tfunction safeClone(value) {\n\t\ttry {\n\t\t\treturn typeof structuredClone === \"function\"\n\t\t\t\t? structuredClone(value)\n\t\t\t\t: JSON.parse(JSON.stringify(value));\n\t\t} catch {\n\t\t\treturn JSON.parse(JSON.stringify(value));\n\t\t}\n\t}\n\n\tconst cloned = {\n\t\tlocaleOptions: safeClone(localeOptions),\n\t\tsymbols: safeClone(symbols),\n\t\tfullforms: safeClone(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","INVALID_PRECISION","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","applyNumberFormatting","value","locale","localeOptions","separator","pad","round","roundingFunc","localePad","minimumFractionDigits","maximumFractionDigits","undefined","toLocaleString","length","p","pow","toString","replace","isFinite","includes","useGrouping","x","tmp","split","s","padEnd","filesize","arg","base","EMPTY","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","isBigInt","Number","isNaN","TypeError","getBaseConfiguration","full","neg","toPrecision","toFixed","unit","handleZeroValue","bigNum","BigInt","precisionAdjusted","calculatedE","pa","floor","calculateBigIntExponent","calculateExponent","valueResult","power","SHIFT","calculateBigIntValue","rounded","r","applyRounding","precisionResult","parseFloat","computed","applyPrecisionHandling","symbolTable","resolveSymbol","numericValue","suffix","abs","decorateResult","formatted","join","formatOutput","partial","safeClone","structuredClone","JSON","parse","stringify","cloned"],"mappings":";;;;AACO,MAAMA,EAAiB,iBAEjBC,EAAoB,oBAGpBC,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,KCpD9BE,EAAmB,CACxBpB,CAACA,GAAK,CAAEqB,WAAW,E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A0B,SACAC,QAASsD,EAAOtD,QAChBC,WACAC,SACAlD,WACAmD,UAAWmD,EAAOnD,UAClBC,WACAC,iBACAC,aAEH,QAAAX,cAAAqD"} +{"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\";\nexport const INVALID_PRECISION = \"Invalid precision\";\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\tINVALID_PRECISION,\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\tSTRING,\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 {boolean} pad - Whether to pad decimal places\n * @param {number} round - Number of decimal places for padding\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @param {string|boolean} [locale=\"\"] - Locale setting\n * @param {Object} [localeOptions={}] - Locale formatting options\n * @param {string} [separator=\"\"] - Custom decimal separator\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\tpad,\n\tround,\n\tsymbol,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n) {\n\tlet value;\n\tif (precision > 0) {\n\t\tvalue = (0).toPrecision(precision);\n\t} else if (pad && round > 0) {\n\t\tvalue = (0).toFixed(round);\n\t} else {\n\t\tvalue = 0;\n\t}\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\tvalue = applyNumberFormatting(\n\t\tprecision <= 0 && (locale === true || locale.length > 0) ? 0 : value,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad && precision <= 0,\n\t\tround,\n\t\tMath.round,\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 * Calculates the unit exponent for a bigint input using bigint comparisons\n * @param {bigint} 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 calculateBigIntExponent(num, e, exponent, isDecimal, precision) {\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\n\tif (e === -1 || isNaN(e)) {\n\t\te = 0;\n\t\tif (isDecimal) {\n\t\t\twhile (e < 8 && num >= 10n ** BigInt(3 * (e + 1))) {\n\t\t\t\te++;\n\t\t\t}\n\t\t} else {\n\t\t\twhile (e < 8 && num >= 1024n ** BigInt(e + 1)) {\n\t\t\t\te++;\n\t\t\t}\n\t\t}\n\t} else if (e < 0) {\n\t\te = 0;\n\t} else {\n\t\te = Math.floor(e);\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 * Calculates the value for a bigint input using bigint arithmetic\n * @param {bigint} num - Input file size in bytes\n * @param {number} e - Current exponent\n * @param {boolean} isDecimal - Whether using decimal base\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 calculateBigIntValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst power = isDecimal ? 10n ** BigInt(3 * e) : 1024n ** BigInt(e);\n\t// Scaled division preserves precision above Number.MAX_SAFE_INTEGER.\n\t// Multiply by 10^16 before dividing, then scale back down, so the\n\t// quotient keeps ~16 significant digits instead of collapsing to a float.\n\tconst SHIFT = 10n ** 16n;\n\tlet result = Number((num * SHIFT) / power) / Number(SHIFT);\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\t// Validate precision range. toPrecision() throws a raw RangeError for\n\t// values outside 1-100; normalize to a clean TypeError and floor any\n\t// non-integer value (which toPrecision would otherwise truncate silently).\n\tif (typeof precision !== \"number\" || isNaN(precision)) {\n\t\tthrow new TypeError(INVALID_PRECISION);\n\t}\n\tprecision = Math.floor(precision);\n\tif (precision < 1 || precision > 100) {\n\t\tthrow new TypeError(INVALID_PRECISION);\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(\n\tvalue,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\troundingFunc,\n) {\n\tlet result = value;\n\n\t// When padding alongside a locale, let the locale formatter emit the fixed\n\t// number of fraction digits. The manual string padding below cannot tell a\n\t// locale-inserted grouping separator from the decimal separator, so it\n\t// dropped digits (e.g. \"1,234,500\" became \"1,234\").\n\tconst localePad =\n\t\tpad && round > 0 ? { minimumFractionDigits: round, maximumFractionDigits: round } : undefined;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString(undefined, localePad);\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, { ...localeOptions, ...localePad });\n\t} else if (separator.length > 0) {\n\t\t// Round before separator replacement to ensure excess decimal places\n\t\t// are truncated when pad is also set (fixes padding + separator bug).\n\t\tif (pad && round > 0) {\n\t\t\tconst p = Math.pow(10, round);\n\t\t\tresult = roundingFunc(result * p) / p;\n\t\t}\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Expand scientific notation to full decimal so pathological values like\n\t// Number.MAX_VALUE don't leak \"e+284\" into the output. Only applies when\n\t// the value is a finite number whose string form uses exponent notation.\n\tif (typeof result === \"number\" && isFinite(result) && result.toString().includes(E)) {\n\t\tresult = result.toLocaleString(\"en-US\", { useGrouping: false });\n\t}\n\n\t// Apply padding for the non-locale paths, where the string has a single\n\t// decimal separator and no grouping is inserted.\n\tif (pad && round > 0 && locale !== true && locale.length === 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(round, 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\t// A string exponent (e.g. \"1\") must be coerced to a number before the\n\t// strict `e === 1` checks below; otherwise it indexes the symbol tables\n\t// with a string and misses the SI special case in resolveSymbol.\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\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} else if (e < 0) {\n\t\t// A forced exponent below the auto sentinel (-1) has no meaning and\n\t\t// would otherwise index the power-of-ten/two lookup tables out of\n\t\t// bounds (producing NaN). Clamp to 0, mirroring the e > 8 clamp below.\n\t\te = 0;\n\t} else {\n\t\t// A non-integer positive exponent (e.g. 1.5) would index the\n\t\t// power-of-ten/two lookup tables out of bounds (producing NaN).\n\t\t// Floor it to the nearest valid integer, mirroring the clamps above.\n\t\te = Math.floor(e);\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\troundingFunc,\n) {\n\tif (neg) {\n\t\t// `precision` leaves the value as a string from toPrecision (e.g. \"1.50\").\n\t\t// Negating that arithmetically coerces it back to a number and drops the\n\t\t// trailing zeros the option asked for, so prefix the sign instead.\n\t\tif (typeof result[0] === \"string\") {\n\t\t\tresult[0] = `-${result[0]}`;\n\t\t} else if (result[0] === 0) {\n\t\t\t// A negative value that rounds to zero (e.g. -0.4) becomes -0, which\n\t\t\t// stringifies to \"0\" and drops the sign. Emit the string \"-0\" so the\n\t\t\t// sign is preserved consistently with the precision path.\n\t\t\tresult[0] = \"-0\";\n\t\t} else {\n\t\t\tresult[0] = -result[0];\n\t\t}\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\t// Capture the numeric value before formatting; a comma decimal separator\n\t// (via separator or a locale such as de-DE) would otherwise make parseFloat\n\t// read \"1,5\" as 1 and select the singular unit name.\n\tlet numericValue;\n\tif (typeof result[0] === \"string\") {\n\t\tnumericValue = parseFloat(result[0]);\n\t} else {\n\t\tnumericValue = result[0];\n\t}\n\n\tresult[0] = applyNumberFormatting(\n\t\tresult[0],\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\troundingFunc,\n\t);\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\t// Determine singular/plural suffix. Use Math.abs so a negative value\n\t\t// of exactly 1 (e.g. -1) selects the singular unit name.\n\t\tlet suffix;\n\t\tif (Math.abs(numericValue) === 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\t// Validate the output option. Any value other than the supported set\n\t// (array, object, string, exponent) would silently fall through to the\n\t// string branch below and produce misleading output.\n\tif (output !== ARRAY && output !== OBJECT && output !== STRING && output !== EXPONENT) {\n\t\tthrow new TypeError(`Invalid output: ${output}`);\n\t}\n\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\tcalculateBigIntExponent,\n\tcalculateBigIntValue,\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, roundingMethod is invalid,\n * precision is out of range (1-100), or output is not a supported format\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 *\n * @remarks\n * **Input coercion:** `arg` is coerced via `Number()`. Numeric strings, hex\n * (`\"0x1F\"`), binary (`\"0b101\"`), and octal (`\"0o17\"`) literals are parsed;\n * `null`, `\"\"`, `\" \"`, `true`, `false`, and single-element arrays coerce to\n * their numeric value. `undefined`, `\"1_000\"`, and `\"1000n\"` throw `TypeError`.\n * A `bigint` that overflows `Number.MAX_SAFE_INTEGER` throws `TypeError`.\n *\n * **Option precedence:** When multiple options conflict, `standard` wins over\n * `base`; `fullform` wins over `symbols`; `locale` wins over `separator`;\n * and a missing `fullforms[e]` falls back to the default unit name.\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\tconst isBigInt = typeof arg === \"bigint\";\n\n\tnum = Number(arg);\n\n\tif (isNaN(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (!isFinite(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\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\tpad,\n\t\t\tround,\n\t\t\tundefined,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t);\n\t}\n\n\t// BigInt inputs use bigint arithmetic to preserve precision above\n\t// Number.MAX_SAFE_INTEGER and detect unit boundaries accurately.\n\tconst bigNum = isBigInt ? (neg ? -BigInt(arg) : BigInt(arg)) : null;\n\n\t// Exponent calculation + clamp + precision adjustment\n\tlet precisionAdjusted = precision;\n\tif (isBigInt) {\n\t\tconst { e: calculatedE, precision: pa } = calculateBigIntExponent(\n\t\t\tbigNum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t} else {\n\t\tconst { e: calculatedE, precision: pa } = calculateExponent(\n\t\t\tnum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t}\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tlet valueResult;\n\tif (isBigInt) {\n\t\tvalueResult = calculateBigIntValue(bigNum, e, isDecimal, bits, ceil, autoExponent);\n\t} else {\n\t\tvalueResult = calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent);\n\t}\n\tval = valueResult.result;\n\te = valueResult.e;\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\t// Return the exponent only after every adjustment that other output\n\t// modes apply (bits auto-increment, rounding overflow, precision), so\n\t// it always matches the exponent reported by object output.\n\tif (output === EXPONENT) {\n\t\treturn 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\troundingFunc,\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\t/**\n\t * Safely clone an object using structuredClone with JSON fallback.\n\t * structuredClone can throw for functions, circular refs, etc.\n\t */\n\tfunction safeClone(value) {\n\t\ttry {\n\t\t\treturn typeof structuredClone === \"function\"\n\t\t\t\t? structuredClone(value)\n\t\t\t\t: JSON.parse(JSON.stringify(value));\n\t\t} catch {\n\t\t\treturn JSON.parse(JSON.stringify(value));\n\t\t}\n\t}\n\n\tconst cloned = {\n\t\tlocaleOptions: safeClone(localeOptions),\n\t\tsymbols: safeClone(symbols),\n\t\tfullforms: safeClone(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","INVALID_PRECISION","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","applyNumberFormatting","value","locale","localeOptions","separator","pad","round","roundingFunc","localePad","minimumFractionDigits","maximumFractionDigits","undefined","toLocaleString","length","p","pow","toString","replace","isFinite","includes","useGrouping","x","tmp","split","s","padEnd","filesize","arg","base","EMPTY","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","isBigInt","Number","isNaN","TypeError","getBaseConfiguration","full","neg","toPrecision","toFixed","unit","handleZeroValue","bigNum","BigInt","precisionAdjusted","calculatedE","pa","floor","calculateBigIntExponent","calculateExponent","valueResult","power","SHIFT","calculateBigIntValue","rounded","r","applyRounding","precisionResult","parseFloat","computed","applyPrecisionHandling","symbolTable","resolveSymbol","numericValue","suffix","abs","decorateResult","form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B,OAAQqB,EAAO,GACfoC,SAAUvC,EACVqD,KAAMV,GAIR,IAAIqC,EAMJ,OAJCA,ED1kBmB,MCykBhB9C,EACS,GAAG/B,EAAO,MAAMA,EAAO,KAEvBA,EAAO8E,KAAK/C,GAElB8C,CACR,CCjZQE,CAAa/E,EAAQH,EAAG2C,EAAGN,EAAQH,GAC3C,CA4BO,SAASiD,GAAQnG,KACvBA,GAAO,EAAKyB,IACZA,GAAM,EAAKuB,KACXA,GAAO,EAAEtB,MACTA,EAAQ,EAACJ,OACTA,EAAS2B,GAAKzB,UACdA,EAAYyB,GAAKC,OACjBA,EFlOoB,IEkONE,SACdA,EAAWH,GAAKI,OAChBA,EAAS3D,EAAMS,SACfA,GAAW,EAAKoD,SAChBA,GAAW,EAAEC,eACbA,EAAiB5D,EAAK6D,UACtBA,EAAY,EAAClC,cACbA,EAAgB,CAAA,EAAE4B,QAClBA,EAAU,CAAA,EAAEG,UACZA,EAAY,IACT,IAKH,SAAS8C,EAAU/E,GAClB,IACC,MAAkC,mBAApBgF,gBACXA,gBAAgBhF,GAChBiF,KAAKC,MAAMD,KAAKE,UAAUnF,GAC9B,CAAE,MACD,OAAOiF,KAAKC,MAAMD,KAAKE,UAAUnF,GAClC,CACD,CAEA,MAAMoF,EAAS,CACdlF,cAAe6E,EAAU7E,GACzB4B,QAASiD,EAAUjD,GACnBG,UAAW8C,EAAU9C,IAGtB,OAAQP,GACPD,EAASC,EAAK,CACb/C,OACAyB,MACAuB,OACAtB,QACAJ,SACAC,cAAekF,EAAOlF,cACtBC,YACA0B,SACAC,QAASsD,EAAOtD,QAChBC,WACAC,SACAlD,WACAmD,UAAWmD,EAAOnD,UAClBC,WACAC,iBACAC,aAEH,QAAAX,cAAAqD"} diff --git a/dist/filesize.umd.js b/dist/filesize.umd.js index 41609dd..81b50e0 100644 --- a/dist/filesize.umd.js +++ b/dist/filesize.umd.js @@ -162,7 +162,7 @@ function handleZeroValue( } value = applyNumberFormatting( - locale === true || locale.length > 0 ? 0 : value, + precision <= 0 && (locale === true || locale.length > 0) ? 0 : value, locale, localeOptions, separator, diff --git a/dist/filesize.umd.min.js b/dist/filesize.umd.min.js index 7a150c2..1895792 100644 --- a/dist/filesize.umd.min.js +++ b/dist/filesize.umd.min.js @@ -2,4 +2,4 @@ 2026 Jason Mulligan @version 11.0.25 */ -!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="Invalid precision",n="iec",o="jedec",r="si",s="byte",a="array",l="object",u="string",c="exponent",f="round",p={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],m=Math.log(1024),y=Math.log(1e3),h={[r]:{isDecimal:!0,ceil:1e3,actualStandard:o},[n]:{isDecimal:!1,ceil:1024,actualStandard:n},[o]:{isDecimal:!1,ceil:1024,actualStandard:o}};function g(t,e,i,n,o,r=!0){let s;s=i?d[e]:b[e];let a=t/s;return n&&(a*=8,r&&a>=o&&e<8&&(a/=o,e++)),{result:a,e:e}}function B(t,e,i,n,o,r,s){let a=t;const l=o&&r>0?{minimumFractionDigits:r,maximumFractionDigits:r}:void 0;if(!0===e)a=a.toLocaleString(void 0,l);else if(e.length>0)a=a.toLocaleString(e,{...i,...l});else if(n.length>0){if(o&&r>0){const t=Math.pow(10,r);a=s(a*t)/t}a=a.toString().replace(".",n)}if("number"==typeof a&&isFinite(a)&&a.toString().includes("e")&&(a=a.toLocaleString("en-US",{useGrouping:!1})),o&&r>0&&!0!==e&&0===e.length){const t=n||".",e=a.toString().split(t),i=e[1]||"";a=`${e[0]}${t}${i.padEnd(r,"0")}`}return a}function M(t,{bits:r=!1,pad:b=!1,base:d=-1,round:M=2,locale:N="",localeOptions:x={},separator:w="",spacer:T=" ",symbols:v={},standard:S="",output:E=u,fullform:I=!1,fullforms:D=[],exponent:O=-1,roundingMethod:$=f,precision:F=0}={}){let j,G=O,k=[],J=0,K="";const P="bigint"==typeof t;if(j=Number(t),isNaN(j))throw new TypeError(e);if(!isFinite(j))throw new TypeError(e);const{isDecimal:Y,ceil:Z,actualStandard:z}=function(t,e){return h[t]?h[t]:2===e?{isDecimal:!1,ceil:1024,actualStandard:n}:{isDecimal:!0,ceil:1e3,actualStandard:o}}(S,d),C=!0===I,U=j<0,q=Math[$];if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(U&&(j=-j),0===j)return function(t,e,i,n,o,r,u,f,b,d,m,y="",h={},g=""){let M;return M=t>0?(0).toPrecision(t):b&&d>0?(0).toFixed(d):0,u===c?0:(M=B(!0===y||y.length>0?0:M,y,h,g,b&&t<=0,d,Math.round),m||(m=i?p.symbol[e].bits[0]:p.symbol[e].bytes[0]),n[m]&&(m=n[m]),o&&(r[0]?m=r[0]:(m=p.fullform[e][0],m+=i?"bit":s)),u===a?[M,m]:u===l?{value:M,symbol:m,exponent:0,unit:m}:M+f+m)}(F,z,r,v,C,D,E,T,b,M,void 0,N,x,w);const A=P?U?-BigInt(t):BigInt(t):null;let H=F;if(P){const{e:t,precision:e}=function(t,e,i,n,o){if("string"==typeof e&&(e=Number(e)),-1===e||isNaN(e))if(e=0,n)for(;e<8&&t>=10n**BigInt(3*(e+1));)e++;else for(;e<8&&t>=1024n**BigInt(e+1);)e++;else e=e<0?0:Math.floor(e);return e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(A,G,0,Y,F);G=t,H=e}else{const{e:t,precision:e}=function(t,e,i,n,o){return"string"==typeof e&&(e=Number(e)),-1===e||isNaN(e)?(e=n?Math.floor(Math.log(t)/y):Math.floor(Math.log(t)/m))<0&&(e=0):e=e<0?0:Math.floor(e),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(j,G,0,Y,F);G=t,H=e}const L=-1===O||isNaN(O);let Q;Q=P?function(t,e,i,n,o,r=!0){const s=i?10n**BigInt(3*e):1024n**BigInt(e),a=10n**16n;let l=Number(t*a/s)/Number(a);return n&&(l*=8,r&&l>=o&&e<8&&(l/=o,e++)),{result:l,e:e}}(A,G,Y,r,Z,L):g(j,G,Y,r,Z,L),J=Q.result,G=Q.e;const R=function(t,e,i,n,o,r){let s,a;return s=i>0&&n>0?Math.pow(10,n):1,a=1===s?o(t):o(t*s)/s,a===e&&i<8&&r&&(a=1,i++),{value:a,e:i}}(J,Z,G,M,q,L);if(k[0]=R.value,G=R.e,H>0){const t=function(t,e,n,o,r,s,a,l,u,c){if("string"==typeof t&&(t=parseFloat(t)),"number"!=typeof e||isNaN(e))throw new TypeError(i);if((e=Math.floor(e))<1||e>100)throw new TypeError(i);let f=t.toPrecision(e);const p=-1===c||isNaN(c);if(f.includes("e")&&n<8&&p){n++;const{result:t}=g(o,n,r,s,a);let i,c;i=u>0?Math.pow(10,u):1,c=1===i?l(t):l(t*i)/i,f=c.toPrecision(e)}return{value:f,e:n}}(k[0],H,G,j,Y,r,Z,q,M,O);k[0]=t.value,G=t.e}return E===c?G:(K=function(t,e,i,n){const o=p.symbol[t][e?"bits":"bytes"];let r;return r=n&&1===i?e?"kbit":"kB":o[i],r}(z,r,G,Y),k[1]=K,function(t,e,i,n,o,r,a,l,u,c,f,b,d,m){let y;if(e&&("string"==typeof t[0]?t[0]=`-${t[0]}`:0===t[0]?t[0]="-0":t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),y="string"==typeof t[0]?parseFloat(t[0]):t[0],t[0]=B(t[0],n,o,r,a,l,m),u){let e,i;e=d?"bit":s,i=1===Math.abs(y)?"":"s",c[b]?t[1]=c[b]:t[1]=p.fullform[f][b]+e+i}}(k,U,v,N,x,w,b,M,C,D,z,G,r,q),function(t,e,i,n,o){if(n!==a&&n!==l&&n!==u&&n!==c)throw new TypeError(`Invalid output: ${n}`);if(n===a)return t;if(n===l)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,G,K,E,T))}t.filesize=M,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",separator:r="",spacer:s=" ",standard:a="",output:l=u,fullform:c=!1,exponent:p=-1,roundingMethod:b=f,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){function g(t){try{return"function"==typeof structuredClone?structuredClone(t):JSON.parse(JSON.stringify(t))}catch{return JSON.parse(JSON.stringify(t))}}const B={localeOptions:g(m),symbols:g(y),fullforms:g(h)};return u=>M(u,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:B.localeOptions,separator:r,spacer:s,symbols:B.symbols,standard:a,output:l,fullform:c,fullforms:B.fullforms,exponent:p,roundingMethod:b,precision:d})}});//# 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="Invalid precision",n="iec",o="jedec",r="si",s="byte",a="array",l="object",u="string",c="exponent",f="round",p={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],m=Math.log(1024),y=Math.log(1e3),h={[r]:{isDecimal:!0,ceil:1e3,actualStandard:o},[n]:{isDecimal:!1,ceil:1024,actualStandard:n},[o]:{isDecimal:!1,ceil:1024,actualStandard:o}};function g(t,e,i,n,o,r=!0){let s;s=i?d[e]:b[e];let a=t/s;return n&&(a*=8,r&&a>=o&&e<8&&(a/=o,e++)),{result:a,e:e}}function B(t,e,i,n,o,r,s){let a=t;const l=o&&r>0?{minimumFractionDigits:r,maximumFractionDigits:r}:void 0;if(!0===e)a=a.toLocaleString(void 0,l);else if(e.length>0)a=a.toLocaleString(e,{...i,...l});else if(n.length>0){if(o&&r>0){const t=Math.pow(10,r);a=s(a*t)/t}a=a.toString().replace(".",n)}if("number"==typeof a&&isFinite(a)&&a.toString().includes("e")&&(a=a.toLocaleString("en-US",{useGrouping:!1})),o&&r>0&&!0!==e&&0===e.length){const t=n||".",e=a.toString().split(t),i=e[1]||"";a=`${e[0]}${t}${i.padEnd(r,"0")}`}return a}function M(t,{bits:r=!1,pad:b=!1,base:d=-1,round:M=2,locale:N="",localeOptions:x={},separator:w="",spacer:T=" ",symbols:v={},standard:S="",output:E=u,fullform:I=!1,fullforms:D=[],exponent:O=-1,roundingMethod:$=f,precision:F=0}={}){let j,G=O,k=[],J=0,K="";const P="bigint"==typeof t;if(j=Number(t),isNaN(j))throw new TypeError(e);if(!isFinite(j))throw new TypeError(e);const{isDecimal:Y,ceil:Z,actualStandard:z}=function(t,e){return h[t]?h[t]:2===e?{isDecimal:!1,ceil:1024,actualStandard:n}:{isDecimal:!0,ceil:1e3,actualStandard:o}}(S,d),C=!0===I,U=j<0,q=Math[$];if("function"!=typeof q)throw new TypeError("Invalid rounding method");if(U&&(j=-j),0===j)return function(t,e,i,n,o,r,u,f,b,d,m,y="",h={},g=""){let M;return M=t>0?(0).toPrecision(t):b&&d>0?(0).toFixed(d):0,u===c?0:(M=B(t<=0&&(!0===y||y.length>0)?0:M,y,h,g,b&&t<=0,d,Math.round),m||(m=i?p.symbol[e].bits[0]:p.symbol[e].bytes[0]),n[m]&&(m=n[m]),o&&(r[0]?m=r[0]:(m=p.fullform[e][0],m+=i?"bit":s)),u===a?[M,m]:u===l?{value:M,symbol:m,exponent:0,unit:m}:M+f+m)}(F,z,r,v,C,D,E,T,b,M,void 0,N,x,w);const A=P?U?-BigInt(t):BigInt(t):null;let H=F;if(P){const{e:t,precision:e}=function(t,e,i,n,o){if("string"==typeof e&&(e=Number(e)),-1===e||isNaN(e))if(e=0,n)for(;e<8&&t>=10n**BigInt(3*(e+1));)e++;else for(;e<8&&t>=1024n**BigInt(e+1);)e++;else e=e<0?0:Math.floor(e);return e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(A,G,0,Y,F);G=t,H=e}else{const{e:t,precision:e}=function(t,e,i,n,o){return"string"==typeof e&&(e=Number(e)),-1===e||isNaN(e)?(e=n?Math.floor(Math.log(t)/y):Math.floor(Math.log(t)/m))<0&&(e=0):e=e<0?0:Math.floor(e),e>8?(o>0&&(o+=8-e),{e:8,precision:o}):{e:e,precision:o}}(j,G,0,Y,F);G=t,H=e}const L=-1===O||isNaN(O);let Q;Q=P?function(t,e,i,n,o,r=!0){const s=i?10n**BigInt(3*e):1024n**BigInt(e),a=10n**16n;let l=Number(t*a/s)/Number(a);return n&&(l*=8,r&&l>=o&&e<8&&(l/=o,e++)),{result:l,e:e}}(A,G,Y,r,Z,L):g(j,G,Y,r,Z,L),J=Q.result,G=Q.e;const R=function(t,e,i,n,o,r){let s,a;return s=i>0&&n>0?Math.pow(10,n):1,a=1===s?o(t):o(t*s)/s,a===e&&i<8&&r&&(a=1,i++),{value:a,e:i}}(J,Z,G,M,q,L);if(k[0]=R.value,G=R.e,H>0){const t=function(t,e,n,o,r,s,a,l,u,c){if("string"==typeof t&&(t=parseFloat(t)),"number"!=typeof e||isNaN(e))throw new TypeError(i);if((e=Math.floor(e))<1||e>100)throw new TypeError(i);let f=t.toPrecision(e);const p=-1===c||isNaN(c);if(f.includes("e")&&n<8&&p){n++;const{result:t}=g(o,n,r,s,a);let i,c;i=u>0?Math.pow(10,u):1,c=1===i?l(t):l(t*i)/i,f=c.toPrecision(e)}return{value:f,e:n}}(k[0],H,G,j,Y,r,Z,q,M,O);k[0]=t.value,G=t.e}return E===c?G:(K=function(t,e,i,n){const o=p.symbol[t][e?"bits":"bytes"];let r;return r=n&&1===i?e?"kbit":"kB":o[i],r}(z,r,G,Y),k[1]=K,function(t,e,i,n,o,r,a,l,u,c,f,b,d,m){let y;if(e&&("string"==typeof t[0]?t[0]=`-${t[0]}`:0===t[0]?t[0]="-0":t[0]=-t[0]),i[t[1]]&&(t[1]=i[t[1]]),y="string"==typeof t[0]?parseFloat(t[0]):t[0],t[0]=B(t[0],n,o,r,a,l,m),u){let e,i;e=d?"bit":s,i=1===Math.abs(y)?"":"s",c[b]?t[1]=c[b]:t[1]=p.fullform[f][b]+e+i}}(k,U,v,N,x,w,b,M,C,D,z,G,r,q),function(t,e,i,n,o){if(n!==a&&n!==l&&n!==u&&n!==c)throw new TypeError(`Invalid output: ${n}`);if(n===a)return t;if(n===l)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,G,K,E,T))}t.filesize=M,t.partial=function({bits:t=!1,pad:e=!1,base:i=-1,round:n=2,locale:o="",separator:r="",spacer:s=" ",standard:a="",output:l=u,fullform:c=!1,exponent:p=-1,roundingMethod:b=f,precision:d=0,localeOptions:m={},symbols:y={},fullforms:h=[]}={}){function g(t){try{return"function"==typeof structuredClone?structuredClone(t):JSON.parse(JSON.stringify(t))}catch{return JSON.parse(JSON.stringify(t))}}const B={localeOptions:g(m),symbols:g(y),fullforms:g(h)};return u=>M(u,{bits:t,pad:e,base:i,round:n,locale:o,localeOptions:B.localeOptions,separator:r,spacer:s,symbols:B.symbols,standard:a,output:l,fullform:c,fullforms:B.fullforms,exponent:p,roundingMethod:b,precision:d})}});//# sourceMappingURL=filesize.umd.min.js.map diff --git a/dist/filesize.umd.min.js.map b/dist/filesize.umd.min.js.map index 89c6ee8..90f7edf 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\";\nexport const INVALID_PRECISION = \"Invalid precision\";\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\tINVALID_PRECISION,\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\tSTRING,\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 {boolean} pad - Whether to pad decimal places\n * @param {number} round - Number of decimal places for padding\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @param {string|boolean} [locale=\"\"] - Locale setting\n * @param {Object} [localeOptions={}] - Locale formatting options\n * @param {string} [separator=\"\"] - Custom decimal separator\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\tpad,\n\tround,\n\tsymbol,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n) {\n\tlet value;\n\tif (precision > 0) {\n\t\tvalue = (0).toPrecision(precision);\n\t} else if (pad && round > 0) {\n\t\tvalue = (0).toFixed(round);\n\t} else {\n\t\tvalue = 0;\n\t}\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\tvalue = applyNumberFormatting(\n\t\tlocale === true || locale.length > 0 ? 0 : value,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad && precision <= 0,\n\t\tround,\n\t\tMath.round,\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 * Calculates the unit exponent for a bigint input using bigint comparisons\n * @param {bigint} 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 calculateBigIntExponent(num, e, exponent, isDecimal, precision) {\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\n\tif (e === -1 || isNaN(e)) {\n\t\te = 0;\n\t\tif (isDecimal) {\n\t\t\twhile (e < 8 && num >= 10n ** BigInt(3 * (e + 1))) {\n\t\t\t\te++;\n\t\t\t}\n\t\t} else {\n\t\t\twhile (e < 8 && num >= 1024n ** BigInt(e + 1)) {\n\t\t\t\te++;\n\t\t\t}\n\t\t}\n\t} else if (e < 0) {\n\t\te = 0;\n\t} else {\n\t\te = Math.floor(e);\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 * Calculates the value for a bigint input using bigint arithmetic\n * @param {bigint} num - Input file size in bytes\n * @param {number} e - Current exponent\n * @param {boolean} isDecimal - Whether using decimal base\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 calculateBigIntValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst power = isDecimal ? 10n ** BigInt(3 * e) : 1024n ** BigInt(e);\n\t// Scaled division preserves precision above Number.MAX_SAFE_INTEGER.\n\t// Multiply by 10^16 before dividing, then scale back down, so the\n\t// quotient keeps ~16 significant digits instead of collapsing to a float.\n\tconst SHIFT = 10n ** 16n;\n\tlet result = Number((num * SHIFT) / power) / Number(SHIFT);\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\t// Validate precision range. toPrecision() throws a raw RangeError for\n\t// values outside 1-100; normalize to a clean TypeError and floor any\n\t// non-integer value (which toPrecision would otherwise truncate silently).\n\tif (typeof precision !== \"number\" || isNaN(precision)) {\n\t\tthrow new TypeError(INVALID_PRECISION);\n\t}\n\tprecision = Math.floor(precision);\n\tif (precision < 1 || precision > 100) {\n\t\tthrow new TypeError(INVALID_PRECISION);\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(\n\tvalue,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\troundingFunc,\n) {\n\tlet result = value;\n\n\t// When padding alongside a locale, let the locale formatter emit the fixed\n\t// number of fraction digits. The manual string padding below cannot tell a\n\t// locale-inserted grouping separator from the decimal separator, so it\n\t// dropped digits (e.g. \"1,234,500\" became \"1,234\").\n\tconst localePad =\n\t\tpad && round > 0 ? { minimumFractionDigits: round, maximumFractionDigits: round } : undefined;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString(undefined, localePad);\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, { ...localeOptions, ...localePad });\n\t} else if (separator.length > 0) {\n\t\t// Round before separator replacement to ensure excess decimal places\n\t\t// are truncated when pad is also set (fixes padding + separator bug).\n\t\tif (pad && round > 0) {\n\t\t\tconst p = Math.pow(10, round);\n\t\t\tresult = roundingFunc(result * p) / p;\n\t\t}\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Expand scientific notation to full decimal so pathological values like\n\t// Number.MAX_VALUE don't leak \"e+284\" into the output. Only applies when\n\t// the value is a finite number whose string form uses exponent notation.\n\tif (typeof result === \"number\" && isFinite(result) && result.toString().includes(E)) {\n\t\tresult = result.toLocaleString(\"en-US\", { useGrouping: false });\n\t}\n\n\t// Apply padding for the non-locale paths, where the string has a single\n\t// decimal separator and no grouping is inserted.\n\tif (pad && round > 0 && locale !== true && locale.length === 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(round, 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\t// A string exponent (e.g. \"1\") must be coerced to a number before the\n\t// strict `e === 1` checks below; otherwise it indexes the symbol tables\n\t// with a string and misses the SI special case in resolveSymbol.\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\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} else if (e < 0) {\n\t\t// A forced exponent below the auto sentinel (-1) has no meaning and\n\t\t// would otherwise index the power-of-ten/two lookup tables out of\n\t\t// bounds (producing NaN). Clamp to 0, mirroring the e > 8 clamp below.\n\t\te = 0;\n\t} else {\n\t\t// A non-integer positive exponent (e.g. 1.5) would index the\n\t\t// power-of-ten/two lookup tables out of bounds (producing NaN).\n\t\t// Floor it to the nearest valid integer, mirroring the clamps above.\n\t\te = Math.floor(e);\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\troundingFunc,\n) {\n\tif (neg) {\n\t\t// `precision` leaves the value as a string from toPrecision (e.g. \"1.50\").\n\t\t// Negating that arithmetically coerces it back to a number and drops the\n\t\t// trailing zeros the option asked for, so prefix the sign instead.\n\t\tif (typeof result[0] === \"string\") {\n\t\t\tresult[0] = `-${result[0]}`;\n\t\t} else if (result[0] === 0) {\n\t\t\t// A negative value that rounds to zero (e.g. -0.4) becomes -0, which\n\t\t\t// stringifies to \"0\" and drops the sign. Emit the string \"-0\" so the\n\t\t\t// sign is preserved consistently with the precision path.\n\t\t\tresult[0] = \"-0\";\n\t\t} else {\n\t\t\tresult[0] = -result[0];\n\t\t}\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\t// Capture the numeric value before formatting; a comma decimal separator\n\t// (via separator or a locale such as de-DE) would otherwise make parseFloat\n\t// read \"1,5\" as 1 and select the singular unit name.\n\tlet numericValue;\n\tif (typeof result[0] === \"string\") {\n\t\tnumericValue = parseFloat(result[0]);\n\t} else {\n\t\tnumericValue = result[0];\n\t}\n\n\tresult[0] = applyNumberFormatting(\n\t\tresult[0],\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\troundingFunc,\n\t);\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\t// Determine singular/plural suffix. Use Math.abs so a negative value\n\t\t// of exactly 1 (e.g. -1) selects the singular unit name.\n\t\tlet suffix;\n\t\tif (Math.abs(numericValue) === 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\t// Validate the output option. Any value other than the supported set\n\t// (array, object, string, exponent) would silently fall through to the\n\t// string branch below and produce misleading output.\n\tif (output !== ARRAY && output !== OBJECT && output !== STRING && output !== EXPONENT) {\n\t\tthrow new TypeError(`Invalid output: ${output}`);\n\t}\n\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\tcalculateBigIntExponent,\n\tcalculateBigIntValue,\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, roundingMethod is invalid,\n * precision is out of range (1-100), or output is not a supported format\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 *\n * @remarks\n * **Input coercion:** `arg` is coerced via `Number()`. Numeric strings, hex\n * (`\"0x1F\"`), binary (`\"0b101\"`), and octal (`\"0o17\"`) literals are parsed;\n * `null`, `\"\"`, `\" \"`, `true`, `false`, and single-element arrays coerce to\n * their numeric value. `undefined`, `\"1_000\"`, and `\"1000n\"` throw `TypeError`.\n * A `bigint` that overflows `Number.MAX_SAFE_INTEGER` throws `TypeError`.\n *\n * **Option precedence:** When multiple options conflict, `standard` wins over\n * `base`; `fullform` wins over `symbols`; `locale` wins over `separator`;\n * and a missing `fullforms[e]` falls back to the default unit name.\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\tconst isBigInt = typeof arg === \"bigint\";\n\n\tnum = Number(arg);\n\n\tif (isNaN(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (!isFinite(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\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\tpad,\n\t\t\tround,\n\t\t\tundefined,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t);\n\t}\n\n\t// BigInt inputs use bigint arithmetic to preserve precision above\n\t// Number.MAX_SAFE_INTEGER and detect unit boundaries accurately.\n\tconst bigNum = isBigInt ? (neg ? -BigInt(arg) : BigInt(arg)) : null;\n\n\t// Exponent calculation + clamp + precision adjustment\n\tlet precisionAdjusted = precision;\n\tif (isBigInt) {\n\t\tconst { e: calculatedE, precision: pa } = calculateBigIntExponent(\n\t\t\tbigNum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t} else {\n\t\tconst { e: calculatedE, precision: pa } = calculateExponent(\n\t\t\tnum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t}\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tlet valueResult;\n\tif (isBigInt) {\n\t\tvalueResult = calculateBigIntValue(bigNum, e, isDecimal, bits, ceil, autoExponent);\n\t} else {\n\t\tvalueResult = calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent);\n\t}\n\tval = valueResult.result;\n\te = valueResult.e;\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\t// Return the exponent only after every adjustment that other output\n\t// modes apply (bits auto-increment, rounding overflow, precision), so\n\t// it always matches the exponent reported by object output.\n\tif (output === EXPONENT) {\n\t\treturn 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\troundingFunc,\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\t/**\n\t * Safely clone an object using structuredClone with JSON fallback.\n\t * structuredClone can throw for functions, circular refs, etc.\n\t */\n\tfunction safeClone(value) {\n\t\ttry {\n\t\t\treturn typeof structuredClone === \"function\"\n\t\t\t\t? structuredClone(value)\n\t\t\t\t: JSON.parse(JSON.stringify(value));\n\t\t} catch {\n\t\t\treturn JSON.parse(JSON.stringify(value));\n\t\t}\n\t}\n\n\tconst cloned = {\n\t\tlocaleOptions: safeClone(localeOptions),\n\t\tsymbols: safeClone(symbols),\n\t\tfullforms: safeClone(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","INVALID_PRECISION","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","applyNumberFormatting","value","locale","localeOptions","separator","pad","round","roundingFunc","localePad","minimumFractionDigits","maximumFractionDigits","undefined","toLocaleString","length","p","pow","toString","replace","isFinite","includes","useGrouping","x","tmp","split","s","padEnd","arg","base","EMPTY","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","isBigInt","Number","isNaN","TypeError","getBaseConfiguration","full","neg","toPrecision","toFixed","unit","handleZeroValue","bigNum","BigInt","precisionAdjusted","calculatedE","pa","floor","calculateBigIntExponent","calculateExponent","valueResult","power","SHIFT","calculateBigIntValue","rounded","r","applyRounding","precisionResult","parseFloat","computed","applyPrecisionHandling","symbolTable","resolveSymbol","numericValue","suffix","abs","decorateResult","formatted","join","formatOutput","partial","safeClone","structuredClone","JSON","parse","stringify","cloned"],"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,iBAEjBC,EAAoB,oBAGpBC,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,CAC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OAAOgF,KAAKC,MAAMD,KAAKE,UAAUlF,GAClC,CACD,CAEA,MAAMmF,EAAS,CACdjF,cAAe4E,EAAU5E,GACzB2B,QAASiD,EAAUjD,GACnBG,UAAW8C,EAAU9C,IAGtB,OAAQP,GACP9D,EAAS8D,EAAK,CACb9C,OACAyB,MACAsB,OACArB,QACAJ,SACAC,cAAeiF,EAAOjF,cACtBC,YACAyB,SACAC,QAASsD,EAAOtD,QAChBC,WACAC,SACAjD,WACAkD,UAAWmD,EAAOnD,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\";\nexport const INVALID_PRECISION = \"Invalid precision\";\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\tINVALID_PRECISION,\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\tSTRING,\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 {boolean} pad - Whether to pad decimal places\n * @param {number} round - Number of decimal places for padding\n * @param {string} [symbol] - Symbol to use (defaults based on bits/standard)\n * @param {string|boolean} [locale=\"\"] - Locale setting\n * @param {Object} [localeOptions={}] - Locale formatting options\n * @param {string} [separator=\"\"] - Custom decimal separator\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\tpad,\n\tround,\n\tsymbol,\n\tlocale = EMPTY,\n\tlocaleOptions = {},\n\tseparator = EMPTY,\n) {\n\tlet value;\n\tif (precision > 0) {\n\t\tvalue = (0).toPrecision(precision);\n\t} else if (pad && round > 0) {\n\t\tvalue = (0).toFixed(round);\n\t} else {\n\t\tvalue = 0;\n\t}\n\n\tif (output === EXPONENT) {\n\t\treturn 0;\n\t}\n\n\tvalue = applyNumberFormatting(\n\t\tprecision <= 0 && (locale === true || locale.length > 0) ? 0 : value,\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad && precision <= 0,\n\t\tround,\n\t\tMath.round,\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 * Calculates the unit exponent for a bigint input using bigint comparisons\n * @param {bigint} 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 calculateBigIntExponent(num, e, exponent, isDecimal, precision) {\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\n\tif (e === -1 || isNaN(e)) {\n\t\te = 0;\n\t\tif (isDecimal) {\n\t\t\twhile (e < 8 && num >= 10n ** BigInt(3 * (e + 1))) {\n\t\t\t\te++;\n\t\t\t}\n\t\t} else {\n\t\t\twhile (e < 8 && num >= 1024n ** BigInt(e + 1)) {\n\t\t\t\te++;\n\t\t\t}\n\t\t}\n\t} else if (e < 0) {\n\t\te = 0;\n\t} else {\n\t\te = Math.floor(e);\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 * Calculates the value for a bigint input using bigint arithmetic\n * @param {bigint} num - Input file size in bytes\n * @param {number} e - Current exponent\n * @param {boolean} isDecimal - Whether using decimal base\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 calculateBigIntValue(num, e, isDecimal, bits, ceil, autoExponent = true) {\n\tconst power = isDecimal ? 10n ** BigInt(3 * e) : 1024n ** BigInt(e);\n\t// Scaled division preserves precision above Number.MAX_SAFE_INTEGER.\n\t// Multiply by 10^16 before dividing, then scale back down, so the\n\t// quotient keeps ~16 significant digits instead of collapsing to a float.\n\tconst SHIFT = 10n ** 16n;\n\tlet result = Number((num * SHIFT) / power) / Number(SHIFT);\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\t// Validate precision range. toPrecision() throws a raw RangeError for\n\t// values outside 1-100; normalize to a clean TypeError and floor any\n\t// non-integer value (which toPrecision would otherwise truncate silently).\n\tif (typeof precision !== \"number\" || isNaN(precision)) {\n\t\tthrow new TypeError(INVALID_PRECISION);\n\t}\n\tprecision = Math.floor(precision);\n\tif (precision < 1 || precision > 100) {\n\t\tthrow new TypeError(INVALID_PRECISION);\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(\n\tvalue,\n\tlocale,\n\tlocaleOptions,\n\tseparator,\n\tpad,\n\tround,\n\troundingFunc,\n) {\n\tlet result = value;\n\n\t// When padding alongside a locale, let the locale formatter emit the fixed\n\t// number of fraction digits. The manual string padding below cannot tell a\n\t// locale-inserted grouping separator from the decimal separator, so it\n\t// dropped digits (e.g. \"1,234,500\" became \"1,234\").\n\tconst localePad =\n\t\tpad && round > 0 ? { minimumFractionDigits: round, maximumFractionDigits: round } : undefined;\n\n\t// Apply locale formatting\n\tif (locale === true) {\n\t\tresult = result.toLocaleString(undefined, localePad);\n\t} else if (locale.length > 0) {\n\t\tresult = result.toLocaleString(locale, { ...localeOptions, ...localePad });\n\t} else if (separator.length > 0) {\n\t\t// Round before separator replacement to ensure excess decimal places\n\t\t// are truncated when pad is also set (fixes padding + separator bug).\n\t\tif (pad && round > 0) {\n\t\t\tconst p = Math.pow(10, round);\n\t\t\tresult = roundingFunc(result * p) / p;\n\t\t}\n\t\tresult = result.toString().replace(PERIOD, separator);\n\t}\n\n\t// Expand scientific notation to full decimal so pathological values like\n\t// Number.MAX_VALUE don't leak \"e+284\" into the output. Only applies when\n\t// the value is a finite number whose string form uses exponent notation.\n\tif (typeof result === \"number\" && isFinite(result) && result.toString().includes(E)) {\n\t\tresult = result.toLocaleString(\"en-US\", { useGrouping: false });\n\t}\n\n\t// Apply padding for the non-locale paths, where the string has a single\n\t// decimal separator and no grouping is inserted.\n\tif (pad && round > 0 && locale !== true && locale.length === 0) {\n\t\tconst resultStr = result.toString();\n\t\tconst x = separator || PERIOD;\n\t\tconst tmp = resultStr.split(x);\n\t\tconst s = tmp[1] || EMPTY;\n\n\t\tresult = `${tmp[0]}${x}${s.padEnd(round, 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\t// A string exponent (e.g. \"1\") must be coerced to a number before the\n\t// strict `e === 1` checks below; otherwise it indexes the symbol tables\n\t// with a string and misses the SI special case in resolveSymbol.\n\tif (typeof e === \"string\") {\n\t\te = Number(e);\n\t}\n\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} else if (e < 0) {\n\t\t// A forced exponent below the auto sentinel (-1) has no meaning and\n\t\t// would otherwise index the power-of-ten/two lookup tables out of\n\t\t// bounds (producing NaN). Clamp to 0, mirroring the e > 8 clamp below.\n\t\te = 0;\n\t} else {\n\t\t// A non-integer positive exponent (e.g. 1.5) would index the\n\t\t// power-of-ten/two lookup tables out of bounds (producing NaN).\n\t\t// Floor it to the nearest valid integer, mirroring the clamps above.\n\t\te = Math.floor(e);\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\troundingFunc,\n) {\n\tif (neg) {\n\t\t// `precision` leaves the value as a string from toPrecision (e.g. \"1.50\").\n\t\t// Negating that arithmetically coerces it back to a number and drops the\n\t\t// trailing zeros the option asked for, so prefix the sign instead.\n\t\tif (typeof result[0] === \"string\") {\n\t\t\tresult[0] = `-${result[0]}`;\n\t\t} else if (result[0] === 0) {\n\t\t\t// A negative value that rounds to zero (e.g. -0.4) becomes -0, which\n\t\t\t// stringifies to \"0\" and drops the sign. Emit the string \"-0\" so the\n\t\t\t// sign is preserved consistently with the precision path.\n\t\t\tresult[0] = \"-0\";\n\t\t} else {\n\t\t\tresult[0] = -result[0];\n\t\t}\n\t}\n\n\tif (symbols[result[1]]) {\n\t\tresult[1] = symbols[result[1]];\n\t}\n\n\t// Capture the numeric value before formatting; a comma decimal separator\n\t// (via separator or a locale such as de-DE) would otherwise make parseFloat\n\t// read \"1,5\" as 1 and select the singular unit name.\n\tlet numericValue;\n\tif (typeof result[0] === \"string\") {\n\t\tnumericValue = parseFloat(result[0]);\n\t} else {\n\t\tnumericValue = result[0];\n\t}\n\n\tresult[0] = applyNumberFormatting(\n\t\tresult[0],\n\t\tlocale,\n\t\tlocaleOptions,\n\t\tseparator,\n\t\tpad,\n\t\tround,\n\t\troundingFunc,\n\t);\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\t// Determine singular/plural suffix. Use Math.abs so a negative value\n\t\t// of exactly 1 (e.g. -1) selects the singular unit name.\n\t\tlet suffix;\n\t\tif (Math.abs(numericValue) === 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\t// Validate the output option. Any value other than the supported set\n\t// (array, object, string, exponent) would silently fall through to the\n\t// string branch below and produce misleading output.\n\tif (output !== ARRAY && output !== OBJECT && output !== STRING && output !== EXPONENT) {\n\t\tthrow new TypeError(`Invalid output: ${output}`);\n\t}\n\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\tcalculateBigIntExponent,\n\tcalculateBigIntValue,\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, roundingMethod is invalid,\n * precision is out of range (1-100), or output is not a supported format\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 *\n * @remarks\n * **Input coercion:** `arg` is coerced via `Number()`. Numeric strings, hex\n * (`\"0x1F\"`), binary (`\"0b101\"`), and octal (`\"0o17\"`) literals are parsed;\n * `null`, `\"\"`, `\" \"`, `true`, `false`, and single-element arrays coerce to\n * their numeric value. `undefined`, `\"1_000\"`, and `\"1000n\"` throw `TypeError`.\n * A `bigint` that overflows `Number.MAX_SAFE_INTEGER` throws `TypeError`.\n *\n * **Option precedence:** When multiple options conflict, `standard` wins over\n * `base`; `fullform` wins over `symbols`; `locale` wins over `separator`;\n * and a missing `fullforms[e]` falls back to the default unit name.\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\tconst isBigInt = typeof arg === \"bigint\";\n\n\tnum = Number(arg);\n\n\tif (isNaN(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\n\t}\n\n\tif (!isFinite(num)) {\n\t\tthrow new TypeError(INVALID_NUMBER);\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\tpad,\n\t\t\tround,\n\t\t\tundefined,\n\t\t\tlocale,\n\t\t\tlocaleOptions,\n\t\t\tseparator,\n\t\t);\n\t}\n\n\t// BigInt inputs use bigint arithmetic to preserve precision above\n\t// Number.MAX_SAFE_INTEGER and detect unit boundaries accurately.\n\tconst bigNum = isBigInt ? (neg ? -BigInt(arg) : BigInt(arg)) : null;\n\n\t// Exponent calculation + clamp + precision adjustment\n\tlet precisionAdjusted = precision;\n\tif (isBigInt) {\n\t\tconst { e: calculatedE, precision: pa } = calculateBigIntExponent(\n\t\t\tbigNum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t} else {\n\t\tconst { e: calculatedE, precision: pa } = calculateExponent(\n\t\t\tnum,\n\t\t\te,\n\t\t\texponent,\n\t\t\tisDecimal,\n\t\t\tprecision,\n\t\t);\n\t\te = calculatedE;\n\t\tprecisionAdjusted = pa;\n\t}\n\tconst autoExponent = exponent === -1 || isNaN(exponent);\n\n\tlet valueResult;\n\tif (isBigInt) {\n\t\tvalueResult = calculateBigIntValue(bigNum, e, isDecimal, bits, ceil, autoExponent);\n\t} else {\n\t\tvalueResult = calculateOptimizedValue(num, e, isDecimal, bits, ceil, autoExponent);\n\t}\n\tval = valueResult.result;\n\te = valueResult.e;\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\t// Return the exponent only after every adjustment that other output\n\t// modes apply (bits auto-increment, rounding overflow, precision), so\n\t// it always matches the exponent reported by object output.\n\tif (output === EXPONENT) {\n\t\treturn 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\troundingFunc,\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\t/**\n\t * Safely clone an object using structuredClone with JSON fallback.\n\t * structuredClone can throw for functions, circular refs, etc.\n\t */\n\tfunction safeClone(value) {\n\t\ttry {\n\t\t\treturn typeof structuredClone === \"function\"\n\t\t\t\t? structuredClone(value)\n\t\t\t\t: JSON.parse(JSON.stringify(value));\n\t\t} catch {\n\t\t\treturn JSON.parse(JSON.stringify(value));\n\t\t}\n\t}\n\n\tconst cloned = {\n\t\tlocaleOptions: safeClone(localeOptions),\n\t\tsymbols: safeClone(symbols),\n\t\tfullforms: safeClone(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","INVALID_PRECISION","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","applyNumberFormatting","value","locale","localeOptions","separator","pad","round","roundingFunc","localePad","minimumFractionDigits","maximumFractionDigits","undefined","toLocaleString","length","p","pow","toString","replace","isFinite","includes","useGrouping","x","tmp","split","s","padEnd","arg","base","EMPTY","spacer","symbols","standard","output","fullforms","exponent","roundingMethod","precision","val","u","isBigInt","Number","isNaN","TypeError","getBaseConfiguration","full","neg","toPrecision","toFixed","unit","handleZeroValue","bigNum","BigInt","precisionAdjusted","calculatedE","pa","floor","calculateBigIntExponent","calculateExponent","valueResult","power","SHIFT","calculateBigIntValue","rounded","r","applyRounding","precisionResult","parseFloat","computed","applyPrecisionHandling","symbolTable","resolveSymbol","numericValue","suffix","abs","decorateResult","formatted","join","formatOutput","partial","safeClone","structuredClone","JSON","parse","stringify","cloned"],"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,iBAEjBC,EAAoB,oBAGpBC,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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AAE,MACD,OAAOgF,KAAKC,MAAMD,KAAKE,UAAUlF,GAClC,CACD,CAEA,MAAMmF,EAAS,CACdjF,cAAe4E,EAAU5E,GACzB2B,QAASiD,EAAUjD,GACnBG,UAAW8C,EAAU9C,IAGtB,OAAQP,GACP9D,EAAS8D,EAAK,CACb9C,OACAyB,MACAsB,OACArB,QACAJ,SACAC,cAAeiF,EAAOjF,cACtBC,YACAyB,SACAC,QAASsD,EAAOtD,QAChBC,WACAC,SACAjD,WACAkD,UAAWmD,EAAOnD,UAClBC,WACAC,iBACAC,aAEH,CAAA"} diff --git a/src/helpers.js b/src/helpers.js index 00fbba3..4f258e1 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -102,7 +102,7 @@ export function handleZeroValue( } value = applyNumberFormatting( - locale === true || locale.length > 0 ? 0 : value, + precision <= 0 && (locale === true || locale.length > 0) ? 0 : value, locale, localeOptions, separator, diff --git a/tests/unit/filesize.test.js b/tests/unit/filesize.test.js index 0a97e9e..1885636 100644 --- a/tests/unit/filesize.test.js +++ b/tests/unit/filesize.test.js @@ -38,6 +38,13 @@ describe("filesize", () => { assert.strictEqual(filesize(0, { locale: "de-DE", output: "exponent" }), 0); }); + it("should retain zero precision when a locale is requested", () => { + assert.strictEqual(filesize(0, { locale: "de-DE", precision: 3 }), "0.00 B"); + assert.strictEqual(filesize(0, { locale: "de-DE", precision: 3, pad: true }), "0.00 B"); + assert.strictEqual(filesize(0, { locale: true, precision: 3 }), "0.00 B"); + assert.strictEqual(filesize(0, { separator: ",", precision: 3, pad: true }), "0,00 B"); + }); + it("should handle small numbers", () => { assert.strictEqual(filesize(1), "1 B"); assert.strictEqual(filesize(512), "512 B");