UnitList.convert()method
Convert an amount from a unit in this list to another unit in this list.
convert(amount: number, sourceKey: K, targetKey: K): number
new UnitList<K>(units: ImmutableObject<K, UnitProps<K>>)
| Param | Type | |
|---|---|---|
units | ImmutableObject<K, UnitProps<K>> | Set of units keyed by their string key — the first entry becomes the base unit. required |
| Return | |
|---|---|
UnitList<K> | Represent a list of related units of measure (e.g. all length units). |
| Property | Type | |
|---|---|---|
.base | Unit<K> | Base unit for this list (the first unit added). required readonly |
Represent a list of related units of measure (e.g. all length units).
.base.unit()new UnitList({ meter: {}, kilometer: { to: { meter: 1000 } } }).convert(1, "kilometer", "meter") // 1000Convert an amount from a unit in this list to another unit in this list.
convert(amount: number, sourceKey: K, targetKey: K): number
Require a unit from this list.
require(key: K): Unit<K>