Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yannickdot/measurement
📏 - measurement API for JavaScript (inspired from the Foundation framework in Swift 3)
https://github.com/yannickdot/measurement
Last synced: about 6 hours ago
JSON representation
📏 - measurement API for JavaScript (inspired from the Foundation framework in Swift 3)
- Host: GitHub
- URL: https://github.com/yannickdot/measurement
- Owner: YannickDot
- License: mit
- Created: 2016-08-06T22:03:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-08-17T07:53:19.000Z (about 8 years ago)
- Last Synced: 2024-11-07T00:48:39.671Z (about 22 hours ago)
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Measurement
📏 - A nice measurement API for JavaScript (inspired from the new Foundation framework in Swift 3)
### Features
- works with any framework
- built for speed
- no deps!
- immutable by design### Installation
```sh
$ npm install measurement-js --save
```## Usage
```js
import {Measurement, UnitMass, UnitDuration} from 'measurement'const weightKilograms = Measurement(75.0, UnitMass.kilograms)
const pomodoroMinutes = Measurement(25.0, UnitDuration.minutes)weightKilograms.toString()
// => 75kgconst weightPounds = weightKilograms.convertTo(UnitMass.pounds)
weightPounds.toString()
// => 165.34683151378331lbspomodoroMinutes.toString()
// => 25minconst pomodoroSeconds = pomodoroMinutes.convertTo(UnitDuration.seconds)
pomodoroSeconds.toString()
// => 1500sconst t0 = Measurement(60.0, UnitDuration.minutes)
const t1 = Measurement(1.0, UnitDuration.hours)t1.equals(t0)
// => true
```## API
### myWeight = Measurement(value, unit)
Initialize a new measurement object named 'myWeight' with a Unit and a Value.### myWeight.convertTo(newUnit)
Creates a new measurment object whose value is the value of myWeight in myWeight's unit converted to the new unit passed as parameter### volumeOne.equals(volumeTwo)
Compares two measurements that represent the same type of metric (eg. Mass, Volume, Duration, etc.)## Supported metrics
* Mass (as `UnitMass`)
* Volume (as `UnitVolume`)
* Duration (as `UnitDuration`)## Tests
```sh
$ npm test
```## Contributing
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.