🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

human-readable

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

human-readable

Presenting values in human-readable form.

0.2.1
latest
Source
npm
Version published
Maintainers
1
Created
Source

human-readable

Presenting values in human-readable form.

npm no dependencies

Installation

npm add human-readable

Usage

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

DecimalSIBinaryIECJEDEC
(103)1kB(210)1KiBKB
(103)2MB(210)2MiBMB
(103)3GB(210)3GiBGB
(103)4TB(210)4TiBTB
(103)5PB(210)5PiBPB

License

MIT

Keywords

format

FAQs

Package last updated on 21 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts