diff --git a/CHANGELOG.md b/CHANGELOG.md index 072eaed..2768672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,24 @@ 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.25](https://github.com/avoidwork/filesize.js/compare/11.0.24...11.0.25) + +- 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) +- chore(deps-dev): bump oxlint from 1.83.0 to 1.85.0 [`#351`](https://github.com/avoidwork/filesize.js/pull/351) +- chore(deps-dev): bump rollup from 4.63.3 to 4.63.4 [`#350`](https://github.com/avoidwork/filesize.js/pull/350) +- chore(deps-dev): bump rollup from 4.63.2 to 4.63.3 [`#349`](https://github.com/avoidwork/filesize.js/pull/349) +- chore(deps-dev): bump oxfmt from 0.67.0 to 0.68.0 [`#348`](https://github.com/avoidwork/filesize.js/pull/348) +- chore(deps-dev): bump oxlint from 1.82.0 to 1.83.0 [`#347`](https://github.com/avoidwork/filesize.js/pull/347) +- chore(deps-dev): bump rollup from 4.63.1 to 4.63.2 [`#346`](https://github.com/avoidwork/filesize.js/pull/346) +- fix: preserve BigInt precision above Number.MAX_SAFE_INTEGER (#355) [`#354`](https://github.com/avoidwork/filesize.js/issues/354) + #### [11.0.24](https://github.com/avoidwork/filesize.js/compare/11.0.23...11.0.24) +> 14 September 2026 + +- chore: release v11.0.24 [`#345`](https://github.com/avoidwork/filesize.js/pull/345) - fix: harden input validation and edge-case handling in filesize() [`#344`](https://github.com/avoidwork/filesize.js/pull/344) - chore(deps-dev): bump oxlint from 1.81.0 to 1.82.0 [`#342`](https://github.com/avoidwork/filesize.js/pull/342) - chore(deps-dev): bump oxfmt from 0.66.0 to 0.67.0 [`#341`](https://github.com/avoidwork/filesize.js/pull/341) diff --git a/dist/filesize.cjs b/dist/filesize.cjs index dd49679..f5f72f6 100644 --- a/dist/filesize.cjs +++ b/dist/filesize.cjs @@ -3,7 +3,7 @@ * * @copyright 2026 Jason Mulligan * @license BSD-3-Clause - * @version 11.0.24 + * @version 11.0.25 */ 'use strict'; diff --git a/dist/filesize.js b/dist/filesize.js index 1310271..3b42145 100644 --- a/dist/filesize.js +++ b/dist/filesize.js @@ -3,7 +3,7 @@ * * @copyright 2026 Jason Mulligan * @license BSD-3-Clause - * @version 11.0.24 + * @version 11.0.25 */ // Error Messages const INVALID_NUMBER = "Invalid number"; diff --git a/dist/filesize.min.js b/dist/filesize.min.js index 53a86e3..e714bd7 100644 --- a/dist/filesize.min.js +++ b/dist/filesize.min.js @@ -1,5 +1,5 @@ /*! 2026 Jason Mulligan - @version 11.0.24 + @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 diff --git a/dist/filesize.umd.js b/dist/filesize.umd.js index defb2b5..1e8d257 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.24 + * @version 11.0.25 */ (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 c295d7f..01df871 100644 --- a/dist/filesize.umd.min.js +++ b/dist/filesize.umd.min.js @@ -1,5 +1,5 @@ /*! 2026 Jason Mulligan - @version 11.0.24 + @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 diff --git a/package-lock.json b/package-lock.json index 89b0ed4..6c4cb96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "filesize", - "version": "11.0.24", + "version": "11.0.25", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "filesize", - "version": "11.0.24", + "version": "11.0.25", "license": "BSD-3-Clause", "devDependencies": { "@rollup/plugin-terser": "^1.0.0", diff --git a/package.json b/package.json index cc72e4a..6dc6ffe 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.24", + "version": "11.0.25", "homepage": "https://filesizejs.com", "author": "Jason Mulligan ", "repository": {