Skip to content

Latest commit

 

History

History
370 lines (253 loc) · 9.97 KB

api.md

File metadata and controls

370 lines (253 loc) · 9.97 KB

Modules

Serialize
Amount
Unit

Functions

getUnitsForQuantity(quantity)

Get all units registered for quantity

Serialize

Serialize.stringToUnit(unitString)

Converts a units serialized representation to it's deserialized representation

Param
unitString

Serialize.unitToString(unit)

Converts a unit to it's serialized representation

Param
unit

Serialize.amountToString(amount)

Convert an amount to it's serialized representation

Param
amount

Serialize.stringToAmount(amountString)

Convert a serialized amount to it's deserialized representation

Param
amountString

Amount

Amount.defaultComparer ⇒ number

Default comparer

Returns: number - Comparer value

Param Type Description
left Amount The left-hand amount
right Amount The right-hand amount

Amount.create(value, unit, decimalCount) ⇒ Amount.<T>

Creates an amount that represents the an exact/absolute value in the specified unit. For example if you create an exact amount of 2 degrees Fahrenheit that will represent -16.6666667 degrees Celsius.

Returns: Amount.<T> - The created amount.

Param Type Description
value number The numeric value of the amount.
unit Unit.<T> The unit of the amount.
decimalCount number | undefined The decimalCount of the amount.

Amount.toString(amount) ⇒ string

Returns a string representation of an Amount.

Returns: string - String representation of the Amount.

Param Type Description
amount Amount The amount.

Amount.neg(amount)

Negation unary operator.

Param Type Description
amount Amount.<T> The amount.

Amount.isQuantity(quantity, amount)

Determines if an Amount is of a quantity.

Param Type Description
quantity Quantity Quantity to check for.
amount Amount.<T> The amount to check.

Amount.plus(left, right) ⇒

Adds two amounts together. The two amounts amounts must have the same quantity. The resulting amount will be of the same quantity as the two amounts. The resulting amount will have it's decimal count set from the most granular amount.

Returns: left + right

Param Description
left The left-hand amount.
right The right-hand

Amount.minus(left, right) ⇒

Substracts two amounts from each other. The two amounts amounts must have the same quantity. The resulting amount will be of the same quantity as the two amounts. The resulting amount will have it's decimal count set from the most granular amount.

Returns: left + right

Param Description
left The left-hand amount.
right The right-hand

Amount.times(left, right)

Multiplies an amount with a number. The resulting amount has the same unit and decimal count as the original amount.

Param Description
left The amount to multiply
right The number to multiply with

Amount.divide(left, right)

Divides an amount with a number. The resulting amount has the same unit and decimal count as the original amount.

Param Description
left The amount to divide
right The number to divide by

Amount.equals(left, right) ⇒ boolean

Compares to amounts for equality

Returns: boolean - True if the amounts are equal, false otherwise.

Param Type Description
left Amount The left-hand Amount.
right Amount The right-hand Amount.

Amount.lessThan(left, right) ⇒ boolean

Checks if one Amount is less than another.

Returns: boolean - True if the left-hand is less than the right-hand, false otherwise.

Param Type Description
left Amount The left-hand Amount.
right Amount The right-hand Amount.

Amount.greaterThan(left, right) ⇒ boolean

Checks if one Amount is greater than another.

Returns: boolean - True if the left-hand is less than the right-hand, false otherwise.

Param Type Description
left Amount The left-hand Amount.
right Amount The right-hand Amount.

Amount.roundDown(step, amount)

Param Description
step Rounding step, for example 5.0 Celsius will round 23 to 20.
amount Amount to round.

Amount.roundUp(step, amount)

Param Description
step Rounding step, for example 5.0 Celsius will round 23 to 25.
amount Amount to round.

Amount.abs(amount)

Gets the absolute amount (equivalent of Math.Abs())

Param Description
amount The amount to get the aboslute amount from.

Amount.valueAs(toUnit, amount)

Gets the value of the amount as a number in the specified unit

Param Description
toUnit The unit to get the amount in.
amount The amount to get the value from.

Unit

Unit.One : Unit

Holds the dimensionless unit ONE

Unit.createBase(quantity, symbol)

Creates a base unit having the specified symbol.

Param Description
quantity The quantity of the resulting unit.
symbol The symbol of this base unit.

Unit.createAlternate(symbol, parent)

Creates an alternate unit for the specified unit identified by the specified symbol.

Param Description
symbol The symbol for this alternate unit.
parent Parent the system unit from which this alternate unit is derived.

Unit.times(quantity, left, right) ⇒

Returns the product of the specified units.

Returns: left * right

Param Description
quantity The quantity of the resulting unit.
left The left unit operand.
right The right unit operand.

Unit.divide(quantity, left, right) ⇒

Returns the quotient of the specified units.

Returns: left / right

Param Description
quantity The quantity of the resulting unit.
left The dividend unit operand.
right The divisor unit operand.

Unit.convert(value, fromUnit, toUnit) ⇒

Converts numeric values from a unit to another unit.

Returns: The converted numeric value.

Param Description
value The numeric value to convert.
fromUnit The unit from which to convert the numeric value.
toUnit The unit to which to convert the numeric value.

getUnitsForQuantity(quantity)

Get all units registered for quantity

Param
quantity