RepoPilot

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

About sindresorhus/pretty-bytes · 2 messages · last activity 5/25/2026

Question

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

RepoPilot

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

The library uses JavaScript's native toLocaleString() method [index.js:L55-L65] to handle locale-specific formatting. The locale option supports multiple modes:

  • locale: false (default): No localization—numbers are formatted without locale-specific formatting
  • locale: true: Uses the system/browser's default locale
  • locale: 'de' (string): Uses a specific locale (e.g., German uses commas as decimal separators and periods as thousands separators)
  • locale: ['unknown', 'de', 'en'] (array): Tries locales in order, using the first supported one

For example, from the test cases [test.js:L71-L110]:

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

The formatting is applied in the toLocaleString function [index.js:L55-L65], which calls number.toLocaleString() with the appropriate locale parameter.

FOLLOW_UPS:

  • How does fixedWidth padding work with locales?
  • What fraction digit options are available?
  • Does it support right-to-left language locales?

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.