@arraypress/file-size
v1.0.0
Published
Format byte counts as human-readable file sizes.
Maintainers
Readme
@arraypress/file-size
Format byte counts as human-readable file sizes. One function, zero dependencies.
Installation
npm install @arraypress/file-sizeUsage
import { 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'API
formatSize(bytes, decimals?)
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.
License
MIT
