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 6.2.0 to 6.2.1

10

CHANGELOG.md

@@ -7,2 +7,12 @@ ### Changelog

#### [6.2.1](https://github.com//avoidwork/filesize.js.git/compare/6.2.0...6.2.1)
> 13 April 2021
- Adding `unit` to `object` output [`#129`](https://github.com//avoidwork/filesize.js.git/pull/129)
- Fixing `array` output such that `fullform` is a potential output [`#128`](https://github.com//avoidwork/filesize.js.git/pull/128)
- Adding `pad` optional setting to pad the ending of decimal place [`#127`](https://github.com//avoidwork/filesize.js.git/pull/127)
- Adding `pad` optional setting to pad the ending of decimal place, fixes #117 [`#117`](https://github.com//avoidwork/filesize.js.git/issues/117)
- Version bump to release [`98a59b1`](https://github.com//avoidwork/filesize.js.git/commit/98a59b1187a1ad4a417f68366eb2615800dfa9c6)
#### [6.2.0](https://github.com//avoidwork/filesize.js.git/compare/6.1.0...6.2.0)

@@ -9,0 +19,0 @@

23

lib/filesize.es6.js

@@ -41,3 +41,3 @@ /**

val = 0,
e, base, bits, ceil, full, fullforms, locale, localeOptions, neg, num, output, round, unix, separator, spacer, standard, symbols;
e, base, bits, ceil, full, fullforms, locale, localeOptions, neg, num, output, pad, round, u, unix, separator, spacer, standard, symbols;

@@ -50,2 +50,3 @@ if (isNaN(arg)) {

unix = descriptor.unix === true;
pad = descriptor.pad === true;
base = descriptor.base || 2;

@@ -113,3 +114,3 @@ round = descriptor.round !== void 0 ? descriptor.round : unix ? 1 : 2;

result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];
u = result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];

@@ -142,2 +143,6 @@ if (unix) {

if (full) {
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
}
// Returning Array, Object, or String (default)

@@ -148,8 +153,14 @@ if (output === "array") {

if (full) {
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
if (output === "object") {
return {value: result[0], symbol: result[1], exponent: e, unit: u};
}
if (output === "object") {
return {value: result[0], symbol: result[1], exponent: e};
if (pad && Number.isInteger(result[0]) === false && round > 0) {
const x = separator || ".",
tmp = result[0].toString().split(x),
s = tmp[1] || "",
l = s.length,
n = round - l;
result[0] = `${tmp[0]}${x}${s.padEnd(l + n, "0")}`;
}

@@ -156,0 +167,0 @@

@@ -5,3 +5,3 @@ /*!

*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).filesize=t()}(this,(function(){"use strict";const e=/^(b|B)$/,t={iec:{bits:["b","Kib","Mib","Gib","Tib","Pib","Eib","Zib","Yib"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["b","Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},i={iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]};function o(o,b={}){let n,a,r,s,l,c,d,p,f,u,B,y,m,g,h,x,M,v=[],j=0;if(isNaN(o))throw new TypeError("Invalid number");return r=!0===b.bits,m=!0===b.unix,a=b.base||2,y=void 0!==b.round?b.round:m?1:2,d=void 0!==b.locale?b.locale:"",p=b.localeOptions||{},g=void 0!==b.separator?b.separator:"",h=void 0!==b.spacer?b.spacer:m?"":" ",M=b.symbols||{},x=2===a&&b.standard||"jedec",B=b.output||"string",l=!0===b.fullform,c=b.fullforms instanceof Array?b.fullforms:[],n=void 0!==b.exponent?b.exponent:-1,u=Number(o),f=u<0,s=a>2?1e3:1024,f&&(u=-u),(-1===n||isNaN(n))&&(n=Math.floor(Math.log(u)/Math.log(s)),n<0&&(n=0)),n>8&&(n=8),"exponent"===B?n:(0===u?(v[0]=0,v[1]=m?"":t[x][r?"bits":"bytes"][n]):(j=u/(2===a?Math.pow(2,10*n):Math.pow(1e3,n)),r&&(j*=8,j>=s&&n<8&&(j/=s,n++)),v[0]=Number(j.toFixed(n>0?y:0)),v[0]===s&&n<8&&void 0===b.exponent&&(v[0]=1,n++),v[1]=10===a&&1===n?r?"kb":"kB":t[x][r?"bits":"bytes"][n],m&&(v[1]="jedec"===x?v[1].charAt(0):n>0?v[1].replace(/B$/,""):v[1],e.test(v[1])&&(v[0]=Math.floor(v[0]),v[1]=""))),f&&(v[0]=-v[0]),v[1]=M[v[1]]||v[1],!0===d?v[0]=v[0].toLocaleString():d.length>0?v[0]=v[0].toLocaleString(d,p):g.length>0&&(v[0]=v[0].toString().replace(".",g)),"array"===B?v:(l&&(v[1]=c[n]?c[n]:i[x][n]+(r?"bit":"byte")+(1===v[0]?"":"s")),"object"===B?{value:v[0],symbol:v[1],exponent:n}:v.join(h)))}return o.partial=e=>t=>o(t,e),o}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).filesize=t()}(this,(function(){"use strict";const e=/^(b|B)$/,t={iec:{bits:["b","Kib","Mib","Gib","Tib","Pib","Eib","Zib","Yib"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["b","Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},i={iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]};function o(o,n={}){let r,b,a,s,l,d,f,p,u,c,B,g,y,m,h,x,M,v,j,N=[],E=0;if(isNaN(o))throw new TypeError("Invalid number");if(a=!0===n.bits,h=!0===n.unix,g=!0===n.pad,b=n.base||2,y=void 0!==n.round?n.round:h?1:2,f=void 0!==n.locale?n.locale:"",p=n.localeOptions||{},x=void 0!==n.separator?n.separator:"",M=void 0!==n.spacer?n.spacer:h?"":" ",j=n.symbols||{},v=2===b&&n.standard||"jedec",B=n.output||"string",l=!0===n.fullform,d=n.fullforms instanceof Array?n.fullforms:[],r=void 0!==n.exponent?n.exponent:-1,c=Number(o),u=c<0,s=b>2?1e3:1024,u&&(c=-c),(-1===r||isNaN(r))&&(r=Math.floor(Math.log(c)/Math.log(s)),r<0&&(r=0)),r>8&&(r=8),"exponent"===B)return r;if(0===c?(N[0]=0,N[1]=h?"":t[v][a?"bits":"bytes"][r]):(E=c/(2===b?Math.pow(2,10*r):Math.pow(1e3,r)),a&&(E*=8,E>=s&&r<8&&(E/=s,r++)),N[0]=Number(E.toFixed(r>0?y:0)),N[0]===s&&r<8&&void 0===n.exponent&&(N[0]=1,r++),m=N[1]=10===b&&1===r?a?"kb":"kB":t[v][a?"bits":"bytes"][r],h&&(N[1]="jedec"===v?N[1].charAt(0):r>0?N[1].replace(/B$/,""):N[1],e.test(N[1])&&(N[0]=Math.floor(N[0]),N[1]=""))),u&&(N[0]=-N[0]),N[1]=j[N[1]]||N[1],!0===f?N[0]=N[0].toLocaleString():f.length>0?N[0]=N[0].toLocaleString(f,p):x.length>0&&(N[0]=N[0].toString().replace(".",x)),l&&(N[1]=d[r]?d[r]:i[v][r]+(a?"bit":"byte")+(1===N[0]?"":"s")),"array"===B)return N;if("object"===B)return{value:N[0],symbol:N[1],exponent:r,unit:m};if(g&&!1===Number.isInteger(N[0])&&y>0){const e=x||".",t=N[0].toString().split(e),i=t[1]||"",o=i.length,n=y-o;N[0]=`${t[0]}${e}${i.padEnd(o+n,"0")}`}return N.join(M)}return o.partial=e=>t=>o(t,e),o}));
//# sourceMappingURL=filesize.es6.min.js.map

@@ -53,3 +53,5 @@ /**

output,
pad,
round,
u,
unix,

@@ -67,2 +69,3 @@ separator,

unix = descriptor.unix === true;
pad = descriptor.pad === true;
base = descriptor.base || 2;

@@ -129,3 +132,3 @@ round = descriptor.round !== void 0 ? descriptor.round : unix ? 1 : 2;

result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];
u = result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];

@@ -156,2 +159,6 @@ if (unix) {

result[0] = result[0].toString().replace(".", separator);
}
if (full) {
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
} // Returning Array, Object, or String (default)

@@ -164,6 +171,2 @@

if (full) {
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
}
if (output === "object") {

@@ -173,6 +176,16 @@ return {

symbol: result[1],
exponent: e
exponent: e,
unit: u
};
}
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"));
}
return result.join(spacer);

@@ -179,0 +192,0 @@ } // Partial application for functional programming

@@ -5,3 +5,3 @@ /*!

*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).filesize=t()}(this,(function(){"use strict";var e=/^(b|B)$/,t={iec:{bits:["b","Kib","Mib","Gib","Tib","Pib","Eib","Zib","Yib"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["b","Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},i={iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]};function o(o){var n,b,r,a,s,l,c,u,d,f,p,B,y,g,m,h,v,x=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},M=[],j=0;if(isNaN(o))throw new TypeError("Invalid number");return r=!0===x.bits,y=!0===x.unix,b=x.base||2,B=void 0!==x.round?x.round:y?1:2,c=void 0!==x.locale?x.locale:"",u=x.localeOptions||{},g=void 0!==x.separator?x.separator:"",m=void 0!==x.spacer?x.spacer:y?"":" ",v=x.symbols||{},h=2===b&&x.standard||"jedec",p=x.output||"string",s=!0===x.fullform,l=x.fullforms instanceof Array?x.fullforms:[],n=void 0!==x.exponent?x.exponent:-1,a=b>2?1e3:1024,(d=(f=Number(o))<0)&&(f=-f),(-1===n||isNaN(n))&&(n=Math.floor(Math.log(f)/Math.log(a)))<0&&(n=0),n>8&&(n=8),"exponent"===p?n:(0===f?(M[0]=0,M[1]=y?"":t[h][r?"bits":"bytes"][n]):(j=f/(2===b?Math.pow(2,10*n):Math.pow(1e3,n)),r&&(j*=8)>=a&&n<8&&(j/=a,n++),M[0]=Number(j.toFixed(n>0?B:0)),M[0]===a&&n<8&&void 0===x.exponent&&(M[0]=1,n++),M[1]=10===b&&1===n?r?"kb":"kB":t[h][r?"bits":"bytes"][n],y&&(M[1]="jedec"===h?M[1].charAt(0):n>0?M[1].replace(/B$/,""):M[1],e.test(M[1])&&(M[0]=Math.floor(M[0]),M[1]=""))),d&&(M[0]=-M[0]),M[1]=v[M[1]]||M[1],!0===c?M[0]=M[0].toLocaleString():c.length>0?M[0]=M[0].toLocaleString(c,u):g.length>0&&(M[0]=M[0].toString().replace(".",g)),"array"===p?M:(s&&(M[1]=l[n]?l[n]:i[h][n]+(r?"bit":"byte")+(1===M[0]?"":"s")),"object"===p?{value:M[0],symbol:M[1],exponent:n}:M.join(m)))}return o.partial=function(e){return function(t){return o(t,e)}},o}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).filesize=t()}(this,(function(){"use strict";var e=/^(b|B)$/,t={iec:{bits:["b","Kib","Mib","Gib","Tib","Pib","Eib","Zib","Yib"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["b","Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},i={iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]};function o(o){var n,r,a,b,s,l,c,u,f,d,p,B,g,y,m,h,v,x,M,j=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},N=[],E=0;if(isNaN(o))throw new TypeError("Invalid number");if(a=!0===j.bits,m=!0===j.unix,B=!0===j.pad,r=j.base||2,g=void 0!==j.round?j.round:m?1:2,c=void 0!==j.locale?j.locale:"",u=j.localeOptions||{},h=void 0!==j.separator?j.separator:"",v=void 0!==j.spacer?j.spacer:m?"":" ",M=j.symbols||{},x=2===r&&j.standard||"jedec",p=j.output||"string",s=!0===j.fullform,l=j.fullforms instanceof Array?j.fullforms:[],n=void 0!==j.exponent?j.exponent:-1,b=r>2?1e3:1024,(f=(d=Number(o))<0)&&(d=-d),(-1===n||isNaN(n))&&(n=Math.floor(Math.log(d)/Math.log(b)))<0&&(n=0),n>8&&(n=8),"exponent"===p)return n;if(0===d?(N[0]=0,N[1]=m?"":t[x][a?"bits":"bytes"][n]):(E=d/(2===r?Math.pow(2,10*n):Math.pow(1e3,n)),a&&(E*=8)>=b&&n<8&&(E/=b,n++),N[0]=Number(E.toFixed(n>0?g:0)),N[0]===b&&n<8&&void 0===j.exponent&&(N[0]=1,n++),y=N[1]=10===r&&1===n?a?"kb":"kB":t[x][a?"bits":"bytes"][n],m&&(N[1]="jedec"===x?N[1].charAt(0):n>0?N[1].replace(/B$/,""):N[1],e.test(N[1])&&(N[0]=Math.floor(N[0]),N[1]=""))),f&&(N[0]=-N[0]),N[1]=M[N[1]]||N[1],!0===c?N[0]=N[0].toLocaleString():c.length>0?N[0]=N[0].toLocaleString(c,u):h.length>0&&(N[0]=N[0].toString().replace(".",h)),s&&(N[1]=l[n]?l[n]:i[x][n]+(a?"bit":"byte")+(1===N[0]?"":"s")),"array"===p)return N;if("object"===p)return{value:N[0],symbol:N[1],exponent:n,unit:y};if(B&&!1===Number.isInteger(N[0])&&g>0){var T=h||".",k=N[0].toString().split(T),w=k[1]||"",G=w.length,K=g-G;N[0]="".concat(k[0]).concat(T).concat(w.padEnd(G+K,"0"))}return N.join(v)}return o.partial=function(e){return function(t){return o(t,e)}},o}));
//# sourceMappingURL=filesize.min.js.map
{
"name": "filesize",
"description": "JavaScript library to generate a human readable String describing the file size",
"version": "6.2.0",
"version": "6.2.1",
"homepage": "https://filesizejs.com",

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

@@ -38,2 +38,5 @@ # filesize.js

### pad
_*(boolean)*_ Decimal place end padding, default is `false`
### separator

@@ -63,3 +66,3 @@ _*(string)*_ Decimal separator character, default is `.`

filesize(265318, {output: "array"}); // [259.1, "KB"]
filesize(265318, {output: "object"}); // {value: 259.1, symbol: "KB", exponent: 1}
filesize(265318, {output: "object"}); // {value: 259.1, symbol: "KB", exponent: 1, unit: "KB"}
filesize(1, {symbols: {B: "Б"}}); // "1 Б"

@@ -66,0 +69,0 @@ filesize(1024); // "1 KB"

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