RepoPilot

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

About sindresorhus/pretty-bytes · 2 messages · last activity 5/25/2026

Question

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

RepoPilot

Yes, there is a bits option to display in bits instead of bytes.

According to 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, which can be useful when referring to bit rate.

Example usage from the README:

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

In the code, the bits option is checked in the main function [index.js:L139-L141] to determine which unit constants to use:

const UNITS = options.bits
	? (options.binary ? BIBIT_UNITS : BIT_UNITS)
	: (options.binary ? BIBYTE_UNITS : BYTE_UNITS);

The test file shows various examples, including [test.js:L141-L151] where it demonstrates that values like 1337 with {bits: true} produce output like '1.34 kbit'.

FOLLOW_UPS:

  • What units are used for binary bits?
  • How does the bits option interact with locale?
  • Can you combine bits with signed option?

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.