镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix: honor locale and separator options for zero values - #364

Merged
avoidwork merged 2 commits into
avoidwork:masterfrom
feritcemkahraman:fix/zero-number-formatting
Oct 11, 2026
Merged

avoidwork merged 2 commits into
avoidwork:masterfrom
feritcemkahraman:fix/zero-number-formatting

Conversation

@feritcemkahraman

@feritcemkahraman feritcemkahraman commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The zero-value fast path bypasses number formatting options. For example, filesize(0, { locale: "de-DE", pad: true }) returns 0.00 B while nonzero values use the requested comma decimal separator. Empty upload sizes therefore render inconsistently with populated sizes.

Pass locale, localeOptions, and separator into zero handling and reuse the shared number formatter. Preserve the existing precision-over-padding priority, exponent output, symbol/full-form handling, and default numeric zero in structured outputs. Regenerated the tracked distributions.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature / enhancement
  • Breaking change
  • Documentation update
  • Build / dependency / tooling change
  • Test additions or updates
  • Other

Related Issues

N/A — independently reproduced; no overlapping open PR found.

Testing

The zero-formatting and locale-plus-precision regressions failed before their fixes (0.00 B rather than 0,00 B) and passes afterward. It covers numeric/BigInt zero, explicit/system locale, localeOptions, custom separator, precision, array/object output, and unchanged exponent output. Explicit precision retains the existing precision string (for example 0.00 B with de-DE), matching the existing nonzero precision path; only zeros without explicit precision are converted to numbers for locale formatting.

node --test --experimental-test-coverage tests/**/*.js: 268 of 269 tests pass; source files retain 100% line/branch/function coverage. The remaining existing test assumes the system locale uses a period (should ignore localeOptions when locale is true). On this Windows machine the system locale is tr-TR, so it produces 1,54 kB. Re-running that test against the original HEAD source confirms the identical failure.

Oxlint passes for source/tests/build configuration, and their oxfmt check passes. npm run build passes. The aggregate npm test formatting glob additionally visits generated dist files on Windows and reports existing formatting differences; the targeted formatter also finds an existing benchmarks/README.md difference. Those unrelated files were not reformatted.

Checklist

  • npm test passes — existing locale/formatting limitations described above
  • npm run build succeeds
  • 100% test coverage maintained — implementation source line/branch/function coverage
  • No hardcoded secrets or credentials introduced
  • Zero external dependencies added
  • ES Modules only (no CommonJS in src/)
  • JSDoc comments added/updated
  • CHANGELOG.md updated (if applicable) — N/A, no release/version change

Screenshots (if applicable)

N/A

@avoidwork
avoidwork merged commit bebc9b5 into avoidwork:master Oct 11, 2026
2 checks passed
@avoidwork avoidwork mentioned this pull request Oct 11, 2026
9 tasks done
@avoidwork

Copy link
Copy Markdown
Owner

Thanks for this fix — it's shipped in v11.0.26. The zero-value path now honors locale, localeOptions, and separator consistently with the non-zero path. Appreciate the contribution! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants