Comparing version 3.1.6 to 3.2.0
@@ -6,7 +6,7 @@ /** | ||
* @license BSD-3-Clause | ||
* @version 3.1.6 | ||
* @version 3.2.0 | ||
*/ | ||
(function (global) { | ||
const b = /^(b|B)$/; | ||
const si = { | ||
const symbol = { | ||
bits: ["b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"], | ||
@@ -26,5 +26,4 @@ bytes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] | ||
let result = [], | ||
skip = false, | ||
val = 0, | ||
e, base, bits, ceil, neg, num, output, round, unix, spacer, suffixes; | ||
e, base, bits, ceil, neg, num, output, round, unix, spacer, symbols; | ||
@@ -37,7 +36,7 @@ if (isNaN(arg)) { | ||
unix = descriptor.unix === true; | ||
base = descriptor.base !== undefined ? descriptor.base : 2; | ||
base = descriptor.base || 2; | ||
round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2; | ||
spacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? "" : " "; | ||
suffixes = descriptor.suffixes !== undefined ? descriptor.suffixes : {}; | ||
output = descriptor.output !== undefined ? descriptor.output : "string"; | ||
symbols = descriptor.symbols || descriptor.suffixes || {}; | ||
output = descriptor.output || "string"; | ||
e = descriptor.exponent !== undefined ? descriptor.exponent : -1; | ||
@@ -80,5 +79,5 @@ num = Number(arg); | ||
result[0] = Number(val.toFixed(e > 0 ? round : 0)); | ||
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : si[bits ? "bits" : "bytes"][e]; | ||
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[bits ? "bits" : "bytes"][e]; | ||
if (!skip && unix) { | ||
if (unix) { | ||
result[1] = result[1].charAt(0); | ||
@@ -99,3 +98,3 @@ | ||
// Applying custom suffix | ||
result[1] = suffixes[result[1]] || result[1]; | ||
result[1] = symbols[result[1]] || result[1]; | ||
@@ -112,3 +111,3 @@ // Returning Array, Object, or String (default) | ||
if (output === "object") { | ||
return {value: result[0], suffix: result[1]}; | ||
return {value: result[0], suffix: result[1], symbol: result[1]}; | ||
} | ||
@@ -115,0 +114,0 @@ |
@@ -8,7 +8,7 @@ "use strict"; | ||
* @license BSD-3-Clause | ||
* @version 3.1.6 | ||
* @version 3.2.0 | ||
*/ | ||
(function (global) { | ||
var b = /^(b|B)$/; | ||
var si = { | ||
var symbol = { | ||
bits: ["b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"], | ||
@@ -30,3 +30,2 @@ bytes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] | ||
var result = [], | ||
skip = false, | ||
val = 0, | ||
@@ -43,3 +42,3 @@ e = undefined, | ||
spacer = undefined, | ||
suffixes = undefined; | ||
symbols = undefined; | ||
@@ -52,7 +51,7 @@ if (isNaN(arg)) { | ||
unix = descriptor.unix === true; | ||
base = descriptor.base !== undefined ? descriptor.base : 2; | ||
base = descriptor.base || 2; | ||
round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2; | ||
spacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? "" : " "; | ||
suffixes = descriptor.suffixes !== undefined ? descriptor.suffixes : {}; | ||
output = descriptor.output !== undefined ? descriptor.output : "string"; | ||
symbols = descriptor.symbols || descriptor.suffixes || {}; | ||
output = descriptor.output || "string"; | ||
e = descriptor.exponent !== undefined ? descriptor.exponent : -1; | ||
@@ -95,5 +94,5 @@ num = Number(arg); | ||
result[0] = Number(val.toFixed(e > 0 ? round : 0)); | ||
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : si[bits ? "bits" : "bytes"][e]; | ||
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[bits ? "bits" : "bytes"][e]; | ||
if (!skip && unix) { | ||
if (unix) { | ||
result[1] = result[1].charAt(0); | ||
@@ -114,3 +113,3 @@ | ||
// Applying custom suffix | ||
result[1] = suffixes[result[1]] || result[1]; | ||
result[1] = symbols[result[1]] || result[1]; | ||
@@ -127,3 +126,3 @@ // Returning Array, Object, or String (default) | ||
if (output === "object") { | ||
return { value: result[0], suffix: result[1] }; | ||
return { value: result[0], suffix: result[1], symbol: result[1] }; | ||
} | ||
@@ -130,0 +129,0 @@ |
{ | ||
"name": "filesize", | ||
"description": "JavaScript library to generate a human readable String describing the file size", | ||
"version": "3.1.6", | ||
"version": "3.2.0", | ||
"homepage": "http://filesizejs.com", | ||
@@ -6,0 +6,0 @@ "author": "Jason Mulligan <jason.mulligan@avoidwork.com>", |
@@ -29,5 +29,8 @@ # filesize.js | ||
### suffixes | ||
_***(object)***_ Dictionary of SI suffixes to replace for localization, defaults to english if no match is found | ||
### symbols | ||
_***(object)***_ Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found | ||
### suffixes (deprecated: use 'symbols') | ||
_***(object)***_ Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found | ||
### unix | ||
@@ -40,10 +43,10 @@ _***(boolean)***_ Enables unix style human readable output, e.g `ls -lh`, default is `false` | ||
filesize(500); // "500 B" | ||
filesize(500, {bits: true}); // "4 kb" | ||
filesize(500, {bits: true}); // "4 Kb" | ||
filesize(265318, {base: 10}); // "265.32 kB" | ||
filesize(265318); // "259.1 kB" | ||
filesize(265318, {round: 0}); // "259 kB" | ||
filesize(265318, {output: "array"}); // [259.1, "kB"] | ||
filesize(265318, {output: "object"}); // {value: 259.1, suffix: "kB"} | ||
filesize(1, {suffixes: {B: "Б"}}); // "1 Б" | ||
filesize(1024); // "1 kB" | ||
filesize(265318); // "259.1 KB" | ||
filesize(265318, {round: 0}); // "259 KB" | ||
filesize(265318, {output: "array"}); // [259.1, "KB"] | ||
filesize(265318, {output: "object"}); // {value: 259.1, suffix: "KB", symbol: "KB"} | ||
filesize(1, {symbols: {B: "Б"}}); // "1 Б" | ||
filesize(1024); // "1 KB" | ||
filesize(1024, {exponent: 0}); // "1024 B" | ||
@@ -57,3 +60,3 @@ filesize(1024, {output: "exponent"}); // 1 | ||
## License | ||
Copyright (c) 2015 Jason Mulligan | ||
Copyright (c) 2016 Jason Mulligan | ||
Licensed under the BSD-3 license. |
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
12296
60
259