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 5/18/2026
Question
RepoPilot
Yes, pretty-bytes respects the user's locale for number formatting through the locale option.
The toLocaleString function [index.js:L55-L65] handles locale-aware formatting by calling JavaScript's native Number.toLocaleString() method:
const toLocaleString = (number, locale, options) => {
let result = number;
if (typeof locale === 'string' || Array.isArray(locale)) {
result = number.toLocaleString(locale, options);
} else if (locale === true || options !== undefined) {
result = number.toLocaleString(undefined, options);
}
return result;
};
The locale option supports three modes [README]:
false(default): No localizationtrue: Uses the system/browser localestringorstring[]: Uses a specific BCP 47 language tag (e.g.,'de','en')
For example, the tests [test.js:L71-L110] demonstrate this:
- German locale:
prettyBytes(1001, {locale: 'de'})→'1 kB'(with German number formatting) - English locale:
prettyBytes(1001, {locale: 'en'})→'1 kB'(with English number formatting)
This affects not just the number itself but also thousand separators and decimal separators based on locale conventions.
FOLLOW_UPS:
- What formatting options control decimal precision?
- How does the
signedoption work with locales? - Can you use both binary and locale options together?
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.