Presenting values in human-readable form.
npm install human-readablehuman-readable
===
Presenting values in human-readable form.
[![npm][npm-badge]][npm-url]
[![no dependencies][dependencies-badge]][dependencies-url]
---
Installation
---
``sh`
npm add human-readable
Usage
---
`javascript
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'
`
`javascript
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][si] | Binary | [IEC][iec] | [JEDEC][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
[npm-badge]: https://img.shields.io/npm/v/human-readable.svg?style=flat
[npm-url]: https://www.npmjs.com/package/human-readable
[dependencies-badge]: https://img.shields.io/david/mvasilkov/human-readable?style=flat
[dependencies-url]: https://www.npmjs.com/package/human-readable?activeTab=dependencies
[iec]: http://www.electropedia.org/iev/iev.nsf/display?openform&ievref=112-01-27
[si]: http://www.electropedia.org/iev/iev.nsf/display?openform&ievref=112-02-03
[jedec]: https://www.jedec.org/standards-documents/dictionary/terms/kilo-k-prefix-units-semiconductor-storage-capacity