6 lines
2.5 KiB
JavaScript
6 lines
2.5 KiB
JavaScript
/*!
|
|
2024 Jason Mulligan <jason.mulligan@avoidwork.com>
|
|
@version 10.1.6
|
|
*/
|
|
const t="array",i="bit",o="bits",e="byte",n="bytes",r="",a="exponent",b="function",s="iec",l="Invalid number",p="Invalid rounding method",u="jedec",c="object",d=".",f="round",g="s",m="si",B="kbit",y="kB",h=" ",M="string",x="0",w={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"]}};function E(E,{bits:T=!1,pad:j=!1,base:N=-1,round:P=2,locale:S=r,localeOptions:k={},separator:G=r,spacer:K=h,symbols:Y={},standard:Z=r,output:v=M,fullform:O=!1,fullforms:$=[],exponent:z=-1,roundingMethod:I=f,precision:L=0}={}){let D=z,q=Number(E),A=[],C=0,F=r;Z===m?(N=10,Z=u):Z===s||Z===u?N=2:2===N?Z=s:(N=10,Z=u);const H=10===N?1e3:1024,J=!0===O,Q=q<0,R=Math[I];if("bigint"!=typeof E&&isNaN(E))throw new TypeError(l);if(typeof R!==b)throw new TypeError(p);if(Q&&(q=-q),(-1===D||isNaN(D))&&(D=Math.floor(Math.log(q)/Math.log(H)),D<0&&(D=0)),D>8&&(L>0&&(L+=8-D),D=8),v===a)return D;if(0===q)A[0]=0,F=A[1]=w.symbol[Z][T?o:n][D];else{C=q/(2===N?Math.pow(2,10*D):Math.pow(1e3,D)),T&&(C*=8,C>=H&&D<8&&(C/=H,D++));const t=Math.pow(10,D>0?P:0);A[0]=R(C*t)/t,A[0]===H&&D<8&&-1===z&&(A[0]=1,D++),F=A[1]=10===N&&1===D?T?B:y:w.symbol[Z][T?o:n][D]}if(Q&&(A[0]=-A[0]),L>0&&(A[0]=A[0].toPrecision(L)),A[1]=Y[A[1]]||A[1],!0===S?A[0]=A[0].toLocaleString():S.length>0?A[0]=A[0].toLocaleString(S,k):G.length>0&&(A[0]=A[0].toString().replace(d,G)),j&&P>0){const t=A[0].toString(),i=G||(t.match(/(\D)/g)||[]).pop()||d,o=t.toString().split(i),e=o[1]||r,n=e.length,a=P-n;A[0]=`${o[0]}${i}${e.padEnd(n+a,x)}`}return J&&(A[1]=$[D]?$[D]:w.fullform[Z][D]+(T?i:e)+(1===A[0]?r:g)),v===t?A:v===c?{value:A[0],symbol:A[1],exponent:D,unit:F}:A.join(K)}function T({bits:t=!1,pad:i=!1,base:o=-1,round:e=2,locale:n=r,localeOptions:a={},separator:b=r,spacer:s=h,symbols:l={},standard:p=r,output:u=M,fullform:c=!1,fullforms:d=[],exponent:g=-1,roundingMethod:m=f,precision:B=0}={}){return r=>E(r,{bits:t,pad:i,base:o,round:e,locale:n,localeOptions:a,separator:b,spacer:s,symbols:l,standard:p,output:u,fullform:c,fullforms:d,exponent:g,roundingMethod:m,precision:B})}export{E as filesize,T as partial};//# sourceMappingURL=filesize.esm.min.js.map
|