Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8603992

Browse files
committedFeb 3, 2018
Adding separator option, fixes #93
1 parent 20baedd commit 8603992

13 files changed

+388
-359
lines changed
 

‎.eslintrc

-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
"es6": true,
66
"amd": true
77
},
8-
"ecmaFeatures": {
9-
"jsx": false,
10-
"superInFunctions": false,
11-
"classes": false,
12-
"modules": [2]
13-
},
148
"rules": {
159
"arrow-parens": [2, "as-needed"],
1610
"arrow-spacing": [2, {"before": true, "after": true}],

‎LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017, Jason Mulligan
1+
Copyright (c) 2018, Jason Mulligan
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

‎README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ _*(string)*_ Output of function (`array`, `exponent`, `object`, or `string`), de
2929
### round
3030
_*(number)*_ Decimal place, default is `2`
3131

32+
### separator
33+
_*(string)*_ Decimal separator charactor, default is `.`
34+
3235
### spacer
3336
_*(string)*_ Character between the `result` and `suffix`, default is `" "`
3437

@@ -61,6 +64,7 @@ filesize(1024, {output: "exponent"}); // 1
6164
filesize(265318, {standard: "iec"}); // "259.1 KiB"
6265
filesize(265318, {standard: "iec", fullform: true}); // "259.1 kibibytes"
6366
filesize(12, {fullform: true, fullforms: ["байтов"]}); // "12 байтов"
67+
filesize(265318, {separator: ","}); // "259,1 KB"
6468
```
6569

6670
## Partial Application
@@ -78,5 +82,5 @@ size(265318); // "259.1 KiB"
7882
filesize.js supports AMD loaders (require.js, curl.js, etc.), node.js & npm (```npm install filesize```), or using a script tag.
7983

8084
## License
81-
Copyright (c) 2017 Jason Mulligan
85+
Copyright (c) 2018 Jason Mulligan
8286
Licensed under the BSD-3 license.

‎lib/filesize.es6.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* filesize
33
*
4-
* @copyright 2017 Jason Mulligan <jason.mulligan@avoidwork.com>
4+
* @copyright 2018 Jason Mulligan <jason.mulligan@avoidwork.com>
55
* @license BSD-3-Clause
6-
* @version 3.5.11
6+
* @version 3.6.0
77
*/
88
(function (global) {
99
const b = /^(b|B)$/,
@@ -33,7 +33,7 @@
3333
function filesize (arg, descriptor = {}) {
3434
let result = [],
3535
val = 0,
36-
e, base, bits, ceil, full, fullforms, neg, num, output, round, unix, spacer, standard, symbols;
36+
e, base, bits, ceil, full, fullforms, neg, num, output, round, unix, separator, spacer, standard, symbols;
3737

3838
if (isNaN(arg)) {
3939
throw new Error("Invalid arguments");
@@ -42,14 +42,15 @@
4242
bits = descriptor.bits === true;
4343
unix = descriptor.unix === true;
4444
base = descriptor.base || 2;
45-
round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2;
46-
spacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? "" : " ";
45+
round = descriptor.round !== void 0 ? descriptor.round : unix ? 1 : 2;
46+
separator = descriptor.separator !== void 0 ? descriptor.separator || "" : "";
47+
spacer = descriptor.spacer !== void 0 ? descriptor.spacer : unix ? "" : " ";
4748
symbols = descriptor.symbols || descriptor.suffixes || {};
4849
standard = base === 2 ? descriptor.standard || "jedec" : "jedec";
4950
output = descriptor.output || "string";
5051
full = descriptor.fullform === true;
5152
fullforms = descriptor.fullforms instanceof Array ? descriptor.fullforms : [];
52-
e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
53+
e = descriptor.exponent !== void 0 ? descriptor.exponent : -1;
5354
num = Number(arg);
5455
neg = num < 0;
5556
ceil = base > 2 ? 1000 : 1024;
@@ -127,6 +128,10 @@
127128
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
128129
}
129130

131+
if (separator.length > 0) {
132+
result[0] = result[0].toString().replace(".", separator);
133+
}
134+
130135
return result.join(spacer);
131136
}
132137

‎lib/filesize.es6.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/filesize.es6.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/filesize.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
/**
44
* filesize
55
*
6-
* @copyright 2017 Jason Mulligan <jason.mulligan@avoidwork.com>
6+
* @copyright 2018 Jason Mulligan <jason.mulligan@avoidwork.com>
77
* @license BSD-3-Clause
8-
* @version 3.5.11
8+
* @version 3.6.0
99
*/
1010
(function (global) {
1111
var b = /^(b|B)$/,
@@ -48,6 +48,7 @@
4848
output = void 0,
4949
round = void 0,
5050
unix = void 0,
51+
separator = void 0,
5152
spacer = void 0,
5253
standard = void 0,
5354
symbols = void 0;
@@ -59,14 +60,15 @@
5960
bits = descriptor.bits === true;
6061
unix = descriptor.unix === true;
6162
base = descriptor.base || 2;
62-
round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2;
63-
spacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? "" : " ";
63+
round = descriptor.round !== void 0 ? descriptor.round : unix ? 1 : 2;
64+
separator = descriptor.separator !== void 0 ? descriptor.separator || "" : "";
65+
spacer = descriptor.spacer !== void 0 ? descriptor.spacer : unix ? "" : " ";
6466
symbols = descriptor.symbols || descriptor.suffixes || {};
6567
standard = base === 2 ? descriptor.standard || "jedec" : "jedec";
6668
output = descriptor.output || "string";
6769
full = descriptor.fullform === true;
6870
fullforms = descriptor.fullforms instanceof Array ? descriptor.fullforms : [];
69-
e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
71+
e = descriptor.exponent !== void 0 ? descriptor.exponent : -1;
7072
num = Number(arg);
7173
neg = num < 0;
7274
ceil = base > 2 ? 1000 : 1024;
@@ -144,6 +146,10 @@
144146
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
145147
}
146148

149+
if (separator.length > 0) {
150+
result[0] = result[0].toString().replace(".", separator);
151+
}
152+
147153
return result.join(spacer);
148154
}
149155

‎lib/filesize.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/filesize.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package-lock.json

+332-325
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "filesize",
33
"description": "JavaScript library to generate a human readable String describing the file size",
4-
"version": "3.5.11",
4+
"version": "3.6.0",
55
"homepage": "https://filesizejs.com",
66
"author": "Jason Mulligan <jason.mulligan@avoidwork.com>",
77
"repository": {
@@ -22,13 +22,13 @@
2222
"devDependencies": {
2323
"babel-core": "^6.26.0",
2424
"babel-preset-env": "^1.6.1",
25-
"babel-minify": "^0.2.0",
25+
"babel-minify": "^0.3.0",
2626
"grunt": "^1.0.1",
2727
"grunt-babel": "^7.0.0",
2828
"grunt-cli": "^1.2.0",
2929
"grunt-contrib-concat": "^1.0.1",
3030
"grunt-contrib-nodeunit": "^1.0.0",
31-
"grunt-contrib-uglify": "^3.1.0",
31+
"grunt-contrib-uglify": "^3.3.0",
3232
"grunt-contrib-watch": "^1.0.0",
3333
"grunt-eslint": "^20.1.0"
3434
},

‎src/filesize.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
function filesize (arg, descriptor = {}) {
1010
let result = [],
1111
val = 0,
12-
e, base, bits, ceil, full, fullforms, neg, num, output, round, unix, spacer, standard, symbols;
12+
e, base, bits, ceil, full, fullforms, neg, num, output, round, unix, separator, spacer, standard, symbols;
1313

1414
if (isNaN(arg)) {
1515
throw new Error("Invalid arguments");
@@ -18,14 +18,15 @@
1818
bits = descriptor.bits === true;
1919
unix = descriptor.unix === true;
2020
base = descriptor.base || 2;
21-
round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2;
22-
spacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? "" : " ";
21+
round = descriptor.round !== void 0 ? descriptor.round : unix ? 1 : 2;
22+
separator = descriptor.separator !== void 0 ? descriptor.separator || "" : "";
23+
spacer = descriptor.spacer !== void 0 ? descriptor.spacer : unix ? "" : " ";
2324
symbols = descriptor.symbols || descriptor.suffixes || {};
2425
standard = base === 2 ? descriptor.standard || "jedec" : "jedec";
2526
output = descriptor.output || "string";
2627
full = descriptor.fullform === true;
2728
fullforms = descriptor.fullforms instanceof Array ? descriptor.fullforms : [];
28-
e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
29+
e = descriptor.exponent !== void 0 ? descriptor.exponent : -1;
2930
num = Number(arg);
3031
neg = num < 0;
3132
ceil = base > 2 ? 1000 : 1024;
@@ -103,6 +104,10 @@
103104
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
104105
}
105106

107+
if (separator.length > 0) {
108+
result[0] = result[0].toString().replace(".", separator);
109+
}
110+
106111
return result.join(spacer);
107112
}
108113

‎test/filesize_test.js

+8
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ exports["filesize"] = {
172172
test.equal(filesize(0, {exponent: 0}), "0 B", "Should be '0 B'");
173173
test.equal(filesize(0, {exponent: 2}), "0 MB", "Should be '0 MB'");
174174

175+
test.done();
176+
},
177+
separator: function (test) {
178+
test.expect(2);
179+
180+
test.equal(filesize(1040, {separator: ""}), "1.02 KB", "Should be '1.02 KB'");
181+
test.equal(filesize(1040, {separator: ","}), "1,02 KB", "Should be '1,02 KB'");
182+
175183
test.done();
176184
}
177185
};

0 commit comments

Comments
 (0)
Please sign in to comment.