Package Exports
- human-readable
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (human-readable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
human-readable
Presenting values in human-readable form.
Installation
npm add human-readableUsage
Size formatter
import { sizeFormatter } from 'human-readable'
const format = sizeFormatter({
std: 'JEDEC', // 'SI' (default) | 'IEC' | 'JEDEC'
decimalPlaces: 2,
keepTrailingZeroes: false,
render: (literal, symbol) => `${literal} ${symbol}B`,
})
format(4096) // '4 KB'
const defaults = sizeFormatter()
defaults(4096) // '4.1 kB'Duration formatter
import { durationFormatter } from 'human-readable'
const span = Date.now() - Date.parse('2019-01-01T09:00:00.000+0200')
const format = durationFormatter({
// 'y' | 'mo' | 'w' | 'd' | 'h' | 'm' | 's' | 'ms'
allowMultiples: ['y', 'mo', 'd'],
keepNonLeadingZeroes: false, // E.g. '1y 0mo 0d'
})
format(span) // '1y 1mo 19d'
const defaults = durationFormatter()
defaults(span) // '1y 1mo 19d 19h 41m 48s'Disk size units
| Decimal | SI | Binary | IEC | JEDEC |
|---|---|---|---|---|
| (103)1 | kB | (210)1 | KiB | KB |
| (103)2 | MB | (210)2 | MiB | MB |
| (103)3 | GB | (210)3 | GiB | GB |
| (103)4 | TB | (210)4 | TiB | TB |
| (103)5 | PB | (210)5 | PiB | PB |
License
MIT