Socket
Socket
Sign inDemoInstall

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 10.0.12 to 10.1.0

16

dist/filesize.esm.js

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

* @license BSD-3-Clause
* @version 10.0.12
* @version 10.1.0
*/

@@ -25,2 +25,3 @@ const ARRAY = "array";

const S = "s";
const SI = "si";
const SI_KBIT = "kbit";

@@ -71,11 +72,12 @@ const SI_KBYTE = "kB";

// Sync base & standard
if (base === -1 && standard.length === 0) {
if (standard === SI) {
base = 10;
standard = JEDEC;
} else if (base === -1 && standard.length > 0) {
standard = standard === IEC ? IEC : JEDEC;
base = standard === IEC ? 2 : 10;
} else if (standard === IEC || standard === JEDEC) {
base = 2;
} else if (base === 2) {
standard = IEC;
} else {
base = base === 2 ? 2 : 10;
standard = base === 10 ? JEDEC : standard === JEDEC ? JEDEC : IEC;
base = 10;
standard = JEDEC;
}

@@ -82,0 +84,0 @@

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

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

* @license BSD-3-Clause
* @version 10.0.12
* @version 10.1.0
*/

@@ -25,2 +25,3 @@ (function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.filesize={}));})(this,(function(exports){'use strict';const ARRAY = "array";

const S = "s";
const SI = "si";
const SI_KBIT = "kbit";

@@ -71,11 +72,12 @@ const SI_KBYTE = "kB";

// Sync base & standard
if (base === -1 && standard.length === 0) {
if (standard === SI) {
base = 10;
standard = JEDEC;
} else if (base === -1 && standard.length > 0) {
standard = standard === IEC ? IEC : JEDEC;
base = standard === IEC ? 2 : 10;
} else if (standard === IEC || standard === JEDEC) {
base = 2;
} else if (base === 2) {
standard = IEC;
} else {
base = base === 2 ? 2 : 10;
standard = base === 10 ? JEDEC : standard === JEDEC ? JEDEC : IEC;
base = 10;
standard = JEDEC;
}

@@ -82,0 +84,0 @@

/*!
2023 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 10.0.12
@version 10.1.0
*/
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,(function(t){"use strict";const i="array",e="bit",o="bits",n="byte",r="bytes",s="",l="exponent",a="function",b="iec",p="Invalid number",f="Invalid rounding method",u="jedec",d="object",c=".",g="round",m="s",y="kbit",h="kB",B=" ",M="string",x="0",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 w(t,{bits:w=!1,pad:E=!1,base:j=-1,round:N=2,locale:P=s,localeOptions:k={},separator:z=s,spacer:G=B,symbols:K={},standard:S=s,output:Y=M,fullform:Z=!1,fullforms:v=[],exponent:I=-1,roundingMethod:O=g,precision:$=0}={}){let L=I,q=Number(t),A=[],C=0,D=s;-1===j&&0===S.length?(j=10,S=u):-1===j&&S.length>0?j=(S=S===b?b:u)===b?2:10:S=10===(j=2===j?2:10)||S===u?u:b;const F=10===j?1e3:1024,H=!0===Z,J=q<0,Q=Math[O];if("bigint"!=typeof t&&isNaN(t))throw new TypeError(p);if(typeof Q!==a)throw new TypeError(f);if(J&&(q=-q),(-1===L||isNaN(L))&&(L=Math.floor(Math.log(q)/Math.log(F)),L<0&&(L=0)),L>8&&($>0&&($+=8-L),L=8),Y===l)return L;if(0===q)A[0]=0,D=A[1]=T.symbol[S][w?o:r][L];else{C=q/(2===j?Math.pow(2,10*L):Math.pow(1e3,L)),w&&(C*=8,C>=F&&L<8&&(C/=F,L++));const t=Math.pow(10,L>0?N:0);A[0]=Q(C*t)/t,A[0]===F&&L<8&&-1===I&&(A[0]=1,L++),D=A[1]=10===j&&1===L?w?y:h:T.symbol[S][w?o:r][L]}if(J&&(A[0]=-A[0]),$>0&&(A[0]=A[0].toPrecision($)),A[1]=K[A[1]]||A[1],!0===P?A[0]=A[0].toLocaleString():P.length>0?A[0]=A[0].toLocaleString(P,k):z.length>0&&(A[0]=A[0].toString().replace(c,z)),E&&!1===Number.isInteger(A[0])&&N>0){const t=z||c,i=A[0].toString().split(t),e=i[1]||s,o=e.length,n=N-o;A[0]=`${i[0]}${t}${e.padEnd(o+n,x)}`}return H&&(A[1]=v[L]?v[L]:T.fullform[S][L]+(w?e:n)+(1===A[0]?s:m)),Y===i?A:Y===d?{value:A[0],symbol:A[1],exponent:L,unit:D}:A.join(G)}t.filesize=w,t.partial=function({bits:t=!1,pad:i=!1,base:e=-1,round:o=2,locale:n=s,localeOptions:r={},separator:l=s,spacer:a=B,symbols:b={},standard:p=s,output:f=M,fullform:u=!1,fullforms:d=[],exponent:c=-1,roundingMethod:m=g,precision:y=0}={}){return s=>w(s,{bits:t,pad:i,base:e,round:o,locale:n,localeOptions:r,separator:l,spacer:a,symbols:b,standard:p,output:f,fullform:u,fullforms:d,exponent:c,roundingMethod:m,precision:y})}}));//# sourceMappingURL=filesize.min.js.map
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).filesize={})}(this,(function(t){"use strict";const i="array",e="bit",o="bits",n="byte",r="bytes",s="",l="exponent",a="function",b="iec",p="Invalid number",f="Invalid rounding method",u="jedec",d="object",c=".",m="round",g="s",y="si",h="kbit",B="kB",M=" ",x="string",T="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(t,{bits:E=!1,pad:j=!1,base:N=-1,round:P=2,locale:k=s,localeOptions:z={},separator:G=s,spacer:K=M,symbols:S={},standard:Y=s,output:Z=x,fullform:v=!1,fullforms:I=[],exponent:O=-1,roundingMethod:$=m,precision:L=0}={}){let q=O,A=Number(t),C=[],D=0,F=s;Y===y?(N=10,Y=u):Y===b||Y===u?N=2:2===N?Y=b:(N=10,Y=u);const H=10===N?1e3:1024,J=!0===v,Q=A<0,R=Math[$];if("bigint"!=typeof t&&isNaN(t))throw new TypeError(p);if(typeof R!==a)throw new TypeError(f);if(Q&&(A=-A),(-1===q||isNaN(q))&&(q=Math.floor(Math.log(A)/Math.log(H)),q<0&&(q=0)),q>8&&(L>0&&(L+=8-q),q=8),Z===l)return q;if(0===A)C[0]=0,F=C[1]=w.symbol[Y][E?o:r][q];else{D=A/(2===N?Math.pow(2,10*q):Math.pow(1e3,q)),E&&(D*=8,D>=H&&q<8&&(D/=H,q++));const t=Math.pow(10,q>0?P:0);C[0]=R(D*t)/t,C[0]===H&&q<8&&-1===O&&(C[0]=1,q++),F=C[1]=10===N&&1===q?E?h:B:w.symbol[Y][E?o:r][q]}if(Q&&(C[0]=-C[0]),L>0&&(C[0]=C[0].toPrecision(L)),C[1]=S[C[1]]||C[1],!0===k?C[0]=C[0].toLocaleString():k.length>0?C[0]=C[0].toLocaleString(k,z):G.length>0&&(C[0]=C[0].toString().replace(c,G)),j&&!1===Number.isInteger(C[0])&&P>0){const t=G||c,i=C[0].toString().split(t),e=i[1]||s,o=e.length,n=P-o;C[0]=`${i[0]}${t}${e.padEnd(o+n,T)}`}return J&&(C[1]=I[q]?I[q]:w.fullform[Y][q]+(E?e:n)+(1===C[0]?s:g)),Z===i?C:Z===d?{value:C[0],symbol:C[1],exponent:q,unit:F}:C.join(K)}t.filesize=E,t.partial=function({bits:t=!1,pad:i=!1,base:e=-1,round:o=2,locale:n=s,localeOptions:r={},separator:l=s,spacer:a=M,symbols:b={},standard:p=s,output:f=x,fullform:u=!1,fullforms:d=[],exponent:c=-1,roundingMethod:g=m,precision:y=0}={}){return s=>E(s,{bits:t,pad:i,base:e,round:o,locale:n,localeOptions:r,separator:l,spacer:a,symbols:b,standard:p,output:f,fullform:u,fullforms:d,exponent:c,roundingMethod:g,precision:y})}}));//# sourceMappingURL=filesize.min.js.map
{
"name": "filesize",
"description": "JavaScript library to generate a human readable String describing the file size",
"version": "10.0.12",
"version": "10.1.0",
"homepage": "https://filesizejs.com",

@@ -32,7 +32,8 @@ "author": "Jason Mulligan <jason.mulligan@avoidwork.com>",

"lint": "eslint *.js src/*.js test/*.js",
"mocha": "mocha test/*.js",
"mocha": "nyc mocha test/*.js",
"rollup": "rollup --config",
"test": "npm run lint && npm run mocha",
"test-webpack": "mkdir -p test/webpack && rm -rf test/webpack/* && git clone git@github.com:rabelais88/typescript-webpack.git test/webpack && echo \"import { filesize } from 'filesize';console.log(filesize(1234));\" >> test/webpack/src/index.ts && cd test/webpack && npm install && mkdir -p node_modules/filesize/dist && cp ../../package.json node_modules/filesize/ && cp ../../dist/* node_modules/filesize/dist/ && npm run build",
"types": "npx -p typescript tsc src/*.js --declaration --allowJs --emitDeclarationOnly --outDir types"
"types": "npx -p typescript tsc src/*.js --declaration --allowJs --emitDeclarationOnly --outDir types",
"prepare": "husky install"
},

@@ -43,3 +44,5 @@ "devDependencies": {

"eslint": "^8.37.0",
"husky": "^8.0.3",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"rollup": "^3.20.2",

@@ -46,0 +49,0 @@ "typescript": "^5.0.2"

@@ -5,9 +5,22 @@ # filesize.js

filesize.js provides a simple way to get a human readable file size string from a number (float or integer) or string.
filesize.js provides a simple way to get a human-readable file size string from a number (float or integer) or string.
```javascript
import {filesize} from "filesize";
filesize(265318, {base: 2, standard: "jedec"}); // "259.1 KB"
filesize(265318, {standard: "jedec"}); // "259.1 KB"
```
## Testing
filesize has 100% code coverage with its tests.
```console
--------------|---------|----------|---------|---------|-----------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------|---------|----------|---------|---------|-----------------------
All files | 100 | 95.52 | 100 | 100 |
filesize.cjs | 100 | 95.52 | 100 | 100 | 77-78,173,196,199,210
--------------|---------|----------|---------|---------|-----------------------
```
## Optional settings

@@ -60,8 +73,29 @@

### standard
_*(string)*_ Standard unit of measure, can be `iec` or `jedec`, default is `iec`; can be overruled by `base`
_*(string)*_ Standard unit of measure, can be `iec`, `jedec`, or `si`. Default is `si` (base 10). The `si` option is an alias of `jedec`, such that it is not valid for other configuration options.
### symbols
_*(object)*_ Dictionary of IEC/JEDEC symbols to replace for localization, defaults to english if no match is found
_*(object)*_ Dictionary of IEC/JEDEC symbols to replace for localization, defaults to english if no match is found; SI is handled automatically with JEDEC values.
## Examples
```javascript
filesize(500); // "500 B"
filesize(500, {bits: true}); // "4 kbit"
filesize(265318, {base: 2}); // "259.1 KiB"
filesize(265318); // "265.32 kB"
filesize(265318, {round: 0}); // "265 kB"
filesize(265318, {output: "array"}); // [265.32, "kB"]
filesize(265318, {output: "object"}); // {value: 265.32, symbol: "kB", exponent: 1, unit: "kB"}
filesize(1, {symbols: {B: "Б"}}); // "1 Б"
filesize(1024); // "1.02 kB"
filesize(1024, {exponent: 0}); // "1024 B"
filesize(1024, {output: "exponent"}); // 1
filesize(265318, {standard: "jedec"}); // "259.1 KB"
filesize(265318, {base: 2, fullform: true}); // "259.1 kibibytes"
filesize(12, {fullform: true, fullforms: ["байтов"]}); // "12 байтов"
filesize(265318, {separator: ","}); // "265,32 kB"
filesize(265318, {locale: "de"}); // "265,32 kB"
```
## Partial Application

@@ -74,3 +108,3 @@ `partial()` takes the second parameter of `filesize()` and returns a new function with the configuration applied

import {partial} from "filesize";
const size = partial({base: 2, standard: "jedec"});
const size = partial({standard: "jedec"});

@@ -77,0 +111,0 @@ size(265318); // "259.1 KB"

@@ -17,2 +17,3 @@ export const ARRAY: "array";

export const S: "s";
export const SI: "si";
export const SI_KBIT: "kbit";

@@ -19,0 +20,0 @@ export const SI_KBYTE: "kB";

interface FileSizeOptionsBase {
base?: number;
base?: 10 | 2;
bits?: boolean;

@@ -15,13 +15,4 @@ exponent?: number;

spacer?: string;
standard?: 'iec' | 'jedec';
symbols?: {
iec: {
bits: string[],
bytes: string[]
},
jedec: {
bits: string[],
bytes: string[]
}
};
standard?: 'si' | 'iec' | 'jedec';
symbols?: {};
}

@@ -28,0 +19,0 @@

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