Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Collection

Represents a collection of units (see Unit) structured in groups (see Group).

Offers key functionality like converting from one unit to another. Is the center at which all of the library's features are brought together.

The basic structure of a collection is basically following: A collection is the parent of multiple groups. Groups are parents of multiple units.

Example:

Collection
 |
 |____Group "length"
 |      |___Unit "meter"
 |      |___Unit "inch"
 |      |___ (...)
 |____Group "mass"
 |      |___Unit "kilogram"
 |      |___Unit "pound"
 |      |___ (...)
(...)

Hierarchy

  • Collection

Index

Properties

Private groups

groups: Map<GroupString, Group> = ...

All groups of the collection arranged in a map.

Methods

Convertible

  • Convertible(value: number, unit: UnitString): Convertible
  • Returns a convertible having the given value and unit. Alias to Collection.from.

    see

    Convertible

    Parameters

    • value: number

      the convertible's value (e.g. 20)

    • unit: UnitString

      the convertible's unit (e.g. °F)

    Returns Convertible

    a convertible having the given value and unit

from

  • Returns a convertible having the given value and unit. Does exactly the same as Collection.Convertible.

    see

    Convertible

    Parameters

    • value: number

      the convertible's value (e.g. 20)

    • unit: UnitString

      the convertible's unit (e.g. °F)

    Returns Convertible

    a convertible having the given value and unit

group

  • group(group: GroupString): Group
  • Returns the group having the passed name.

    see

    Group

    Parameters

    • group: GroupString

      the group's name

    Returns Group

    the group itself

groupList

  • groupList(): GroupString[]
  • Returns a string array containing the names of all groups.

    Returns GroupString[]

    a string array containing the names of all groups

isSupported

  • isSupported(possibleUnit: string): boolean
  • Returns whether the passed unit is supported.

    Parameters

    • possibleUnit: string

      the unit

    Returns boolean

    whether the passed unit is supported

possibilities

  • possibilities(): UnitString[]
  • Returns a string array containing the short names of all units.

    Returns UnitString[]

    a string array containing the short names of all units

toString

  • toString(): string
  • Returns the collection as human-readable string.

    Returns string

    the collection as string

unit

  • unit(unit: UnitString): Unit
  • Returns the unit object belonging to the given unit.

    see

    Unit

    Parameters

    • unit: UnitString

      the unit as string

    Returns Unit

    the unit object belonging to the given unit string

Generated using TypeDoc