Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmandel/ucum.js
JavaScript library for unitsofmeasure.org (UCUM)
https://github.com/jmandel/ucum.js
Last synced: 19 days ago
JSON representation
JavaScript library for unitsofmeasure.org (UCUM)
- Host: GitHub
- URL: https://github.com/jmandel/ucum.js
- Owner: jmandel
- Created: 2014-07-10T22:21:16.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-12T17:18:00.000Z (over 8 years ago)
- Last Synced: 2024-10-06T15:39:05.735Z (about 1 month ago)
- Language: JavaScript
- Size: 86.9 KB
- Stars: 24
- Watchers: 6
- Forks: 6
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ucum.js
JavaScript implementation of UCUM (http://unitsofmeasure.org)## Units conversion
`ucum.convert`: Convert a value (represented as a Javascript Number) from one UCUM unit (represented as a case-sensitive UCUM string) to another, assuming they are conformant.
```
var one_inch = ucum.convert(2.54, 'cm', '[in_i]');
console.log(one_inch)1
```## Units parsing
`ucum.parse`: Parse a string into a ucum.js JSON representation (an object with `value` as a Number, and `units` as an Object where keys are case-sensitive UCUM unit names and values are integers representing an exponent).
```
var parsed = ucum.parse('km/h');
console.log(parsed);{ value: 1000, units: { m: 1, h: -1 } }
```## Units canonicalization
`ucum.canonicalize`: Parse a string into a ucum.js JSON representation (an object with `value` as a Number, and `units` as an Object where keys are case-sensitive UCUM unit names and values are integers representing an exponent), and convert this to an expression where all `units` properties are reduced to the following base units: meter, second, gram, radian, kelvin, coulomb, candela.
```
var canonical = ucum.canonicalize('[in_i]/a');
console.log(canonical);{ value: 8.048774304763354e-10, units: { m: 1, s: -1 } }
```### To use in browser
Save and include a `` tag for [dist/ucum.js](dist/ucum.js)
### To use in Node.js
```
npm install ucum.js
```### To build
```
$ git clone https://github.com/jmandel/ucum.js
$ cd ucum.js
$ npm install
$ make
```