Upstream avoidwork/filesize.js state of the touched files before cc6ad645b3

This commit is contained in:
upstream committed 2026-09-04 04:49:30 +02:00
1 parent d0bb0d64af
commit 3da8421ddf
2 files changed
+10 -20

No files matched your search

+10 -10
View File
@@ -402,16 +402,6 @@ export function decorateResult(
bits, bits,
roundingFunc, roundingFunc,
) { ) {
// Capture the number before the sign and the formatting: a comma decimal
// separator makes parseFloat read "1,5" as 1, and a leading "-" breaks the
// "=== 1" singular check.
let numericValue;
if (typeof result[0] === "string") {
numericValue = parseFloat(result[0]);
} else {
numericValue = result[0];
}
if (neg) { if (neg) {
// `precision` leaves the value as a string from toPrecision (e.g. "1.50"). // `precision` leaves the value as a string from toPrecision (e.g. "1.50").
// Negating that arithmetically coerces it back to a number and drops the // Negating that arithmetically coerces it back to a number and drops the
@@ -423,6 +413,16 @@ export function decorateResult(
result[1] = symbols[result[1]]; result[1] = symbols[result[1]];
} }
// Capture the numeric value before formatting; a comma decimal separator
// (via separator or a locale such as de-DE) would otherwise make parseFloat
// read "1,5" as 1 and select the singular unit name.
let numericValue;
if (typeof result[0] === "string") {
numericValue = parseFloat(result[0]);
} else {
numericValue = result[0];
}
result[0] = applyNumberFormatting( result[0] = applyNumberFormatting(
result[0], result[0],
locale, locale,
-10
View File
@@ -268,16 +268,6 @@ describe("filesize", () => {
); );
}); });
it("should keep the singular fullform name for negative one-magnitude values", () => {
assert.strictEqual(filesize(-1, { fullform: true }), "-1 byte");
assert.strictEqual(filesize(-0.125, { bits: true, fullform: true }), "-1 bit");
});
it("should keep the plural fullform name for negative values", () => {
assert.strictEqual(filesize(-2, { fullform: true }), "-2 bytes");
assert.strictEqual(filesize(-0.25, { bits: true, fullform: true }), "-2 bits");
});
it("should handle bits fullform singular", () => { it("should handle bits fullform singular", () => {
assert.strictEqual(filesize(0.125, { bits: true, fullform: true }), "1 bit"); assert.strictEqual(filesize(0.125, { bits: true, fullform: true }), "1 bit");
}); });