pretty-bytes is a JavaScript utility for converting raw byte counts into compact, human-readable size strings. It uses decimal SI units by default, turning values such as 1337 bytes into 1.34 kB. The library can display bits instead of bytes and can switch to binary prefixes such as KiB when appropriate. Signed output is available for showing positive or negative size differences. Formatting can be localized, and developers can control fractional digits, spacing, and non-breaking spaces. Fixed-width output can align values neatly in tables, status displays, and progress interfaces. The function accepts both regular numbers and BigInt values, making it suitable for a wide range of file-size and data-rate displays.
Features
- Human-readable byte formatting
- Bit and byte output modes
- Decimal and binary unit prefixes
- Localized number formatting
- Configurable precision and spacing
- Fixed-width aligned output