Skip to content

Commit b2ec833

Browse files
authored
Merge pull request #138 from getsnoopy/make-si-default
Make SI and IEC standards defaults
2 parents 1e36a1b + 360b085 commit b2ec833

File tree

3 files changed

+126
-117
lines changed

3 files changed

+126
-117
lines changed

README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ 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 `10`
1313

1414
### bits
1515
_*(boolean)*_ Enables `bit` sizes, default is `false`
@@ -51,10 +51,10 @@ _*(string)*_ Decimal separator character, default is `.`
5151
_*(string)*_ Character between the `result` and `symbol`, default is `" "`
5252

5353
### standard
54-
_*(string)*_ Standard unit of measure, can be `iec` or `jedec`, default is `jedec`; can be overruled by `base`
54+
_*(string)*_ Standard unit of measure, can be `iec` or `jedec`, default is `iec`; can be overruled by `base`
5555

5656
### symbols
57-
_*(object)*_ Dictionary of SI/JEDEC/IEC symbols to replace for localization, defaults to english if no match is found
57+
_*(object)*_ Dictionary of SI/IEC/JEDEC symbols to replace for localization, defaults to english if no match is found
5858

5959
### unix
6060
_*(boolean)*_ Enables unix style human readable output, e.g `ls -lh`, default is `false`
@@ -63,21 +63,21 @@ _*(boolean)*_ Enables unix style human readable output, e.g `ls -lh`, default is
6363

6464
```javascript
6565
filesize(500); // "500 B"
66-
filesize(500, {bits: true}); // "4 Kb"
67-
filesize(265318, {base: 10}); // "265.32 kB"
68-
filesize(265318); // "259.1 KB"
69-
filesize(265318, {round: 0}); // "259 KB"
70-
filesize(265318, {output: "array"}); // [259.1, "KB"]
71-
filesize(265318, {output: "object"}); // {value: 259.1, symbol: "KB", exponent: 1, unit: "KB"}
66+
filesize(500, {bits: true}); // "4 kbit"
67+
filesize(265318, {base: 2}); // "259.1 KiB"
68+
filesize(265318); // "265.32 kB"
69+
filesize(265318, {round: 0}); // "265 kB"
70+
filesize(265318, {output: "array"}); // [265.32, "kB"]
71+
filesize(265318, {output: "object"}); // {value: 265.32, symbol: "kB", exponent: 1, unit: "kB"}
7272
filesize(1, {symbols: {B: "Б"}}); // "1 Б"
73-
filesize(1024); // "1 KB"
73+
filesize(1024); // "1.02 kB"
7474
filesize(1024, {exponent: 0}); // "1024 B"
7575
filesize(1024, {output: "exponent"}); // 1
76-
filesize(265318, {standard: "iec"}); // "259.1 KiB"
77-
filesize(265318, {standard: "iec", fullform: true}); // "259.1 kibibytes"
76+
filesize(265318, {standard: "jedec"}); // "259.1 KB"
77+
filesize(265318, {base: 2, fullform: true}); // "259.1 kibibytes"
7878
filesize(12, {fullform: true, fullforms: ["байтов"]}); // "12 байтов"
79-
filesize(265318, {separator: ","}); // "259,1 KB"
80-
filesize(265318, {locale: "de"}); // "259,1 KB"
79+
filesize(265318, {separator: ","}); // "265,32 kB"
80+
filesize(265318, {locale: "de"}); // "265,32 kB"
8181
```
8282

8383
## Partial Application
@@ -86,9 +86,9 @@ upon execution. This can be used to reduce `Object` creation if you call `filesi
8686
in lexical scope.
8787

8888
```javascript
89-
const size = filesize.partial({standard: "iec"});
89+
const size = filesize.partial({base: 2, standard: "jedec"});
9090

91-
size(265318); // "259.1 KiB"
91+
size(265318); // "259.1 KB"
9292
```
9393

9494
## How can I load filesize.js?

src/filesize.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ function filesize (arg, descriptor = {}) {
3838
bits = descriptor.bits === true;
3939
unix = descriptor.unix === true;
4040
pad = descriptor.pad === true;
41-
base = descriptor.base || 2;
41+
base = descriptor.base || 10;
4242
round = descriptor.round !== void 0 ? descriptor.round : unix ? 1 : 2;
4343
locale = descriptor.locale !== void 0 ? descriptor.locale : "";
4444
localeOptions = descriptor.localeOptions || {};
4545
separator = descriptor.separator !== void 0 ? descriptor.separator : "";
4646
spacer = descriptor.spacer !== void 0 ? descriptor.spacer : unix ? "" : " ";
4747
symbols = descriptor.symbols || {};
48-
standard = base === 2 ? descriptor.standard || "jedec" : "jedec";
48+
standard = base === 2 ? descriptor.standard || "iec" : "jedec";
4949
output = descriptor.output || "string";
5050
full = descriptor.fullform === true;
5151
fullforms = descriptor.fullforms instanceof Array ? descriptor.fullforms : [];
@@ -110,7 +110,7 @@ function filesize (arg, descriptor = {}) {
110110
u = result[1] = base === 10 && e === 1 ? bits ? "kbit" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];
111111

112112
if (unix) {
113-
result[1] = standard === "jedec" ? result[1].charAt(0) : e > 0 ? result[1].replace(/B$/, "") : result[1];
113+
result[1] = result[1].charAt(0);
114114

115115
if (b.test(result[1])) {
116116
result[0] = Math.floor(result[0]);

0 commit comments

Comments
 (0)