UnitExpression

Represents an expression made of composed Units. This structure is the basis of DerivedUnit definitions. Logically, a UnitExpression represents a list of Terms multiplied together. Each Term has a base "unit" and a power. For instance, a UnitExpression that represents "meter per second squared," would consist of one Term that represents "meter" (to the first power) and another Term that represents "second squared."

Methods

dimensions() → {Dimensions}

Returns a Dimensions object that represents the unit dimensions of this UnitExpression.
Returns:
Dimensions

div(rhs) → {UnitExpression}

Divides this UnitExpression by another UnitExpression and returns the result as another UnitExpression. Logically, this operation is implemented by inverting the divisor `rhs` and performing a multiplication operation.
Parameters:
Name Type Description
rhs UnitExpression
Returns:
UnitExpression

mult(rhs) → {UnitExpression}

Multiplies this UnitExpression by another UnitExpression and returns the result as another UnitExpression. Logically, this operation is implemented by concatenating all of the terms together and combining like bases.
Parameters:
Name Type Description
rhs UnitExpression
Returns:
UnitExpression

pow(power) → {UnitExpression}

Exponentiates this UnitExpression by the given power and returns the result as another UnitExpression.
Parameters:
Name Type Description
power number
Returns:
UnitExpression

simplify() → {UnitExpression}

Simplifies the UnitExpression by combining like Terms.
Returns:
UnitExpression

terms() → {array.<Term>}

Returns an immutable array of Terms that make up the UnitExpression.
Returns:
array.<Term>

toBaseUnits() → {UnitExpression}

Recursively breaks down this UnitExpression into its constituent Terms and each Term into its constituent BaseUnits, until only BaseUnits are left.
Returns:
UnitExpression

toMap() → {object}

Projects this UnitExpression onto an equivalent map, where each unit type becomes a key, and the value is the sum of all the powers of the Terms of that type.
Returns:
object

toString() → {string}

Returns a string representation of the given UnitExpression. For example, the string representation of a UnitExpression that represents "meters per second squared" will be "m/s^2".
Returns:
string