@suzukihayate/humanun
v0.1.0
Published
Format AND parse human-friendly bytes, durations and numbers. Round-trippable, zero dependencies.
Downloads
35
Maintainers
Readme
humanun
Format and parse human-friendly bytes, durations and numbers — round-trippable, zero dependencies.
Most libraries only format (number → string). humanun goes both ways, so parse(format(x)) gives you back x for clean values.
- Zero dependencies, typed (TypeScript), ESM — Node / Deno / Bun / browser
- Bytes (SI or binary), durations, compact numbers
Install
npm install @suzukihayate/humanunUsage
import { bytes, parseBytes, duration, parseDuration, number, parseNumber } from '@suzukihayate/humanun';
bytes(1500); // "1.5 kB"
bytes(1572864, { binary: true }); // "1.5 MiB"
parseBytes('1.5 MB'); // 1500000
parseBytes('1536 KiB'); // 1572864
duration(5400000); // "1h 30m"
parseDuration('1h30m'); // 5400000
parseDuration('2.5h'); // 9000000
number(1500); // "1.5K"
parseNumber('2.3M'); // 2300000
parseNumber('1,500'); // 1500API
bytes(n, { binary?, decimals?, space? })/parseBytes(str)duration(ms, { parts? })/parseDuration(str)(units: ms, s, m, h, d, w)number(n, { decimals? })/parseNumber(str)(K, M, B, T)
parseBytes understands both SI (kB, MB) and binary (KiB, MiB) suffixes, so parsing is always unambiguous.
Test
node --testLicense
MIT © 2026 Hayate Suzuki
