Creates a standard measure that is used to express amounts.
the unit's format, holds the unit's different symbols (e.g. m, metre, meters
for the unit meter)
the unit system the unit is belonging to
Creates a standard measure that is used to express amounts.
Using this constructor function one doesn't need to specify functions describing how to convert the unit to the group's base unit and vice versa.
Instead one only specifies the mathematical relation the the base unit - in the form of a ratio and a shift.
Example: You want to define the unit Fahrenheit and you have already defined the base unit Kelvin.
You know the formula to convert a value from Fahrenheit to Kelvin is: °F * 5/9 + (45967/180) = °K
.
Using the other constructor function you had to write the following:
new Unit({...}, (val) => (val - (45967/180)) / 5/9, (val) => val * 5/9 + (45967/180), ...);
As you see there is repetitive code. Couldn't one save one of the two converter functions? Lets see how we create the unit using this constructor.
new Unit({...}, 5/9, 45967/180, ...)
5/9
is the ratio between the units, 45967/180
the shift. Much easier, isn't it? And no repetitive code!
the unit's format, holds the unit's different symbols (e.g. m, metre, meters
for the unit meter)
the unit system the unit is belonging to
The unit's {@link UnitFormat}. Holds the unit's unique symbols,
which allow the parser to recognize the unit in a string.
Added to that it provides the basis for the .format()
method of the Convertible.
Converts a value from the group's base unit to this unit.
The unit system the unit is belonging to. E.g. imperial
, metric
, ...
This meta information is used for the Convertible's .asBest()
method.
By default, the Convertible always remains in the same system of units.
Converts a value from this unit to the group's base unit.
Creates a string array holding all this unit's different notations.
a string array holding all this unit's different notations
Returns an array of units to which this unit can be converted.
an array of units to which this unit can be converted
Returns the unit's standard string representation - therefore the most common symbol. For example 'm'
is returned for the unit meter.
the unit's standard string representation
Generated using TypeDoc
Represents a standard measure that is used to express amounts.
A unit is always part of one single Group (attribute: Unit.group). It is always defined in relation to the base unit of its group.
The exact relation is defined in the converter functions Unit.fromBase and Unit.toBase. Thereby
fromBase(val: number) => number
defines the conversion from the base unit tothis
andtoBase(val: number) => number
vice versa. As a result of this simple concept, all units of a group are convertible into each other.The 4th important property of each unit is its Unit.format. This defines the unit's shape. It allows firstly the parser to recognize the unit in a string and secondly it provides the basis for the
.format()
method of the Convertible.Lastly every unit is part of a unit system (attribute: Unit.system). This meta information is used for the Convertible's
.asBest()
method. By default, the Convertible always remains in the same system of units.