pretty-metric
Parse, convert, and humanize metric sizes
Last updated 8 months ago by stevelacy .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install pretty-metric 
SYNC missed versions from official npm registry.

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)

Current Tags

  • 1.1.1                                ...           latest (8 months ago)

3 Versions

  • 1.1.1                                ...           8 months ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |