pretty-metric

2.0.0 • Public • Published

pretty-metric Build Status

Parse, convert, and humanize metric sizes

Install

$ npm install pretty-metric

Usage

const prettyMetric = require('pretty-metric')

prettyMetric(1500).km()
// => 1.5km

prettyMetric(1500000).humanize()
// => 1,500km

prettyMetric(1500).humanize()
// => 1.5km

prettyMetric(.4).humanize()
// => 40cm

// Using input types
prettyMetric(150).input('cm').humanize()
// => 1.5m

prettyMetric(0.5).input('cm').humanize()
// => 5mm

Functions

.km(), .hm(), .dam(), .m(), .dm(), .cm(), .mm()

Converts the input measurement to the corresponding output

Default input measurement type is meter. It can be changed with .input()

prettyMetric(1500).km()
// => 1.5km

prettyMetric(1).mm()
// => 1000m

humanize()

Converts the input value to a more human recognizable size

This method will automatically add commas to the output string as follows:

100000 => 100km
1000000 => 1,000km
10000000 => 10,000km
prettyMetric(150).humanize()
// => 1.5m

input()

Sets the input value to a particular metric

This can be chained with humanize()

prettyMetric(1500).input('cm').km()
// => 0.015km

prettyMetric(1500).input('mm').humanize()
// => 1.5m

Supported sizes

km:  kilometer  - 1000m
hm:  hectometer - 100m
dam: decameter  - 10m
m:   meter      - 1m
dm:  decimeter  - .1m
cm:  centimeter - .01m
mm:  millimeter  - .001m

License (MIT)

Package Sidebar

Install

npm i pretty-metric

Weekly Downloads

63

Version

2.0.0

License

MIT

Unpacked Size

20.4 kB

Total Files

7

Last publish

Collaborators

  • stevelacy
  • yocontra