Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions dist/filesize.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -415,21 +415,27 @@ function applyNumberFormatting(
result = result.toLocaleString(undefined, localePad);
} else if (locale.length > 0) {
result = result.toLocaleString(locale, { ...localeOptions, ...localePad });
} else if (separator.length > 0) {
} else {
// Round before separator replacement to ensure excess decimal places
// are truncated when pad is also set (fixes padding + separator bug).
if (pad && round > 0) {
if (separator.length > 0 && pad && round > 0) {
const p = Math.pow(10, round);
result = roundingFunc(result * p) / p;
}
result = result.toString().replace(PERIOD, separator);
}

// Expand scientific notation to full decimal so pathological values like
// Number.MAX_VALUE don't leak "e+284" into the output. Only applies when
// the value is a finite number whose string form uses exponent notation.
if (typeof result === "number" && isFinite(result) && result.toString().includes(E)) {
result = result.toLocaleString("en-US", { useGrouping: false });
// Expand scientific notation to full decimal so pathological values like
// Number.MAX_VALUE don't leak "e+284" into the output. Only applies when
// the value is a finite number whose string form uses exponent notation.
// It runs before the separator is applied so a custom separator can't
// leave "1e-9" behind, and keeps up to 20 fraction digits so small
// values such as 1e-9 aren't truncated to "0" (the Intl default is 3).
if (typeof result === "number" && isFinite(result) && result.toString().includes(E)) {
result = result.toLocaleString("en-US", { useGrouping: false, maximumFractionDigits: 20 });
}

if (separator.length > 0) {
result = result.toString().replace(PERIOD, separator);
}
}

// Apply padding for the non-locale paths, where the string has a single
Expand Down
24 changes: 15 additions & 9 deletions dist/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,21 +411,27 @@ function applyNumberFormatting(
result = result.toLocaleString(undefined, localePad);
} else if (locale.length > 0) {
result = result.toLocaleString(locale, { ...localeOptions, ...localePad });
} else if (separator.length > 0) {
} else {
// Round before separator replacement to ensure excess decimal places
// are truncated when pad is also set (fixes padding + separator bug).
if (pad && round > 0) {
if (separator.length > 0 && pad && round > 0) {
const p = Math.pow(10, round);
result = roundingFunc(result * p) / p;
}
result = result.toString().replace(PERIOD, separator);
}

// Expand scientific notation to full decimal so pathological values like
// Number.MAX_VALUE don't leak "e+284" into the output. Only applies when
// the value is a finite number whose string form uses exponent notation.
if (typeof result === "number" && isFinite(result) && result.toString().includes(E)) {
result = result.toLocaleString("en-US", { useGrouping: false });
// Expand scientific notation to full decimal so pathological values like
// Number.MAX_VALUE don't leak "e+284" into the output. Only applies when
// the value is a finite number whose string form uses exponent notation.
// It runs before the separator is applied so a custom separator can't
// leave "1e-9" behind, and keeps up to 20 fraction digits so small
// values such as 1e-9 aren't truncated to "0" (the Intl default is 3).
if (typeof result === "number" && isFinite(result) && result.toString().includes(E)) {
result = result.toLocaleString("en-US", { useGrouping: false, maximumFractionDigits: 20 });
}

if (separator.length > 0) {
result = result.toString().replace(PERIOD, separator);
}
}

// Apply padding for the non-locale paths, where the string has a single
Expand Down
2 changes: 1 addition & 1 deletion dist/filesize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/filesize.min.js.map

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions dist/filesize.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,21 +411,27 @@ function applyNumberFormatting(
result = result.toLocaleString(undefined, localePad);
} else if (locale.length > 0) {
result = result.toLocaleString(locale, { ...localeOptions, ...localePad });
} else if (separator.length > 0) {
} else {
// Round before separator replacement to ensure excess decimal places
// are truncated when pad is also set (fixes padding + separator bug).
if (pad && round > 0) {
if (separator.length > 0 && pad && round > 0) {
const p = Math.pow(10, round);
result = roundingFunc(result * p) / p;
}
result = result.toString().replace(PERIOD, separator);
}

// Expand scientific notation to full decimal so pathological values like
// Number.MAX_VALUE don't leak "e+284" into the output. Only applies when
// the value is a finite number whose string form uses exponent notation.
if (typeof result === "number" && isFinite(result) && result.toString().includes(E)) {
result = result.toLocaleString("en-US", { useGrouping: false });
// Expand scientific notation to full decimal so pathological values like
// Number.MAX_VALUE don't leak "e+284" into the output. Only applies when
// the value is a finite number whose string form uses exponent notation.
// It runs before the separator is applied so a custom separator can't
// leave "1e-9" behind, and keeps up to 20 fraction digits so small
// values such as 1e-9 aren't truncated to "0" (the Intl default is 3).
if (typeof result === "number" && isFinite(result) && result.toString().includes(E)) {
result = result.toLocaleString("en-US", { useGrouping: false, maximumFractionDigits: 20 });
}

if (separator.length > 0) {
result = result.toString().replace(PERIOD, separator);
}
}

// Apply padding for the non-locale paths, where the string has a single
Expand Down
Loading
Loading