-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathfilesize.esm.min.js
6 lines (6 loc) · 2.06 KB
/
filesize.esm.min.js
1
2
3
4
5
6
/*!
2022 Jason Mulligan <[email protected]>
@version 8.0.7
*/
const i={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"]}},t={iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]},e={floor:Math.floor,ceil:Math.ceil};function o(o,a={}){let n,r,b,s,l,p,c,d,u,B,f,g,h,M,y,m,v,x,N,E,w=[],P=0;if(isNaN(o))throw new TypeError("Invalid number");if(b=!0===a.bits,g=!0===a.pad,r=a.base||10,h=void 0!==a.round?a.round:2,c=void 0!==a.locale?a.locale:"",d=a.localeOptions||{},y=void 0!==a.separator?a.separator:"",m=void 0!==a.spacer?a.spacer:" ",x=a.symbols||{},v=a.standard in i?a.standard:"iec",f=a.output||"string",l=!0===a.fullform,p=a.fullforms instanceof Array?a.fullforms:[],n=void 0!==a.exponent?a.exponent:-1,N=e[a.roundingMethod]||Math.round,B=Number(o),u=B<0,s=r>2?1e3:1024,E=!1===isNaN(a.precision)?parseInt(a.precision,10):0,u&&(B=-B),(-1===n||isNaN(n))&&(n=Math.floor(Math.log(B)/Math.log(s)),n<0&&(n=0)),n>8&&(E>0&&(E+=8-n),n=8),"exponent"===f)return n;if(0===B)w[0]=0,M=w[1]=i[v][b?"bits":"bytes"][n];else{P=B/(2===r?Math.pow(2,10*n):Math.pow(1e3,n)),b&&(P*=8,P>=s&&n<8&&(P/=s,n++));const t=Math.pow(10,n>0?h:0);w[0]=N(P*t)/t,w[0]===s&&n<8&&void 0===a.exponent&&(w[0]=1,n++),M=w[1]=i[v][b?"bits":"bytes"][n]}if(u&&(w[0]=-w[0]),E>0&&(w[0]=w[0].toPrecision(E)),w[1]=x[w[1]]||w[1],!0===c?w[0]=w[0].toLocaleString():c.length>0?w[0]=w[0].toLocaleString(c,d):y.length>0&&(w[0]=w[0].toString().replace(".",y)),g&&!1===Number.isInteger(w[0])&&h>0){const i=y||".",t=w[0].toString().split(i),e=t[1]||"",o=e.length,a=h-o;w[0]=`${t[0]}${i}${e.padEnd(o+a,"0")}`}return l&&(w[1]=p[n]?p[n]:t[v][n]+(b?"bit":"byte")+(1===w[0]?"":"s")),"array"===f?w:"object"===f?{value:w[0],symbol:w[1],exponent:n,unit:M}:w.join(m)}o.partial=i=>t=>o(t,i);export{o as default};
//# sourceMappingURL=filesize.esm.min.js.map