RepoPilot

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

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

Question

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

RepoPilot

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

According to the API documentation in [readme.md:L58-L70], the bits option is a boolean that defaults to 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:

import prettyBytes from 'pretty-bytes';

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

The implementation in [index.js:L135-L137] uses this option to select the appropriate units:

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

So when bits: true is passed, it uses BIT_UNITS (or BIBIT_UNITS if binary mode is also enabled) instead of the default byte units.

FOLLOW_UPS:

  • What units are used for bits and bytes?
  • Can you combine bits option with binary option?
  • How does the signed option work?

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.