Skip to content

Commit 6505945

Browse files
add support for localeOptions
1 parent b0b12dd commit 6505945

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/filesize.js

+3-2
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, locale, neg, num, output, round, unix, separator, spacer, standard, symbols;
12+
e, base, bits, ceil, full, fullforms, locale, localeOptions, neg, num, output, round, unix, separator, spacer, standard, symbols;
1313

1414
if (isNaN(arg)) {
1515
throw new TypeError("Invalid number");
@@ -20,6 +20,7 @@
2020
base = descriptor.base || 2;
2121
round = descriptor.round !== void 0 ? descriptor.round : unix ? 1 : 2;
2222
locale = descriptor.locale !== void 0 ? descriptor.locale : "";
23+
localeOptions = descriptor.localeOptions || {};
2324
separator = descriptor.separator !== void 0 ? descriptor.separator : "";
2425
spacer = descriptor.spacer !== void 0 ? descriptor.spacer : unix ? "" : " ";
2526
symbols = descriptor.symbols || {};
@@ -95,7 +96,7 @@
9596
if (locale === true) {
9697
result[0] = result[0].toLocaleString();
9798
} else if (locale.length > 0) {
98-
result[0] = result[0].toLocaleString(locale);
99+
result[0] = result[0].toLocaleString(locale, localeOptions);
99100
} else if (separator.length > 0) {
100101
result[0] = result[0].toString().replace(".", separator);
101102
}

test/filesize_test.js

+14
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,19 @@ exports.filesize = {
161161
test.equal(filesize(1040, {locale: true}), Number(1.02).toLocaleString() + " KB", "Should be '" + Number(1.02).toLocaleString() + " KB'");
162162
test.equal(filesize(1040, {locale: "de"}), Number(1.02).toLocaleString("de") + " KB", "Should be '" + Number(1.02).toLocaleString("de") + " KB'");
163163
test.done();
164+
},
165+
localeOptions: function (test) {
166+
test.expect(4);
167+
test.equal(filesize(1024, {locale: "de"}), "1 KB", "Should be '1 KB'");
168+
test.equal(filesize(1024, {localeOptions: {minimumFractionDigits: 1}}), "1 KB", "Should be '1 KB'");
169+
test.equal(filesize(1024, {
170+
locale: true,
171+
localeOptions: {minimumFractionDigits: 1}
172+
}), "1 KB", "Should be '1 KB'");
173+
test.equal(filesize(1024, {
174+
locale: "de",
175+
localeOptions: {minimumFractionDigits: 1}
176+
}), Number(1).toLocaleString("de", {minimumFractionDigits: 1}) + " KB", "Should be '" + Number(1).toLocaleString("de", {minimumFractionDigits: 1}) + " KB'");
177+
test.done();
164178
}
165179
};

0 commit comments

Comments
 (0)