UNPKG

2.55 kBJavaScriptView Raw
1/*!
2 2022 Jason Mulligan <jason.mulligan@avoidwork.com>
3 @version 10.0.5
4*/
5const t={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 i(i,{bits:e=!1,pad:o=!1,base:n=-1,round:r=2,locale:b="",localeOptions:s={},separator:l="",spacer:a=" ",symbols:c={},standard:p="",output:u="string",fullform:d=!1,fullforms:f=[],exponent:g=-1,roundingMethod:m="round",precision:y=0}={}){let B=g,h=Number(i),M=[],j=0,x="";-1===n&&0===p.length?(n=10,p="jedec"):-1===n&&p.length>0?n="iec"===(p="iec"===p?"iec":"jedec")?2:10:p=10===(n=2===n?2:10)||"jedec"===p?"jedec":"iec";const w=10===n?1e3:1024,E=!0===d,N=h<0,T=Math[m];if("bigint"!=typeof i&&isNaN(i))throw new TypeError("Invalid number");if("function"!=typeof T)throw new TypeError("Invalid rounding method");if(N&&(h=-h),(-1===B||isNaN(B))&&(B=Math.floor(Math.log(h)/Math.log(w)),B<0&&(B=0)),B>8&&(y>0&&(y+=8-B),B=8),"exponent"===u)return B;if(0===h)M[0]=0,x=M[1]=t.symbol[p][e?"bits":"bytes"][B];else{j=h/(2===n?Math.pow(2,10*B):Math.pow(1e3,B)),e&&(j*=8,j>=w&&B<8&&(j/=w,B++));const i=Math.pow(10,B>0?r:0);M[0]=T(j*i)/i,M[0]===w&&B<8&&-1===g&&(M[0]=1,B++),x=M[1]=10===n&&1===B?e?"kbit":"kB":t.symbol[p][e?"bits":"bytes"][B]}if(N&&(M[0]=-M[0]),y>0&&(M[0]=M[0].toPrecision(y)),M[1]=c[M[1]]||M[1],!0===b?M[0]=M[0].toLocaleString():b.length>0?M[0]=M[0].toLocaleString(b,s):l.length>0&&(M[0]=M[0].toString().replace(".",l)),o&&!1===Number.isInteger(M[0])&&r>0){const t=l||".",i=M[0].toString().split(t),e=i[1]||"",o=e.length,n=r-o;M[0]=`${i[0]}${t}${e.padEnd(o+n,"0")}`}return E&&(M[1]=f[B]?f[B]:t.fullform[p][B]+(e?"bit":"byte")+(1===M[0]?"":"s")),"array"===u?M:"object"===u?{value:M[0],symbol:M[1],exponent:B,unit:x}:M.join(a)}function e({bits:t=!1,pad:e=!1,base:o=-1,round:n=2,locale:r="",localeOptions:b={},separator:s="",spacer:l=" ",symbols:a={},standard:c="",output:p="string",fullform:u=!1,fullforms:d=[],exponent:f=-1,roundingMethod:g="round",precision:m=0}={}){return y=>i(y,{bits:t,pad:e,base:o,round:n,locale:r,localeOptions:b,separator:s,spacer:l,symbols:a,standard:c,output:p,fullform:u,fullforms:d,exponent:f,roundingMethod:g,precision:m})}export{i as filesize,e as partial};//# sourceMappingURL=filesize.esm.min.js.map