Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

filesize

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filesize - npm Package Compare versions

Comparing version 9.0.8 to 9.0.9

82

lib/filesize.es6.js

@@ -6,3 +6,3 @@ /**

* @license BSD-3-Clause
* @version 9.0.8
* @version 9.0.9
*/

@@ -15,2 +15,24 @@ (function (global, factory) {

const ARRAY = "array";
const BIT = "bit";
const BITS = "bits";
const BYTE = "byte";
const BYTES = "bytes";
const EMPTY = "";
const EXPONENT = "exponent";
const FUNCTION = "function";
const IEC = "iec";
const INVALID_NUMBER = "Invalid number";
const INVALID_ROUND = "Invalid rounding method";
const JEDEC = "jedec";
const OBJECT = "object";
const PERIOD = ".";
const ROUND = "round";
const S = "s";
const SI_KBIT = "kbit";
const SI_KBYTE = "kB";
const SPACE = " ";
const STRING = "string";
const ZERO = "0";
const strings = {

@@ -41,3 +63,20 @@ symbol: {

*/
function filesize (arg, {bits = false, pad = false, base = -1, round = 2, locale = "", localeOptions = {}, separator = "", spacer = " ", symbols = {}, standard = "", output = "string", fullform = false, fullforms = [], exponent = -1, roundingMethod = "round", precision = 0} = {}) {
function filesize (arg, {
bits = false,
pad = false,
base = -1,
round = 2,
locale = EMPTY,
localeOptions = {},
separator = EMPTY,
spacer = SPACE,
symbols = {},
standard = EMPTY,
output = STRING,
fullform = false,
fullforms = [],
exponent = -1,
roundingMethod = ROUND,
precision = 0
} = {}) {
let e = exponent,

@@ -47,3 +86,3 @@ num = Number(arg),

val = 0,
u = "";
u = EMPTY;

@@ -53,9 +92,9 @@ // Sync base & standard

base = 10;
standard = "iec";
standard = JEDEC;
} else if (base === -1 && standard.length > 0) {
standard = standard === "iec" ? "iec" : "jedec";
base = standard === "iec" ? 10 : 2;
standard = standard === IEC ? IEC : JEDEC;
base = standard === IEC ? 2 : 10;
} else {
base = base === 2 ? 2 : 10;
standard = base === 10 ? "iec" : "jedec";
standard = base === 10 ? JEDEC : IEC;
}

@@ -69,7 +108,7 @@

if (isNaN(arg)) {
throw new TypeError("Invalid number");
throw new TypeError(INVALID_NUMBER);
}
if (typeof roundingFunc !== "function") {
throw new TypeError("Invalid rounding method");
if (typeof roundingFunc !== FUNCTION) {
throw new TypeError(INVALID_ROUND);
}

@@ -100,3 +139,3 @@

if (output === "exponent") {
if (output === EXPONENT) {
return e;

@@ -108,3 +147,3 @@ }

result[0] = 0;
u = result[1] = strings.symbol[standard][bits ? "bits" : "bytes"][e];
u = result[1] = strings.symbol[standard][bits ? BITS : BYTES][e];
} else {

@@ -130,3 +169,3 @@ val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));

u = result[1] = strings.symbol[standard][bits ? "bits" : "bytes"][e];
u = result[1] = base === 10 && e === 1 ? bits ? SI_KBIT : SI_KBYTE : strings.symbol[standard][bits ? BITS : BYTES][e];
}

@@ -152,21 +191,26 @@

} else if (separator.length > 0) {
result[0] = result[0].toString().replace(".", separator);
result[0] = result[0].toString().replace(PERIOD, separator);
}
if (pad && Number.isInteger(result[0]) === false && round > 0) {
const x = separator || ".",
const x = separator || PERIOD,
tmp = result[0].toString().split(x),
s = tmp[1] || "",
s = tmp[1] || EMPTY,
l = s.length,
n = round - l;
result[0] = `${tmp[0]}${x}${s.padEnd(l + n, "0")}`;
result[0] = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;
}
if (full) {
result[1] = fullforms[e] ? fullforms[e] : strings.fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
result[1] = fullforms[e] ? fullforms[e] : strings.fullform[standard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);
}
// Returning Array, Object, or String (default)
return output === "array" ? result : output === "object" ? {value: result[0], symbol: result[1], exponent: e, unit: u} : result.join(spacer);
return output === ARRAY ? result : output === OBJECT ? {
value: result[0],
symbol: result[1],
exponent: e,
unit: u
} : result.join(spacer);
}

@@ -173,0 +217,0 @@

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

@@ -6,4 +6,26 @@ /**

* @license BSD-3-Clause
* @version 9.0.8
* @version 9.0.9
*/
const ARRAY = "array";
const BIT = "bit";
const BITS = "bits";
const BYTE = "byte";
const BYTES = "bytes";
const EMPTY = "";
const EXPONENT = "exponent";
const FUNCTION = "function";
const IEC = "iec";
const INVALID_NUMBER = "Invalid number";
const INVALID_ROUND = "Invalid rounding method";
const JEDEC = "jedec";
const OBJECT = "object";
const PERIOD = ".";
const ROUND = "round";
const S = "s";
const SI_KBIT = "kbit";
const SI_KBYTE = "kB";
const SPACE = " ";
const STRING = "string";
const ZERO = "0";
const strings = {

@@ -34,3 +56,20 @@ symbol: {

*/
function filesize (arg, {bits = false, pad = false, base = -1, round = 2, locale = "", localeOptions = {}, separator = "", spacer = " ", symbols = {}, standard = "", output = "string", fullform = false, fullforms = [], exponent = -1, roundingMethod = "round", precision = 0} = {}) {
function filesize (arg, {
bits = false,
pad = false,
base = -1,
round = 2,
locale = EMPTY,
localeOptions = {},
separator = EMPTY,
spacer = SPACE,
symbols = {},
standard = EMPTY,
output = STRING,
fullform = false,
fullforms = [],
exponent = -1,
roundingMethod = ROUND,
precision = 0
} = {}) {
let e = exponent,

@@ -40,3 +79,3 @@ num = Number(arg),

val = 0,
u = "";
u = EMPTY;

@@ -46,9 +85,9 @@ // Sync base & standard

base = 10;
standard = "iec";
standard = JEDEC;
} else if (base === -1 && standard.length > 0) {
standard = standard === "iec" ? "iec" : "jedec";
base = standard === "iec" ? 10 : 2;
standard = standard === IEC ? IEC : JEDEC;
base = standard === IEC ? 2 : 10;
} else {
base = base === 2 ? 2 : 10;
standard = base === 10 ? "iec" : "jedec";
standard = base === 10 ? JEDEC : IEC;
}

@@ -62,7 +101,7 @@

if (isNaN(arg)) {
throw new TypeError("Invalid number");
throw new TypeError(INVALID_NUMBER);
}
if (typeof roundingFunc !== "function") {
throw new TypeError("Invalid rounding method");
if (typeof roundingFunc !== FUNCTION) {
throw new TypeError(INVALID_ROUND);
}

@@ -93,3 +132,3 @@

if (output === "exponent") {
if (output === EXPONENT) {
return e;

@@ -101,3 +140,3 @@ }

result[0] = 0;
u = result[1] = strings.symbol[standard][bits ? "bits" : "bytes"][e];
u = result[1] = strings.symbol[standard][bits ? BITS : BYTES][e];
} else {

@@ -123,3 +162,3 @@ val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));

u = result[1] = strings.symbol[standard][bits ? "bits" : "bytes"][e];
u = result[1] = base === 10 && e === 1 ? bits ? SI_KBIT : SI_KBYTE : strings.symbol[standard][bits ? BITS : BYTES][e];
}

@@ -145,21 +184,26 @@

} else if (separator.length > 0) {
result[0] = result[0].toString().replace(".", separator);
result[0] = result[0].toString().replace(PERIOD, separator);
}
if (pad && Number.isInteger(result[0]) === false && round > 0) {
const x = separator || ".",
const x = separator || PERIOD,
tmp = result[0].toString().split(x),
s = tmp[1] || "",
s = tmp[1] || EMPTY,
l = s.length,
n = round - l;
result[0] = `${tmp[0]}${x}${s.padEnd(l + n, "0")}`;
result[0] = `${tmp[0]}${x}${s.padEnd(l + n, ZERO)}`;
}
if (full) {
result[1] = fullforms[e] ? fullforms[e] : strings.fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
result[1] = fullforms[e] ? fullforms[e] : strings.fullform[standard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);
}
// Returning Array, Object, or String (default)
return output === "array" ? result : output === "object" ? {value: result[0], symbol: result[1], exponent: e, unit: u} : result.join(spacer);
return output === ARRAY ? result : output === OBJECT ? {
value: result[0],
symbol: result[1],
exponent: e,
unit: u
} : result.join(spacer);
}

@@ -166,0 +210,0 @@

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

@@ -6,207 +6,239 @@ /**

* @license BSD-3-Clause
* @version 9.0.8
* @version 9.0.9
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.filesize = factory());
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.filesize = factory());
})(this, (function () { 'use strict';
var strings = {
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 _typeof(obj) {
"@babel/helpers - typeof";
/**
* filesize
*
* @method filesize
* @param {Mixed} arg String, Int or Float to transform
* @param {Object} descriptor [Optional] Flags
* @return {String} Readable file size String
*/
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function filesize(arg) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$bits = _ref.bits,
bits = _ref$bits === void 0 ? false : _ref$bits,
_ref$pad = _ref.pad,
pad = _ref$pad === void 0 ? false : _ref$pad,
_ref$base = _ref.base,
base = _ref$base === void 0 ? -1 : _ref$base,
_ref$round = _ref.round,
round = _ref$round === void 0 ? 2 : _ref$round,
_ref$locale = _ref.locale,
locale = _ref$locale === void 0 ? "" : _ref$locale,
_ref$localeOptions = _ref.localeOptions,
localeOptions = _ref$localeOptions === void 0 ? {} : _ref$localeOptions,
_ref$separator = _ref.separator,
separator = _ref$separator === void 0 ? "" : _ref$separator,
_ref$spacer = _ref.spacer,
spacer = _ref$spacer === void 0 ? " " : _ref$spacer,
_ref$symbols = _ref.symbols,
symbols = _ref$symbols === void 0 ? {} : _ref$symbols,
_ref$standard = _ref.standard,
standard = _ref$standard === void 0 ? "" : _ref$standard,
_ref$output = _ref.output,
output = _ref$output === void 0 ? "string" : _ref$output,
_ref$fullform = _ref.fullform,
fullform = _ref$fullform === void 0 ? false : _ref$fullform,
_ref$fullforms = _ref.fullforms,
fullforms = _ref$fullforms === void 0 ? [] : _ref$fullforms,
_ref$exponent = _ref.exponent,
exponent = _ref$exponent === void 0 ? -1 : _ref$exponent,
_ref$roundingMethod = _ref.roundingMethod,
roundingMethod = _ref$roundingMethod === void 0 ? "round" : _ref$roundingMethod,
_ref$precision = _ref.precision,
precision = _ref$precision === void 0 ? 0 : _ref$precision;
var ARRAY = "array";
var BIT = "bit";
var BITS = "bits";
var BYTE = "byte";
var BYTES = "bytes";
var EMPTY = "";
var EXPONENT = "exponent";
var FUNCTION = "function";
var IEC = "iec";
var INVALID_NUMBER = "Invalid number";
var INVALID_ROUND = "Invalid rounding method";
var JEDEC = "jedec";
var OBJECT = "object";
var PERIOD = ".";
var ROUND = "round";
var S = "s";
var SI_KBIT = "kbit";
var SI_KBYTE = "kB";
var SPACE = " ";
var STRING = "string";
var ZERO = "0";
var e = exponent,
num = Number(arg),
result = [],
val = 0,
u = ""; // Sync base & standard
var strings = {
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"]
}
};
if (base === -1 && standard.length === 0) {
base = 10;
standard = "iec";
} else if (base === -1 && standard.length > 0) {
standard = standard === "iec" ? "iec" : "jedec";
base = standard === "iec" ? 10 : 2;
} else {
base = base === 2 ? 2 : 10;
standard = base === 10 ? "iec" : "jedec";
}
/**
* filesize
*
* @method filesize
* @param {Mixed} arg String, Int or Float to transform
* @param {Object} descriptor [Optional] Flags
* @return {String} Readable file size String
*/
var ceil = base === 10 ? 1000 : 1024,
full = fullform === true,
neg = num < 0,
roundingFunc = Math[roundingMethod];
function filesize(arg) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$bits = _ref.bits,
bits = _ref$bits === void 0 ? false : _ref$bits,
_ref$pad = _ref.pad,
pad = _ref$pad === void 0 ? false : _ref$pad,
_ref$base = _ref.base,
base = _ref$base === void 0 ? -1 : _ref$base,
_ref$round = _ref.round,
round = _ref$round === void 0 ? 2 : _ref$round,
_ref$locale = _ref.locale,
locale = _ref$locale === void 0 ? EMPTY : _ref$locale,
_ref$localeOptions = _ref.localeOptions,
localeOptions = _ref$localeOptions === void 0 ? {} : _ref$localeOptions,
_ref$separator = _ref.separator,
separator = _ref$separator === void 0 ? EMPTY : _ref$separator,
_ref$spacer = _ref.spacer,
spacer = _ref$spacer === void 0 ? SPACE : _ref$spacer,
_ref$symbols = _ref.symbols,
symbols = _ref$symbols === void 0 ? {} : _ref$symbols,
_ref$standard = _ref.standard,
standard = _ref$standard === void 0 ? EMPTY : _ref$standard,
_ref$output = _ref.output,
output = _ref$output === void 0 ? STRING : _ref$output,
_ref$fullform = _ref.fullform,
fullform = _ref$fullform === void 0 ? false : _ref$fullform,
_ref$fullforms = _ref.fullforms,
fullforms = _ref$fullforms === void 0 ? [] : _ref$fullforms,
_ref$exponent = _ref.exponent,
exponent = _ref$exponent === void 0 ? -1 : _ref$exponent,
_ref$roundingMethod = _ref.roundingMethod,
roundingMethod = _ref$roundingMethod === void 0 ? ROUND : _ref$roundingMethod,
_ref$precision = _ref.precision,
precision = _ref$precision === void 0 ? 0 : _ref$precision;
if (isNaN(arg)) {
throw new TypeError("Invalid number");
}
var e = exponent,
num = Number(arg),
result = [],
val = 0,
u = EMPTY; // Sync base & standard
if (typeof roundingFunc !== "function") {
throw new TypeError("Invalid rounding method");
} // Flipping a negative number to determine the size
if (base === -1 && standard.length === 0) {
base = 10;
standard = JEDEC;
} else if (base === -1 && standard.length > 0) {
standard = standard === IEC ? IEC : JEDEC;
base = standard === IEC ? 2 : 10;
} else {
base = base === 2 ? 2 : 10;
standard = base === 10 ? JEDEC : IEC;
}
var ceil = base === 10 ? 1000 : 1024,
full = fullform === true,
neg = num < 0,
roundingFunc = Math[roundingMethod];
if (neg) {
num = -num;
} // Determining the exponent
if (isNaN(arg)) {
throw new TypeError(INVALID_NUMBER);
}
if (_typeof(roundingFunc) !== FUNCTION) {
throw new TypeError(INVALID_ROUND);
} // Flipping a negative number to determine the size
if (e === -1 || isNaN(e)) {
e = Math.floor(Math.log(num) / Math.log(ceil));
if (e < 0) {
e = 0;
}
} // Exceeding supported length, time to reduce & multiply
if (neg) {
num = -num;
} // Determining the exponent
if (e > 8) {
if (precision > 0) {
precision += 8 - e;
}
if (e === -1 || isNaN(e)) {
e = Math.floor(Math.log(num) / Math.log(ceil));
e = 8;
}
if (e < 0) {
e = 0;
}
} // Exceeding supported length, time to reduce & multiply
if (output === "exponent") {
return e;
} // Zero is now a special case because bytes divide by 1
if (e > 8) {
if (precision > 0) {
precision += 8 - e;
}
if (num === 0) {
result[0] = 0;
u = result[1] = strings.symbol[standard][bits ? "bits" : "bytes"][e];
} else {
val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));
e = 8;
}
if (bits) {
val = val * 8;
if (output === EXPONENT) {
return e;
} // Zero is now a special case because bytes divide by 1
if (val >= ceil && e < 8) {
val = val / ceil;
e++;
}
}
var p = Math.pow(10, e > 0 ? round : 0);
result[0] = roundingFunc(val * p) / p;
if (num === 0) {
result[0] = 0;
u = result[1] = strings.symbol[standard][bits ? BITS : BYTES][e];
} else {
val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));
if (result[0] === ceil && e < 8 && exponent === -1) {
result[0] = 1;
e++;
}
if (bits) {
val = val * 8;
u = result[1] = strings.symbol[standard][bits ? "bits" : "bytes"][e];
} // Decorating a 'diff'
if (val >= ceil && e < 8) {
val = val / ceil;
e++;
}
}
var p = Math.pow(10, e > 0 ? round : 0);
result[0] = roundingFunc(val * p) / p;
if (neg) {
result[0] = -result[0];
} // Setting optional precision
if (result[0] === ceil && e < 8 && exponent === -1) {
result[0] = 1;
e++;
}
u = result[1] = base === 10 && e === 1 ? bits ? SI_KBIT : SI_KBYTE : strings.symbol[standard][bits ? BITS : BYTES][e];
} // Decorating a 'diff'
if (precision > 0) {
result[0] = result[0].toPrecision(precision);
} // Applying custom symbol
if (neg) {
result[0] = -result[0];
} // Setting optional precision
result[1] = symbols[result[1]] || result[1];
if (locale === true) {
result[0] = result[0].toLocaleString();
} else if (locale.length > 0) {
result[0] = result[0].toLocaleString(locale, localeOptions);
} else if (separator.length > 0) {
result[0] = result[0].toString().replace(".", separator);
}
if (precision > 0) {
result[0] = result[0].toPrecision(precision);
} // Applying custom symbol
if (pad && Number.isInteger(result[0]) === false && round > 0) {
var x = separator || ".",
tmp = result[0].toString().split(x),
s = tmp[1] || "",
l = s.length,
n = round - l;
result[0] = "".concat(tmp[0]).concat(x).concat(s.padEnd(l + n, "0"));
}
if (full) {
result[1] = fullforms[e] ? fullforms[e] : strings.fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
} // Returning Array, Object, or String (default)
result[1] = symbols[result[1]] || result[1];
if (locale === true) {
result[0] = result[0].toLocaleString();
} else if (locale.length > 0) {
result[0] = result[0].toLocaleString(locale, localeOptions);
} else if (separator.length > 0) {
result[0] = result[0].toString().replace(PERIOD, separator);
}
return output === "array" ? result : output === "object" ? {
value: result[0],
symbol: result[1],
exponent: e,
unit: u
} : result.join(spacer);
} // Partial application for functional programming
if (pad && Number.isInteger(result[0]) === false && round > 0) {
var x = separator || PERIOD,
tmp = result[0].toString().split(x),
s = tmp[1] || EMPTY,
l = s.length,
n = round - l;
result[0] = "".concat(tmp[0]).concat(x).concat(s.padEnd(l + n, ZERO));
}
if (full) {
result[1] = fullforms[e] ? fullforms[e] : strings.fullform[standard][e] + (bits ? BIT : BYTE) + (result[0] === 1 ? EMPTY : S);
} // Returning Array, Object, or String (default)
filesize.partial = function (opt) {
return function (arg) {
return filesize(arg, opt);
};
};
return filesize;
return output === ARRAY ? result : output === OBJECT ? {
value: result[0],
symbol: result[1],
exponent: e,
unit: u
} : result.join(spacer);
} // Partial application for functional programming
filesize.partial = function (opt) {
return function (arg) {
return filesize(arg, opt);
};
};
return filesize;
}));
/*!
2022 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 9.0.8
@version 9.0.9
*/
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(i="undefined"!=typeof globalThis?globalThis:i||self).filesize=t()}(this,(function(){"use strict";var i={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 t(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=e.bits,n=void 0!==o&&o,r=e.pad,b=void 0!==r&&r,a=e.base,d=void 0===a?-1:a,l=e.round,s=void 0===l?2:l,c=e.locale,f=void 0===c?"":c,u=e.localeOptions,p=void 0===u?{}:u,v=e.separator,g=void 0===v?"":v,h=e.spacer,y=void 0===h?" ":h,m=e.symbols,B=void 0===m?{}:m,M=e.standard,T=void 0===M?"":M,j=e.output,w=void 0===j?"string":j,x=e.fullform,E=void 0!==x&&x,N=e.fullforms,P=void 0===N?[]:N,G=e.exponent,K=void 0===G?-1:G,S=e.roundingMethod,Y=void 0===S?"round":S,Z=e.precision,z=void 0===Z?0:Z,I=K,k=Number(t),L=[],O=0,q="";-1===d&&0===T.length?(d=10,T="iec"):-1===d&&T.length>0?d="iec"===(T="iec"===T?"iec":"jedec")?10:2:T=10===(d=2===d?2:10)?"iec":"jedec";var A=10===d?1e3:1024,C=!0===E,D=k<0,F=Math[Y];if(isNaN(t))throw new TypeError("Invalid number");if("function"!=typeof F)throw new TypeError("Invalid rounding method");if(D&&(k=-k),(-1===I||isNaN(I))&&(I=Math.floor(Math.log(k)/Math.log(A)))<0&&(I=0),I>8&&(z>0&&(z+=8-I),I=8),"exponent"===w)return I;if(0===k)L[0]=0,q=L[1]=i.symbol[T][n?"bits":"bytes"][I];else{O=k/(2===d?Math.pow(2,10*I):Math.pow(1e3,I)),n&&(O*=8)>=A&&I<8&&(O/=A,I++);var H=Math.pow(10,I>0?s:0);L[0]=F(O*H)/H,L[0]===A&&I<8&&-1===K&&(L[0]=1,I++),q=L[1]=i.symbol[T][n?"bits":"bytes"][I]}if(D&&(L[0]=-L[0]),z>0&&(L[0]=L[0].toPrecision(z)),L[1]=B[L[1]]||L[1],!0===f?L[0]=L[0].toLocaleString():f.length>0?L[0]=L[0].toLocaleString(f,p):g.length>0&&(L[0]=L[0].toString().replace(".",g)),b&&!1===Number.isInteger(L[0])&&s>0){var J=g||".",Q=L[0].toString().split(J),R=Q[1]||"",U=R.length,V=s-U;L[0]="".concat(Q[0]).concat(J).concat(R.padEnd(U+V,"0"))}return C&&(L[1]=P[I]?P[I]:i.fullform[T][I]+(n?"bit":"byte")+(1===L[0]?"":"s")),"array"===w?L:"object"===w?{value:L[0],symbol:L[1],exponent:I,unit:q}:L.join(y)}return t.partial=function(i){return function(e){return t(e,i)}},t}));
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(i="undefined"!=typeof globalThis?globalThis:i||self).filesize=t()}(this,(function(){"use strict";function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(i){return typeof i}:function(i){return i&&"function"==typeof Symbol&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},i(t)}var t="array",o="bits",e="byte",n="bytes",r="",b="exponent",l="function",a="iec",d="Invalid number",f="Invalid rounding method",u="jedec",s="object",c=".",p="round",y="kbit",m="string",v={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 g(g){var h=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},B=h.bits,M=void 0!==B&&B,S=h.pad,T=void 0!==S&&S,w=h.base,x=void 0===w?-1:w,E=h.round,j=void 0===E?2:E,N=h.locale,P=void 0===N?r:N,k=h.localeOptions,G=void 0===k?{}:k,K=h.separator,Y=void 0===K?r:K,Z=h.spacer,z=void 0===Z?" ":Z,I=h.symbols,L=void 0===I?{}:I,O=h.standard,q=void 0===O?r:O,A=h.output,C=void 0===A?m:A,D=h.fullform,F=void 0!==D&&D,H=h.fullforms,J=void 0===H?[]:H,Q=h.exponent,R=void 0===Q?-1:Q,U=h.roundingMethod,V=void 0===U?p:U,W=h.precision,X=void 0===W?0:W,$=R,_=Number(g),ii=[],ti=0,oi=r;-1===x&&0===q.length?(x=10,q=u):-1===x&&q.length>0?x=(q=q===a?a:u)===a?2:10:q=10===(x=2===x?2:10)?u:a;var ei=10===x?1e3:1024,ni=!0===F,ri=_<0,bi=Math[V];if(isNaN(g))throw new TypeError(d);if(i(bi)!==l)throw new TypeError(f);if(ri&&(_=-_),(-1===$||isNaN($))&&($=Math.floor(Math.log(_)/Math.log(ei)))<0&&($=0),$>8&&(X>0&&(X+=8-$),$=8),C===b)return $;if(0===_)ii[0]=0,oi=ii[1]=v.symbol[q][M?o:n][$];else{ti=_/(2===x?Math.pow(2,10*$):Math.pow(1e3,$)),M&&(ti*=8)>=ei&&$<8&&(ti/=ei,$++);var li=Math.pow(10,$>0?j:0);ii[0]=bi(ti*li)/li,ii[0]===ei&&$<8&&-1===R&&(ii[0]=1,$++),oi=ii[1]=10===x&&1===$?M?y:"kB":v.symbol[q][M?o:n][$]}if(ri&&(ii[0]=-ii[0]),X>0&&(ii[0]=ii[0].toPrecision(X)),ii[1]=L[ii[1]]||ii[1],!0===P?ii[0]=ii[0].toLocaleString():P.length>0?ii[0]=ii[0].toLocaleString(P,G):Y.length>0&&(ii[0]=ii[0].toString().replace(c,Y)),T&&!1===Number.isInteger(ii[0])&&j>0){var ai=Y||c,di=ii[0].toString().split(ai),fi=di[1]||r,ui=fi.length,si=j-ui;ii[0]="".concat(di[0]).concat(ai).concat(fi.padEnd(ui+si,"0"))}return ni&&(ii[1]=J[$]?J[$]:v.fullform[q][$]+(M?"bit":e)+(1===ii[0]?r:"s")),C===t?ii:C===s?{value:ii[0],symbol:ii[1],exponent:$,unit:oi}:ii.join(z)}return g.partial=function(i){return function(t){return g(t,i)}},g}));
//# sourceMappingURL=filesize.min.js.map
{
"name": "filesize",
"description": "JavaScript library to generate a human readable String describing the file size",
"version": "9.0.8",
"version": "9.0.9",
"homepage": "https://filesizejs.com",

@@ -6,0 +6,0 @@ "author": "Jason Mulligan <jason.mulligan@avoidwork.com>",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc