uno-it
v1.0.0
Published
Sum a string of multiple units into one single unit
Downloads
1
Maintainers
Readme
uno-it
Sum a string of multiple units into one single unit.
unoIt('cm in ft', 'ft') => ∑(ft)
uno-it
is built on top of convert-unit for its conversions. Unfortunately, uno-it
currently doesn't account for significant figures (soon to come), and is under the assumption that the inputs are of infinite precision.
Install
$ npm install --save uno-it
Usage
const unoIt = require('uno-it');
unoIt('20ft 9cms 1 inch 200 m', 'm');
//=> 206.21
unoIt('90 ml 10l', 'l');
//=> 10.09
unoIt('90.17 kg 1 lb 100 g', 'kg');
//=> 90.72
Possible Measurements
As long as the base of the measurements are defined, it will be evaluated properly.
IE: "ins" == "in", "mg" == "mgs"
- mass: mcg, mg, g, kg, oz, lb
- volume: ml, l, tsp, tbsp, fl-oz, cup, pnt, qt, gal
- length: mm, cm, m, in, ft, mi
API
unoIt(input, desiredUnit [, options])
input
Type: <string>
The string containing multiple units of the same type.
IE: "1 cup 10 qt 9 pnt 2 gal"
desiredUnit
Type: <string>
The desired unit to convert the string to.
options
round
Type: <boolean>
Default: 2
The decimal value to round the result to.
type
Type: <string>
("volume", "mass", "length")
By default uno-it
will attempt to match the first value as the measurement type. However, for faster processing, the type can be specified.
License
MIT © Brandon Him