1.4.5 • Published 3 years ago

@harvest-profit/units v1.4.5

Weekly downloads
67
License
MIT
Repository
github
Last release
3 years ago

npm Build Status codecov npm

Installation

To add this package to your project

yarn add @harvest-profit/units

To use, try the following:

import UnitsHelper from '@harvest-profit/units'

const isCompatibleUnit = UnitsHelper.isCompatibleUnit('lbs', 'tons');
console.log(isCompatibleUnit); // true

More commonly, you will use the line item/product functions or to generate units for select boxes

UnitsHelper.perAcreCost(product, item, acres) // 3.50
UnitsHelper.listAvailableUnits(product) // ['gallons', 'floz', 'milliliters', ...]

All of this is build off of the Units object and a set of definitions declared in this repo. You can use this object to handle any conversions or any other interaction with those units.

import { Units } from '@harvest-profit/units';

const amount = new Units(1, 'gallon');
amount.to('pints').toNumber() // 8 pints

amount.isCompatible('lbs') // false


// Can use any different name. If a name is missing, just add it to the aliases in the definition in a PR
const gal = new Units(1, 'gal');
const gallon = new Units(1, 'gallon');
const gallons = new Units(1, 'gallons');

Units.selectableUnits('liquid') // ['gallons', 'floz', 'milliliters', ...]

Units.isCompatible('g', 'lb') // true
Units.isCompatible(gallon, 'lb') // false
Units.isCompatible(gal, gallon) // true

Development

To deploy a new version to NPM, bump the version number, commit/merge to master, and run the following:

yarn run clean
yarn run build

# Either NPM
npm publish --access public
# Or Yarn, they do the same thing
yarn publish --access public

License

This project is MIT licensed

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

6 years ago

1.2.1-alpha.2

6 years ago

1.2.1-alpha.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago