nano-human-bytes
v1.0.1
Published
Human-readable byte formatting with parsing and locale support
Maintainers
Readme
nano-human-bytes
A tiny utility to format and parse byte values (e.g., 1024 -> 1 KB).
Installation
pnpm add nano-human-bytes
# or
npm install nano-human-bytesUsage
import { formatBytes, parseBytes } from 'nano-human-bytes';
// Format
formatBytes(1024); // '1 KB'
formatBytes(1536, { decimals: 2 }); // '1.50 KB'
formatBytes(1000, {bits: true}); // '8 Kb' (approx)
// Parse
parseBytes('1 KB'); // 1024
parseBytes('1.5 MB'); // 1572864API
formatBytes(bytes, options?)
decimals: number (default: 2)bits: boolean (default: false) - output bitsunitDisplay: 'short' | 'long' (default: 'short')space: boolean (default: true)locale: string (optional)
parseBytes(string)
Returns number or null if invalid.
License
MIT
