Format byte counts as human-readable file sizes. One function, zero dependencies.
npm install @arraypress/file-sizeimport { formatSize } from '@arraypress/file-size';
formatSize(0) // '0 B'
formatSize(1024) // '1.0 KB'
formatSize(52428800) // '50.0 MB'
formatSize(1073741824) // '1.0 GB'
formatSize(1099511627776) // '1.0 TB'
// Custom decimal places
formatSize(1536, 2) // '1.50 KB'
formatSize(1536, 0) // '2 KB'Returns a human-readable string. Uses binary units (1 KB = 1024 bytes). Bytes are shown without decimals, larger units default to 1 decimal place. Returns empty string for null/undefined/negative values.
MIT