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 6/1/2026
Yes, there is. The bits option allows you to format the number as bits instead of bytes.
According to the API documentation [readme.md:L46-L85], 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, which can be useful when referring to bit rate.
Here's an example from the documentation [index.d.ts:L161-L177]:
prettyBytes(1337, {bits: true});
//=> '1.34 kbit'
The test file [test.js:L141-L180] shows additional examples of the bits option in action, demonstrating that values below 1000 bits display as b (e.g., '0.7 b'), while larger values use the appropriate prefix like '1 kbit' or '10 Pbit'.
FOLLOW_UPS:
- How does the binary option differ from bits option?
- What are the available unit prefixes for bits?
- Can bits and binary options be used 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.