@nlib/human-readable

Converts an integer to a human readable format

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
00Mar 18, 2019Nov 17, 2017Minified + gzip package size for @nlib/human-readable in KB

Readme

@nlib/human-readable

Build Status Build status codecov dependencies Status devDependencies Status

Converts an integer to a human readable format.

Install

npm install @nlib/human-readable

Usage

const console = require('console');
const humanReadable = require('@nlib/human-readable');
console.log(humanReadable(1000));
// 1K
console.log(humanReadable(1000000));
// 1M

Javascript API

humanReadable(size: Number, options: ?Object]) → String

  • size: An integer to be converted.
  • options: configures behavior.
    • round: Function. The default value is Math.round.
    • base: Number. The default value is 1000. humanReadable(2048, {base: 1024}) → '2.0K'.
    • digits: Number. The default value is 1. humanReadable(2000, {digits: 3}) → '2.000K'.
    • prefix: array-like. The default value is ' KMGTPEZY'. humanReadable(2000, {prefix: [, 'Kilo']}) → '2.0Kilo'.
    • negativePrefix: array-like. The default value is ' mμnpfazy'. humanReadable(0.02, {negativePrefix: [, 'milli']}) → '20milli'.

LICENSE

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.