UNPKG

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