GithubHelp home page GithubHelp logo

mvasilkov / human-readable Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 1.0 47 KB

Presenting values in human-readable form.

License: MIT License

JavaScript 33.21% TypeScript 66.79%
typescript formatting iec jedec readable

human-readable's Introduction

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

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

human-readable's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sayag11

human-readable's Issues

Support for React / JSX

Render something along the lines of:

<span className="number">1<span> <span className="symbol">GiB<span>

This will allows e.g. making the unit symbol bold.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.