Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brh55/uno-it
:heavy_plus_sign: Sum a string of multiple units into one single unit
https://github.com/brh55/uno-it
mass measurements sum-values units-of-measure volume
Last synced: 24 days ago
JSON representation
:heavy_plus_sign: Sum a string of multiple units into one single unit
- Host: GitHub
- URL: https://github.com/brh55/uno-it
- Owner: brh55
- License: mit
- Created: 2017-02-08T18:37:27.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-09T09:12:42.000Z (about 8 years ago)
- Last Synced: 2025-01-01T04:46:13.596Z (about 2 months ago)
- Topics: mass, measurements, sum-values, units-of-measure, volume
- Language: JavaScript
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# uno-it [](https://travis-ci.org/brh55/uno-it) [](https://github.com/sindresorhus/xo)
> 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](https://www.npmjs.com/package/convert-units) 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
```js
const unoIt = require('uno-it');unoIt('20ft 9cms 1 inch 200 m', 'm');
//=> 206.21unoIt('90 ml 10l', 'l');
//=> 10.09unoIt('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: [``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
The string containing multiple units of the same type.
`IE: "1 cup 10 qt 9 pnt 2 gal"`
#### desiredUnit
Type: [``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
The desired unit to convert the string to.
#### options
##### round
Type: [``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
Default: `2`The decimal value to round the result to.
#### type
Type: [``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) *("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](https://github.com/brh55)