Skip to content

Commit 7d8b650

Browse files
committed
Adding longform flag, fixing markdown in README
Fixing README
1 parent 7009d45 commit 7d8b650

9 files changed

+62
-19
lines changed

README.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,37 @@ filesize.js provides a simple way to get a human readable file size string from
99
`filesize()` accepts an optional descriptor Object as a second argument, so you can customize the output.
1010

1111
### base
12-
_***(number)***_ Number base, default is `2`
12+
_*(number)*_ Number base, default is `2`
1313

1414
### bits
15-
_***(boolean)***_ Enables `bit` sizes, default is `false`
15+
_*(boolean)*_ Enables `bit` sizes, default is `false`
1616

1717
### exponent
18-
_***(number)***_ Specifies the SI suffix via exponent, e.g. `2` is `MB` for bytes, default is `-1`
18+
_*(number)*_ Specifies the SI suffix via exponent, e.g. `2` is `MB` for bytes, default is `-1`
19+
20+
### longform
21+
_*(boolean)*_ Enables long form of unit of measure, default is `false`
1922

2023
### output
21-
_***(string)***_ Output of function (`array`, `exponent`, `object`, or `string`), default is `string`
24+
_*(string)*_ Output of function (`array`, `exponent`, `object`, or `string`), default is `string`
2225

2326
### round
24-
_***(number)***_ Decimal place, default is `2`
27+
_*(number)*_ Decimal place, default is `2`
2528

2629
### spacer
27-
_***(string)***_ Character between the `result` and `suffix`, default is `" "`
30+
_*(string)*_ Character between the `result` and `suffix`, default is `" "`
2831

2932
### standard
30-
_***(string)***_ Standard unit of measure, can be `iec` or `jedec`, default is `jedec`; can be overruled by `base`
33+
_*(string)*_ Standard unit of measure, can be `iec` or `jedec`, default is `jedec`; can be overruled by `base`
3134

3235
### symbols
33-
_***(object)***_ Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found
36+
_*(object)*_ Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found
3437

3538
### suffixes (deprecated: use 'symbols')
36-
_***(object)***_ Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found
39+
_*(object)*_ Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found
3740

3841
### unix
39-
_***(boolean)***_ Enables unix style human readable output, e.g `ls -lh`, default is `false`
42+
_*(boolean)*_ Enables unix style human readable output, e.g `ls -lh`, default is `false`
4043

4144
## Examples
4245

@@ -53,6 +56,7 @@ filesize(1024); // "1 KB"
5356
filesize(1024, {exponent: 0}); // "1024 B"
5457
filesize(1024, {output: "exponent"}); // 1
5558
filesize(265318, {standard: "iec"}); // "259.1 KiB"
59+
filesize(265318, {standard: "iec", longform: true}); // "259.1 kibibytes"
5660
```
5761

5862
## Partial Application

lib/filesize.es6.js

+11-2
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.4.3
6+
* @version 3.5.0
77
*/
88
(function (global) {
99
const b = /^(b|B)$/,
@@ -16,6 +16,10 @@
1616
bits: ["b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"],
1717
bytes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
1818
}
19+
},
20+
longform = {
21+
iec: ["", "kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"],
22+
jedec: ["", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta"]
1923
};
2024

2125
/**
@@ -29,7 +33,7 @@
2933
function filesize (arg, descriptor = {}) {
3034
let result = [],
3135
val = 0,
32-
e, base, bits, ceil, neg, num, output, round, unix, spacer, standard, symbols;
36+
e, base, bits, ceil, long, neg, num, output, round, unix, spacer, standard, symbols;
3337

3438
if (isNaN(arg)) {
3539
throw new Error("Invalid arguments");
@@ -43,6 +47,7 @@
4347
symbols = descriptor.symbols || descriptor.suffixes || {};
4448
standard = base === 2 ? descriptor.standard || "jedec" : "jedec";
4549
output = descriptor.output || "string";
50+
long = descriptor.longform === true;
4651
e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
4752
num = Number(arg);
4853
neg = num < 0;
@@ -117,6 +122,10 @@
117122
return {value: result[0], suffix: result[1], symbol: result[1]};
118123
}
119124

125+
if (long) {
126+
result[1] = longform[standard][e] + (bits ? "bit" : "byte") + (result[0] > 1 ? "s" : "");
127+
}
128+
120129
return result.join(spacer);
121130
}
122131

lib/filesize.js

+11-1
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.4.3
8+
* @version 3.5.0
99
*/
1010
(function (global) {
1111
var b = /^(b|B)$/,
@@ -18,6 +18,10 @@
1818
bits: ["b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"],
1919
bytes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
2020
}
21+
},
22+
longform = {
23+
iec: ["", "kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"],
24+
jedec: ["", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta"]
2125
};
2226

2327
/**
@@ -37,6 +41,7 @@
3741
base = void 0,
3842
bits = void 0,
3943
ceil = void 0,
44+
long = void 0,
4045
neg = void 0,
4146
num = void 0,
4247
output = void 0,
@@ -58,6 +63,7 @@
5863
symbols = descriptor.symbols || descriptor.suffixes || {};
5964
standard = base === 2 ? descriptor.standard || "jedec" : "jedec";
6065
output = descriptor.output || "string";
66+
long = descriptor.longform === true;
6167
e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
6268
num = Number(arg);
6369
neg = num < 0;
@@ -132,6 +138,10 @@
132138
return { value: result[0], suffix: result[1], symbol: result[1] };
133139
}
134140

141+
if (long) {
142+
result[1] = longform[standard][e] + (bits ? "bit" : "byte") + (result[0] > 1 ? "s" : "");
143+
}
144+
135145
return result.join(spacer);
136146
}
137147

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)