Does this respect the user's locale for number formatting?
Does this respect the user's locale for number formatting?
About sindresorhus/pretty-bytes · 2 messages · last activity 6/1/2026
Yes, pretty-bytes respects the user's locale for number formatting through the locale option.
The library provides a toLocaleString function [index.js:L55-L65] that handles locale-aware formatting. It supports three modes:
- String locale: Pass a specific BCP 47 language tag like
'de'or'en' - System locale: Pass
locale: trueto use the browser/system default - Locale array: Pass multiple locale options as a fallback chain, e.g.,
['unknown', 'de', 'en']
When a locale is provided, the function calls JavaScript's native Number.toLocaleString() with the specified locale, which handles decimal separators and thousands separators according to that locale's conventions.
For example [test.js:L75-L76]:
t.is(prettyBytes(1001, {locale: 'de'}), '1 kB'); // German uses space for thousands
t.is(prettyBytes(1001, {locale: 'en'}), '1 kB'); // English uses comma
And for larger numbers [test.js:L79-L80]:
t.is(prettyBytes(1e30, {locale: 'de'}), '1.000.000 YB'); // German: dots as thousands separator
t.is(prettyBytes(1e30, {locale: 'en'}), '1,000,000 YB'); // English: commas
If no locale is specified or locale: false, the number formatting is not localized [index.js:L55-L65].
FOLLOW_UPS:
- How does the library handle fraction digits with locale?
- What happens when you pass an invalid locale string?
- Does binary mode support locale formatting?
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.