https://github.com/vaporyjs/vaporyjs-units
Unit conversion utility.
https://github.com/vaporyjs/vaporyjs-units
vaporyjs
Last synced: 4 months ago
JSON representation
Unit conversion utility.
- Host: GitHub
- URL: https://github.com/vaporyjs/vaporyjs-units
- Owner: vaporyjs
- License: mit
- Created: 2018-03-04T04:43:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T05:04:44.000Z (over 2 years ago)
- Last Synced: 2024-04-24T21:43:40.255Z (about 1 year ago)
- Topics: vaporyjs
- Language: JavaScript
- Homepage: https://vapory.org
- Size: 229 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# vaporyjs-units
[](https://www.npmjs.org/package/vaporyjs-units)
[](https://travis-ci.org/vaporyjs/vaporyjs-units)
[](https://coveralls.io/r/vaporyjs/vaporyjs-units)
[](https://gitter.im/vapory/vaporyjs-lib) or #vaporyjs on freenodeUnit conversion utility.
There are two methods:
- `convert(value, unitFrom, unitTo)` - convert a value between two units
- `lazyConvert(value, unitTo)` - include unit type in the input and the outputThe `value` and the output in all cases is a string.
## Examples
```js
Units.convert('1', 'vap', 'wei') // '1000000000000000000'
Units.convert('1', 'wei', 'vap') // '0.000000000000000001'
Units.convert('1', 'finney', 'vap') // '0.001'Units.lazyConvert('1 vap', 'wei') // '1000000000000000000 wei'
Units.lazyConvert('1 wei', 'vap') // '0.000000000000000001 vap'
Units.lazyConvert('1 finney', 'vap') // '0.001 vap'
```## Units
Units are defined in `units.json`. It is compatible with [web3.js](https://github.com/vaporyco/web3.js) and additionally includes `VAP`.