diff --git a/CHANGELOG.md b/CHANGELOG.md index 2768672..4fed372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,22 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [11.0.26](https://github.com/avoidwork/filesize.js/compare/11.0.25...11.0.26) + +- fix: honor locale and separator options for zero values [`#364`](https://github.com/avoidwork/filesize.js/pull/364) +- chore: update dev dependencies to latest versions [`#363`](https://github.com/avoidwork/filesize.js/pull/363) +- chore(deps-dev): bump rollup from 4.63.6 to 4.64.0 [`#362`](https://github.com/avoidwork/filesize.js/pull/362) +- chore(deps-dev): bump rollup from 4.63.5 to 4.63.6 [`#361`](https://github.com/avoidwork/filesize.js/pull/361) +- chore(deps-dev): bump oxfmt from 0.70.0 to 0.71.0 [`#360`](https://github.com/avoidwork/filesize.js/pull/360) +- chore(deps-dev): bump oxlint from 1.85.0 to 1.86.0 [`#359`](https://github.com/avoidwork/filesize.js/pull/359) +- chore(deps-dev): bump auto-changelog from 2.6.1 to 2.7.0 [`#358`](https://github.com/avoidwork/filesize.js/pull/358) +- chore(deps-dev): bump rollup from 4.63.4 to 4.63.5 [`#357`](https://github.com/avoidwork/filesize.js/pull/357) + #### [11.0.25](https://github.com/avoidwork/filesize.js/compare/11.0.24...11.0.25) +> 26 September 2026 + +- chore: release v11.0.25 [`#356`](https://github.com/avoidwork/filesize.js/pull/356) - fix: preserve BigInt precision above Number.MAX_SAFE_INTEGER [`#355`](https://github.com/avoidwork/filesize.js/pull/355) - docs: fix README accuracy errors [`#353`](https://github.com/avoidwork/filesize.js/pull/353) - chore(deps-dev): bump oxfmt from 0.68.0 to 0.70.0 [`#352`](https://github.com/avoidwork/filesize.js/pull/352) diff --git a/dist/filesize.cjs b/dist/filesize.cjs index 407640f..cf7cfa3 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -3,7 +3,7 @@ * * @copyright 2026 Jason Mulligan * @license BSD-3-Clause - * @version 11.0.25 + * @version 11.0.26 */ 'use strict'; diff --git a/dist/filesize.js b/dist/filesize.js index 0b270ad..398c6bd 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -3,7 +3,7 @@ * * @copyright 2026 Jason Mulligan * @license BSD-3-Clause - * @version 11.0.25 + * @version 11.0.26 */ // Error Messages const INVALID_NUMBER = "Invalid number"; diff --git a/dist/filesize.min.js b/dist/filesize.min.js index 79a191f..67cf2c8 100644 --- a/dist/filesize.min.js +++ b/dist/filesize.min.js @@ -1,5 +1,5 @@ /*! 2026 Jason Mulligan - @version 11.0.25 + @version 11.0.26 */ 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.umd.js b/dist/filesize.umd.js index 81b50e0..3b652b2 100644 --- a/dist/filesize.umd.js +++ b/dist/filesize.umd.js @@ -3,7 +3,7 @@ * * @copyright 2026 Jason Mulligan * @license BSD-3-Clause - * @version 11.0.25 + * @version 11.0.26 */ (function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.filesize={}));})(this,(function(exports){'use strict';// Error Messages const INVALID_NUMBER = "Invalid number"; diff --git a/dist/filesize.umd.min.js b/dist/filesize.umd.min.js index 1895792..4754283 100644 --- a/dist/filesize.umd.min.js +++ b/dist/filesize.umd.min.js @@ -1,5 +1,5 @@ /*! 2026 Jason Mulligan - @version 11.0.25 + @version 11.0.26 */ !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/package-lock.json b/package-lock.json index 3a59c4a..9a392f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "filesize", - "version": "11.0.25", + "version": "11.0.26", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "filesize", - "version": "11.0.25", + "version": "11.0.26", "license": "BSD-3-Clause", "devDependencies": { "@rollup/plugin-terser": "^1.0.0", diff --git a/package.json b/package.json index d22cc77..ca03696 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "filesize", "description": "Lightweight, zero-dependency JavaScript utility to convert bytes to human-readable strings with localization support", - "version": "11.0.25", + "version": "11.0.26", "homepage": "https://filesizejs.com", "author": "Jason Mulligan ", "repository": {