npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kinaxis/unit-of-measure

v1.0.10

Published

Helper functions for applying unit of measure conversions.

Downloads

5

Readme

unit-of-measure

Helper functions for applying unit of measure conversions.

Documentation

Types

ControlSet

A grouping of RapidResponse control table settings.

To use RapidResponse control sets in an embedded algorithm, the algorithm must have appropriate dependencies on the ControlSet table.

For more information about control tables and control sets, see https://help.kinaxis.com/20162/GlobalHelp/Content/RR_Integration/Data_model_and_Integration/Control_tables_and_control_sets.htm.

|Property |Type |Description| |--------------|--------|-----------| |Value |string|The name of the control set.|


UnitOfMeasure

Defines the magnitude of a RapidResponse quantity with respect to the base unit of measure.

To use RapidResponse units of measure in an embedded algorithm, the algorithm must have appropriate dependencies on the UnitOfMeasure table.

|Property |Type |Description| |--------------|------------|-----------| |Value |string |The name of the unit of measure.| |BaseConversion|number |The factor to use when converting from the base unit of measure.| |ControlSet |ControlSet|The unit of measure's control set.|


ItemSpecificUOMConversion

A unit of measure used on an individual item basis, rather than for all items. This is used to override the standard conversion rate.

|Property |Type |Description| |-------------|---------------|-----------| |UnitOfMeasure|UnitOfMeasure|The unit of measure to override.| |Factor |number |The factor to use when converting from the base unit of measure.|


NumberUoM

A converted quantity with its associated unit of measure.

|Property |Type |Description| |---------------|-----------------------------------------|-----------| |Number |number |The converted quantity.| |UnitOfMeasure |UnitOfMeasure |The unit of measure of Number.| |IsMoney |boolean |Whether or not Number is a money value.| |ItemSpecificUoM|ItemSpecificUOMConversion[] | undefined|Optional list of units of measure to override when doing conversions.|


Functions

GetTargetUoM(tables, uom, controlSet)

Retrieves a specific unit of measure.

For example, a user may want to retrieve the unit of measure for "Milliliter" in the "Volume" control set. The output would resemble

{
    Value: "Milliliter",
    BaseConversion: 0.001,
    ControlSet: { Value: "Volume" }
}

|Argument |Type |Description| |----------|------------|-----------| |tables |Tables |All global tables. Currently this function only looks at the UnitOfMeasure table. A global dependency on the Mfg::UnitOfMeasure table and Core::ControlSet is required to use this library.| |uom |string |A string representing the desired unit of measure (e.g., "Milliliter"). This string parameter is analogous to the "Value" string key field in the Mfg::UnitOfMeasure table.| |controlSet|ControlSet|The control set related to the desired unit of measure (e.g., "Volume"). This control set parameter is analogous to the reference key field in the Mfg::UnitOfMeasure table.|

Return value: A UnitOfMeasure object which matches uom and controlSet. If a unit of measure can not be found based on the given uom and controlSet, undefined is returned.


ConvertUoM_Quantity(uom, tables, targetUoM)

Converts a quantity value from a given unit of measure to another unit of measure.

For example, a user may want to convert 5 Liters into Milliliters. One would expect the result to be 5000 Millilitres.

|Argument |Type |Description| |---------|-----------|-----------| |uom |NumberUoM|A quantity value with an associated unit of measure. Example: { Number: 5, UnitOfMeasure: { Value: "Liter", BaseConversion: 1, ControlSet: { Value: "Volume" } }, IsMoney: false }. The example illustrates 5 Liters.| |tables |Tables |All global tables. Currently this function only looks at the UnitOfMeasure table. A global dependency on the Mfg::UnitOfMeasure table and Core::ControlSet is required to use this library.| |targetUoM|string |The target unit of measure to convert the uom into. First, uom.ItemSpecificUoM is searched (if present) and then tables.UnitOfMeasures is searched if no item-specific entry for the target is found.|

Return value: The converted number with its associated unit of measure. Example:

uom = {
    Number: 5,
    UnitOfMeasure: {
        Value:"Liter",
        BaseConversion: 1,
        ControlSet: { Value: "Volume" }
    },
    IsMoney: false
};

targetUoM = "Milliliter";

returns

{
    Number: 5000,
    UnitOfMeasure: {
        Value: "Milliliter",
        BaseConversion: 0.001,
        ControlSet: {Value:"Volume"}
    },
    IsMoney:false
}
  • If the targetUoM is not found, NaN is returned as the converted value with an invalid UoM
  • If ConvertUoM_Quantity() is called with uom.IsMoney === true, an Error is thrown.
  • If the conversion ratio of the base or target unit of measure is less than or equal to zero, NaN is returned.
  • If the quantity value to convert is NaN, NaN is returned

ConvertUoM_Money(uom, tables, targetUoM)

Converts a money value from a given unit of measure to another unit of measure.

Unlike quantity, money values are only converted on a per unit cost basis. Let's assume we have a part named 'Bike' with quantity '24' each with an average selling price of '2 USD'. If we wanted to convert the quantity value (24) to Dozens, we would return 2 Dozens (2 dozen units is equal to 24 units). If we wanted to convert the money value (2USD) to Dozens we would return 24 USDs (1 dozen units is worth 24USD).

|Argument |Type |Description| |---------|-----------|-----------| |uom |NumberUoM|A money value with an associated unit of measure. Example { Number: 2, UnitOfMeasure: { Value:"Single", BaseConversion: 1, ControlSet: { Value:"Count" } }, IsMoney: true }. The example illustrates 2 units.| |tables |Tables |All global tables. Currently this function only looks at the UnitOfMeasure table. A global dependency on the Mfg::UnitOfMeasure table and Core::ControlSet is required to use this library.| |targetUoM|string |The target unit of measure to convert the uom into. First, uom.ItemSpecificUoM is searched (if present) and then tables.UnitOfMeasures is searched if no item-specific entry for the target is found.|

Return value: The converted number with its associated unit of measure. Example:

uom = {
    Number: 2,
    UnitOfMeasure: {
        Value: "Single",
        BaseConversion: 1,
        ControlSet: { Value: "Count" }
    },
    IsMoney: true
};

targetUoM = "Dozen";

returns

{
    Number: 24,
    UnitOfMeasure: {
        Value: "Dozen",
        BaseConversion: 12,
        ControlSet: {Value: "Count"}
    },
    IsMoney: true
}
  • If the targetUoM is not found, NaN is returned as the converted value with an invalid UoM
  • If ConvertUoM_Money() is called with uom.IsMoney === false, an Error is thrown.
  • If the conversion ratio of the base or target unit of measure is less than or equal to zero, NaN is returned.
  • If the money value to convert is NaN, NaN is returned.

For more information on unit of measure, see: https://help.kinaxis.com/20162/GlobalHelp/Content/RR_Admin/Client_Administration/uom_create.htm.

Please contact [email protected] if you experience any issues.

Copyright © 2022 Kinaxis. All Rights Reserved.