JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 80392
  • Score
    100M100P100Q152655F
  • License ISC

Converts a number to/from a human readable string: `1337` ↔ `1.34kB`

Package Exports

  • human-format

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (human-format) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

human-format

Build Status Dependency Status devDependency Status

Converts a number to/from a human readable string: 13371.34kB

Install

Download manually or with package-manager.

npm

npm install --save human-format

bower

bower install --save human-format

Usage

Formatting

humanFormat(1337)
//=> '1.34 k'

// The number of decimals can be changed.
humanFormat(1337, {
  decimals: 1
})
//=> '1.3 k'

// Units and scales can be specified.
humanFormat(65536, {
    scale: 'binary',
    unit: 'B'
})
//=> 64 kiB

// A custom seperator can be specified.
humanFormat(1337, {
  seperator: ' - '
})
//=> 1.34 - k

// Custom scales can be created!
var timeScale = new humanFormat.Scale({
    seconds: 0,
    minutes: 60,
    hours: 3600,
    days: 86400,
    months: 2592000,
})
humanFormat(26729235, { scale: timeScale })
//=> 10.31 months

// You can force a prefix to be used.
humanFormat(100, { unit: 'm', prefix: 'k' })
//=> 0.1 km

// You can access the raw result.
humanFormat.raw(100, { prefix: 'k' })
//=> {
//   prefix: 'k',
//   value: 0.09999999999999999 // Close value, not rounded.
// }

Parsing

humanFormat.parse('1.34 kiB', { scale: 'binary' })
//=> 1372.16

// You can access the raw result.
humanFormat.parse.raw('1.34 kB')
//=> {
//  factor: 1000,
//  prefix: 'k',
//  unit: 'B',
//  value: 1.34
//}

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

Contributors:

  • @sweetpi
  • @Itay289
  • @qrohlf

License

ISC © Julien Fontanet