Class: Unit

Unit()

new Unit()

Unit expression represented as an array of unit factors.

Each factor has kind, multiplier, and exponent fields.

Extends

  • Array

Methods

clone() → {Unit}

Creates a deep copy of this unit.

Returns:

Cloned unit.

Type
Unit

divide(unit) → {Unit}

Divides this unit by another unit.

Parameters:
Name Type Description
unit Unit

Divisor unit.

Returns:

Quotient unit.

Type
Unit

equal(unit, rebase) → {boolean}

Checks unit equality.

Parameters:
Name Type Default Description
unit Unit

Unit to compare with.

rebase boolean false

Compare through primitive units when true.

Returns:

true if units are equal.

Type
boolean

multiply(unit) → {Unit}

Multiplies this unit by another unit.

Parameters:
Name Type Description
unit Unit

Unit to multiply by.

Returns:

Product unit.

Type
Unit

power(n) → {Array.<object>}

Multiplies all exponents by n.

Parameters:
Name Type Default Description
n number 1

Power value.

Returns:

Powered unit factors.

Type
Array.<object>

rebase(legalUnits) → {Unit}

Expands non-legal units into legal units.

This method requires bound unit definitions. The returned unit is not bound to unit definition objects.

Parameters:
Name Type Description
legalUnits Array.<string>

Allowed unit ids.

Returns:

Rebasing result.

Type
Unit

rebaseToPrimitive() → {Unit}

Expands all derived units into primitive units.

Primitive units are unit definitions without their own units property. This method requires bound unit definitions.

Returns:

Primitive-unit representation.

Type
Unit

root(n) → {Array.<object>}

Divides all exponents by n.

Parameters:
Name Type Default Description
n number 1

Root value.

Returns:

Rooted unit factors.

Type
Array.<object>

simplify(dimensionlessKind) → {Unit}

Simplifies unit factors by combining equal kinds and canceling exponents. Canceled factors contribute their multiplier to the dimensionless factor.

Parameters:
Name Type Default Description
dimensionlessKind string dimensionless

Unit kind used to store dimensionless multipliers.

Returns:

Simplified unit.

Type
Unit

toHTML() → {string}

Serializes this unit to inline HTML.

Returns:

HTML fragment.

Type
string

toHTML2(spaceSymbol, timesSymbol, minusSymbol) → {string}

Serializes this unit to fraction-style HTML.

Parameters:
Name Type Default Description
spaceSymbol string &#160;

HTML space symbol.

timesSymbol string &#215;

HTML multiplication symbol.

minusSymbol string

HTML minus symbol.

Returns:

HTML fragment.

Type
string

toHash() → {string}

Serializes this unit to a stable identifier.

Returns:

Identifier such as _mM2_L__mg__h2.

Type
string

toQ(options) → {Array.<object>}

Converts this unit to Q-array representation.

Parameters:
Name Type Description
options object

Serialization options.

Returns:

Unit factors.

Type
Array.<object>

toString(usePrefix) → {string}

Serializes this unit to compact text.

Parameters:
Name Type Default Description
usePrefix boolean false

Use known SI prefixes for multipliers.

Returns:

String such as mM^2*L/mg/h2.

Type
string

toTerm() → {UnitTerm|undefined}

Calculates the physical term represented by this unit.

This method requires bound unit definitions.

Returns:

Unit term, or undefined if it cannot be calculated.

Type
UnitTerm | undefined

toTex() → {string}

Serializes this unit to TeX.

Returns:

TeX expression.

Type
string

toXmlUnitDefinition(legalUnits, options) → {string}

Serializes this unit as an SBML unitDefinition XML fragment.

Parameters:
Name Type Description
legalUnits Array.<string>

Allowed SBML unit ids.

options object

Serialization options.

Returns:

XML fragment.

Type
string

(static) fromQ(obj) → {Unit}

Creates a unit from Q-array representation.

Parameters:
Name Type Description
obj Array.<object>

Unit factors.

Returns:

Unit instance.

Type
Unit

(static) parse(unitString) → {Unit}

Parses a unit string.

Parameters:
Name Type Description
unitString string

String such as mM^2*L/mg/h2 or (1e-2 mg)^3/L.

Returns:

Parsed unit.

Type
Unit