Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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
  • Socket score

Version published
Weekly downloads
226K
increased by6.63%
Maintainers
1
Weekly downloads
 
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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc