Is there an option to display in bits instead of bytes?
Is there an option to display in bits instead of bytes?
About sindresorhus/pretty-bytes · 2 messages · last activity 7/6/2026
Yes, there is. The bits option allows you to format the number as bits instead of bytes.
According to the API documentation in the README, the bits option is a boolean with a default value of false. When set to true, it formats the number as bits instead of bytes.
Here's an example from the README:
prettyBytes(1337, {bits: true});
//=> '1.34 kbit'
In the implementation [index.js:L139-L141], the code selects between different unit arrays based on this option:
const UNITS = options.bits
? (options.binary ? BIBIT_UNITS : BIT_UNITS)
: (options.binary ? BIBYTE_UNITS : BYTE_UNITS);
The BIT_UNITS array [index.js:L26-L34] contains units like 'b', 'kbit', 'Mbit', etc., while BIBIT_UNITS [index.js:L36-L44] contains binary bit units like 'b', 'kibit', 'Mibit', and so on.
FOLLOW_UPS:
- What's the difference between binary and non-binary formatting?
- How does the signed option work with bits?
- Can I customize the units used in formatting?
Want to ask your own question?
Open chat for sindresorhus/pretty-bytesPublic 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.