Skip to content

Commit 727db07

Browse files
committed
Adding fullforms for overriding full form
1 parent d957df3 commit 727db07

8 files changed

+21
-12
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ _*(number)*_ Specifies the SI suffix via exponent, e.g. `2` is `MB` for bytes, d
2020
### fullform
2121
_*(boolean)*_ Enables full form of unit of measure, default is `false`
2222

23+
### fullforms
24+
_*(array)*_ Array of full form overrides, default is `[]`
25+
2326
### output
2427
_*(string)*_ Output of function (`array`, `exponent`, `object`, or `string`), default is `string`
2528

@@ -57,6 +60,7 @@ filesize(1024, {exponent: 0}); // "1024 B"
5760
filesize(1024, {output: "exponent"}); // 1
5861
filesize(265318, {standard: "iec"}); // "259.1 KiB"
5962
filesize(265318, {standard: "iec", fullform: true}); // "259.1 kibibytes"
63+
filesize(0, {fullform: true, fullforms: ["байт"]}); // "0 байт"
6064
```
6165

6266
## Partial Application

lib/filesize.es6.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @copyright 2017 Jason Mulligan <[email protected]>
55
* @license BSD-3-Clause
6-
* @version 3.5.3
6+
* @version 3.5.4
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, neg, num, output, round, unix, spacer, standard, symbols;
36+
e, base, bits, ceil, full, fullforms, neg, num, output, round, unix, spacer, standard, symbols;
3737

3838
if (isNaN(arg)) {
3939
throw new Error("Invalid arguments");
@@ -48,6 +48,7 @@
4848
standard = base === 2 ? descriptor.standard || "jedec" : "jedec";
4949
output = descriptor.output || "string";
5050
full = descriptor.fullform === true;
51+
fullforms = descriptor.fullforms instanceof Array ? descriptor.fullforms : [];
5152
e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
5253
num = Number(arg);
5354
neg = num < 0;
@@ -124,7 +125,7 @@
124125
}
125126

126127
if (full) {
127-
result[1] = fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
128+
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
128129
}
129130

130131
return result.join(spacer);

lib/filesize.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @copyright 2017 Jason Mulligan <[email protected]>
77
* @license BSD-3-Clause
8-
* @version 3.5.3
8+
* @version 3.5.4
99
*/
1010
(function (global) {
1111
var b = /^(b|B)$/,
@@ -42,6 +42,7 @@
4242
bits = void 0,
4343
ceil = void 0,
4444
full = void 0,
45+
fullforms = void 0,
4546
neg = void 0,
4647
num = void 0,
4748
output = void 0,
@@ -64,6 +65,7 @@
6465
standard = base === 2 ? descriptor.standard || "jedec" : "jedec";
6566
output = descriptor.output || "string";
6667
full = descriptor.fullform === true;
68+
fullforms = descriptor.fullforms instanceof Array ? descriptor.fullforms : [];
6769
e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
6870
num = Number(arg);
6971
neg = num < 0;
@@ -140,7 +142,7 @@
140142
}
141143

142144
if (full) {
143-
result[1] = fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
145+
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
144146
}
145147

146148
return result.join(spacer);

lib/filesize.min.js

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

0 commit comments

Comments
 (0)