fix(helpers): keep fullform singular for negative one-magnitude values
decorateResult() captured numericValue (used to pick the singular vs
plural fullform suffix) after the negative sign was already prefixed
onto result[0], so filesize(-1, {fullform: true}) compared -1 === 1
and wrongly pluralized to "-1 bytes" instead of "-1 byte". Capture the
magnitude before the sign is applied instead.
This commit is contained in:
1 parent
6758bfef36
commit
d0bb0d64af
3 files changed
+20
-100
No files matched your search
+10
-10
@@ -402,6 +402,16 @@ export function decorateResult(
|
||||
bits,
|
||||
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) {
|
||||
// `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
|
||||
@@ -413,16 +423,6 @@ export function decorateResult(
|
||||
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],
|
||||
locale,
|
||||
|
||||
Reference in new issue
Block a user