convert-units

Convert between quantities in different units

``npm install convert-units``

convert-units

A handy utility for converting between quantities in different units.

Usage

`convert-units` has a simple chained API that is easy to read.

Here's how you move between the metric units for volume:

``````var convert = require('convert-units')

convert(1).from('ltr').to('ml')
// 1000
``````

Jump from imperial to metric units the same way:

``````convert(1).from('lb').to('kg')
// 0.4536... (tested to 4 significant figures)
``````

Just be careful not to ask for an impossible conversion:

``````convert(1).from('oz').to('fl-oz')
// throws -- you can't go from mass to volume!
``````

You can get a list of the measurement types supported with `.measures`

``````convert().measurements()
// [ 'mass', 'volume' ]
``````

If you ever want to know the possible conversions for a unit, just use `.possibilities`

``````convert().from('ltr').possibilities()
// [ 'ml', 'ltr', 'tsp', 'tbsp', 'fl-oz', 'cup', 'pnt', 'qt', 'gal' ]

convert().from('kg').possibilities()
// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb' ]
``````

You can also get the possible conversions for a measure:

``````convert().possibilities('mass')
// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb' ]
``````

To get a detailed description of a unit, use `describe`

``````convert().describe('kg')
/*
{
measure: 'mass'
, system: 'metric'
, singular: 'Kilogram'
, plural: 'Kilograms'
}
*/
``````

Supported Units

• ml
• ltr
• tsp
• tbsp
• fl-oz
• cup
• pnt
• qt
• gal

• mcg
• mg
• g
• kg
• oz
• lb

Want More?

Adding new measurement sets is easy. Take a look at `lib/definitions` to see how it's done.