@ucropit/unit-system
TypeScript icon, indicating that this package has built-in type declarations

1.0.22 • Public • Published

Unit System Converter

Package to manage unit convertion in ucropit's core for diferent systems

Installation

First install Node.js. Then:

$ npm install @ucropit/unit-system

Importing

// Using Node.js `require()`
const unitSystemConverter = require('@ucropit/unit-system');

// Using ES6 imports
import * as unitSystemConverter from '@ucropit/unit-system';
// Or
import { convertUnits, convertPay, convertSupplyUnits, convertBuToLb } from '@ucropit/unit-system';

Convert units from metric or imperial systems

import { convertUnits } from '@ucropit/unit-system';
const quantity = 3000;
const fromUnit = 'kg';
const toUnit = 'lb';

const result: number = convertUnits(quantity, fromUnit, toUnit);

Convert supply units from metric to imperial or vice versa

import { convertSupplyUnits, IConvertedResult } from '@ucropit/unit-system';
const quantity = 150;
const fromUnit = 'bl';

const result: IConvertedResult = convertSupplyUnits(quantity, fromUnit);

Convert pay units from metric to imperial or vice versa

import { convertPay, IConvertedResult } from '@ucropit/unit-system';
const quantity = 3000;
const fromUnit = 'kg/ha';
const equivalence = 60; //optional

const result: IConvertedResult = convertPay(quantity, fromUnit, equivalence);

Convert unit custom

import { convertUnitFromTo, IConvertedResult, convertAnyUnitFromTo } from '@ucropit/unit-system';
const quantity = 3000
const fromUnit = 'bu'
const toUnit = 'kg'
const equivalence = 1 //optional
const cropType='soy' //optional if toUnit is bu or bu/ac set cropType
const inverse = false

const result: IConvertedResult = convertUnitFromTo({quantity, fromUnit, toUnit, equivalence, cropType, inverse})

//use convertsUnits joined with convertUnitFromTo
const resultAny: IConvertedResult = convertUnitFromTo({quantity, fromUnit, toUnit, equivalence, cropType})

Convert unit bu to lb

import { convertUnitFromTo, IConvertedResult, convertBuToLb} from '@ucropit/unit-system';
const quantity = 3000
const cropType='soy' 
const returnedUnit='LB' //optional if toUnit is bu or bu/ac set cropType

const result: IConvertedResult = convertBuToLb({quantity, cropType, returnedUnit})

License

MIT License

Copyright (c) 2022 Ucropit

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

/@ucropit/unit-system/

    Package Sidebar

    Install

    npm i @ucropit/unit-system

    Weekly Downloads

    63

    Version

    1.0.22

    License

    ISC

    Unpacked Size

    253 kB

    Total Files

    164

    Last publish

    Collaborators

    • arqui78
    • ucropit
    • gabojaime
    • roiner123
    • jjtc07