RepoPilot

Does this respect the user's locale for number formatting?

About sindresorhus/pretty-bytes · 2 messages · last activity 7/20/2026

Question

Does this respect the user's locale for number formatting?

RepoPilot

Yes, pretty-bytes does respect the user's locale for number formatting through the locale option.

The library uses the toLocaleString function [index.js:L55-L65] to format numbers according to a specified locale. Here's how it works:

Locale option behaviors:

  1. locale: false (default) — No localization; numbers are formatted without locale-specific formatting.

  2. locale: true — Uses the system/browser's default locale for formatting.

  3. locale: 'de' or other language tag — Formats using a specific BCP 47 language tag (e.g., German uses commas as decimal separators and periods as thousand separators).

  4. locale: ['unknown', 'de', 'en'] — Accepts an array of language tags; the first supported locale is used.

Example from the tests [test.js:L71-L110]:

  • prettyBytes(1001, {locale: 'de'})'1 kB' (German formatting)
  • prettyBytes(1e30, {locale: 'de'})'1.000.000 YB' (uses periods for thousands)
  • prettyBytes(1e30, {locale: 'en'})'1,000,000 YB' (uses commas for thousands)

The implementation calls Number.prototype.toLocaleString() internally, which handles all locale-specific number formatting conventions [index.js:L55-L65].

FOLLOW_UPS:

  • What does the signed option do?
  • How does the binary prefix option work?
  • What is the fixedWidth option for?

Want to ask your own question?

Open chat for sindresorhus/pretty-bytes

Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/pretty-bytes. AI answers can be incomplete or stale — verify before relying on them.