An open API service indexing awesome lists of open source software.

https://github.com/mvasilkov/human-readable

Presenting values in human-readable form.
https://github.com/mvasilkov/human-readable

formatting iec jedec readable typescript

Last synced: 12 months ago
JSON representation

Presenting values in human-readable form.

Awesome Lists containing this project

README

          

human-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
---

### Size formatter

```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'
```

### Duration formatter

```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