RepoPilot

Is there an option to display in bits instead of bytes?

About sindresorhus/pretty-bytes · 2 messages · last activity 6/29/2026

Question

Is there an option to display in bits instead of bytes?

RepoPilot

Yes, there is. The bits option allows you to format the number as bits instead of bytes.

From the API documentation [readme.md:L59-L72], the bits option:

  • Type: boolean
  • Default: false
  • Purpose: Format the number as bits instead of bytes. This can be useful when referring to bit rate.

Example usage:

prettyBytes(1337, {bits: true});
//=> '1.34 kbit'

When you set bits: true, the library uses different unit arrays. Looking at the implementation [index.js:L6-L37], there are separate unit definitions: BIT_UNITS for standard bit formatting and BIBIT_UNITS for binary bit formatting. The main function selects the appropriate units based on the bits and binary options [index.js:L137-L140].

FOLLOW_UPS:

  • How does the binary option differ from bits?
  • What units are used for bit formatting?
  • Can I combine bits with binary prefix 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.