Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Unit

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 to this and toBase(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.

Hierarchy

  • Unit

Index

Properties

format

format: UnitFormat

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.

fromBase

fromBase: Converter

Converts a value from the group's base unit to this unit.

param

value in the group's base unit

returns

value in this unit

group

group: Group = ...

The unit's Group. Units belonging to the same group are convertible into each other.

system

system: string

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.

toBase

toBase: Converter

Converts a value from this unit to the group's base unit.

param

value in this unit

returns

value in the group's base unit

Methods

computeNotations

  • computeNotations(): UnitString[]
  • Creates a string array holding all this unit's different notations.

    Returns UnitString[]

    a string array holding all this unit's different notations

possibilities

  • possibilities(): UnitString[]
  • Returns an array of units to which this unit can be converted.

    Returns UnitString[]

    an array of units to which this unit can be converted

toString

  • toString(): UnitString
  • Returns the unit's standard string representation - therefore the most common symbol. For example 'm' is returned for the unit meter.

    Returns UnitString

    the unit's standard string representation

Generated using TypeDoc