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);
More commonly, you will use the line item/product functions or to generate units for select boxes
UnitsHelper.perAcreCost(product, item, acres)
UnitsHelper.listAvailableUnits(product)
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()
amount.isCompatible('lbs')
const gal = new Units(1, 'gal');
const gallon = new Units(1, 'gallon');
const gallons = new Units(1, 'gallons');
Units.selectableUnits('liquid')
Units.isCompatible('g', 'lb')
Units.isCompatible(gallon, 'lb')
Units.isCompatible(gal, gallon)
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
npm publish --access public
yarn publish --access public
License
This project is MIT licensed