Comparing version 3.2.1 to 3.3.0
@@ -6,3 +6,3 @@ /** | ||
* @license BSD-3-Clause | ||
* @version 3.2.1 | ||
* @version 3.3.0 | ||
*/ | ||
@@ -12,4 +12,10 @@ (function (global) { | ||
const symbol = { | ||
bits: ["b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"], | ||
bytes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] | ||
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"] | ||
} | ||
}; | ||
@@ -28,3 +34,3 @@ | ||
val = 0, | ||
e, base, bits, ceil, neg, num, output, round, unix, spacer, symbols; | ||
e, base, bits, ceil, neg, num, output, round, unix, spacer, standard, symbols; | ||
@@ -41,2 +47,3 @@ if (isNaN(arg)) { | ||
symbols = descriptor.symbols || descriptor.suffixes || {}; | ||
standard = base === 2 ? descriptor.standard || "jedec" : "jedec"; | ||
output = descriptor.output || "string"; | ||
@@ -84,6 +91,6 @@ e = descriptor.exponent !== undefined ? descriptor.exponent : -1; | ||
result[0] = Number(val.toFixed(e > 0 ? round : 0)); | ||
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[bits ? "bits" : "bytes"][e]; | ||
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e]; | ||
if (unix) { | ||
result[1] = result[1].charAt(0); | ||
result[1] = standard === "jedec" ? result[1].charAt(0) : e > 0 ? result[1].replace(/B$/, "") : result[1]; | ||
@@ -102,3 +109,3 @@ if (b.test(result[1])) { | ||
// Applying custom suffix | ||
// Applying custom symbol | ||
result[1] = symbols[result[1]] || result[1]; | ||
@@ -105,0 +112,0 @@ |
@@ -8,3 +8,3 @@ "use strict"; | ||
* @license BSD-3-Clause | ||
* @version 3.2.1 | ||
* @version 3.3.0 | ||
*/ | ||
@@ -14,4 +14,10 @@ (function (global) { | ||
var symbol = { | ||
bits: ["b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"], | ||
bytes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] | ||
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"] | ||
} | ||
}; | ||
@@ -32,13 +38,14 @@ | ||
val = 0, | ||
e = undefined, | ||
base = undefined, | ||
bits = undefined, | ||
ceil = undefined, | ||
neg = undefined, | ||
num = undefined, | ||
output = undefined, | ||
round = undefined, | ||
unix = undefined, | ||
spacer = undefined, | ||
symbols = undefined; | ||
e = void 0, | ||
base = void 0, | ||
bits = void 0, | ||
ceil = void 0, | ||
neg = void 0, | ||
num = void 0, | ||
output = void 0, | ||
round = void 0, | ||
unix = void 0, | ||
spacer = void 0, | ||
standard = void 0, | ||
symbols = void 0; | ||
@@ -55,2 +62,3 @@ if (isNaN(arg)) { | ||
symbols = descriptor.symbols || descriptor.suffixes || {}; | ||
standard = base === 2 ? descriptor.standard || "jedec" : "jedec"; | ||
output = descriptor.output || "string"; | ||
@@ -98,6 +106,6 @@ e = descriptor.exponent !== undefined ? descriptor.exponent : -1; | ||
result[0] = Number(val.toFixed(e > 0 ? round : 0)); | ||
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[bits ? "bits" : "bytes"][e]; | ||
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e]; | ||
if (unix) { | ||
result[1] = result[1].charAt(0); | ||
result[1] = standard === "jedec" ? result[1].charAt(0) : e > 0 ? result[1].replace(/B$/, "") : result[1]; | ||
@@ -116,3 +124,3 @@ if (b.test(result[1])) { | ||
// Applying custom suffix | ||
// Applying custom symbol | ||
result[1] = symbols[result[1]] || result[1]; | ||
@@ -119,0 +127,0 @@ |
{ | ||
"name": "filesize", | ||
"description": "JavaScript library to generate a human readable String describing the file size", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"homepage": "http://filesizejs.com", | ||
@@ -6,0 +6,0 @@ "author": "Jason Mulligan <jason.mulligan@avoidwork.com>", |
@@ -29,2 +29,5 @@ # filesize.js | ||
### standard | ||
_***(string)***_ Standard unit of measure, can be `iec` or `jedec`, default is `jedec`; can be overruled by `base` | ||
### symbols | ||
@@ -53,2 +56,3 @@ _***(object)***_ Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found | ||
filesize(1024, {output: "exponent"}); // 1 | ||
filesize(265318, {standard: "iec"}); // "259.1 KiB" | ||
``` | ||
@@ -55,0 +59,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13212
280
64