Take a partial set of UnitTerms, and fills in the missing exponents with 0.
Divide two Unit types, A/B (by subtracting the exponents).
Divide two UnitTerms, A/B
Our supported exponents. A finite list of exponents allows TypeScript to automatically type exponents as numeric literal types.
Invert a UnitTerms (by negating the exponents).
Multiply two Unit types (by adding the exponents).
Multiply two UnitTerms (by adding the exponents.)
An object of primitive UNIT: Exponent pairs that uniquely describes each type.
Type of our PRIMITIVE_MAP map. This provides one key/value entry for each primitive, indexed by the UNIT enum.
An object with keys being the name of Primitive types and the values being exponents. All values are required; supply zero for values not supplied.
See PUnitTerms for a partial set where types can be left undefined.
A map from primitive name to its Unit instance.
String literal parser for LaTeX literals (avoids the need for quoting backslash).
Define a unit alias, which can convert to/from a corresponding standard unprefixed SI unit.
Define a derived type.
The numbers in the keys are exponents for primitive types. They are taken as type literals,
This ensures, for example, that the types of U.velocity and U.acceleration are distinct.
const U.velocity = defineUnit({distance: 1, time: -1});
const U.acceleration = defineUnit({distance: 1, time: -2});
Results in types of:
type U.velocity = Unit<{distance: 1, time: -1}>
type U.acceleration = Unit<{distance: 1, time: -2}>
The key defining the type composition
Additional attributes describing the type.
Additional names to use for this type, e.g. newton.
Get a unit by name.
To process a # + unit into standard unprefixed SI, do:
const [siVal, siUnit] = getUnit(unitName).toSI(val);
To just get the standard SI unit, do:
const siUnit = getUnit(unitName).si;
if true, only unscaled SI units are returned.
Turn the structured UnitTerms key into a string to do the lookup for unique types.
Generated using TypeDoc
Representation and manipulation of physical units.
These are based on SI, and in particular the (Guide for the Use of the International System of Units (SI))https://physics.nist.gov/cuu/pdf/sp811.pdf(https://physics.nist.gov/cuu/pdf/sp811.pdf]) However, this does not try to be complete, and extends the set of base units somewhat to aid clarity (for example, 'cycles/revolutions') while preserving semantics and standardized presentation. Having units that map to SI '1' is not very helpful sometimes.
See the Units.Units namespace for definitions of individual units.