Formats a byte count for human reading.
- Home: https://github.com/twhb/format-bytes.js
- npm: format-bytes
formatBytes(8) === '8 bytes';
formatBytes(3171) === '3.17 KB';
formatBytes(Number.MAX_SAFE_INTEGER) === '9.01 PB';
formatBytes(Number.MAX_VALUE) === '1.80 × 10^308 bytes';
Returns a string representing bytes
for human reading. Uses the units bytes
, KB
, MB
… YB
, with larger numbers in scientific notation. Rounding may occur.
bytes: An integer >= 0, the byte count to format.