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 any 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"
 |      |___ (...)
 |____Group "custom"
 |      |___Unit "small coins"
 |      |___Unit "big coins"

Collections are not static. In fact they are very flexible. You can add, overwrite and remove unit groups using the Collection.Editor. Added to that groups are editable in the same way (see Group.Editor), which leads to the fact that groups can be modified in their entirety at runtime.

Hierarchy

  • Collection

Index

Constructors

constructor

Properties

Readonly Editor

Editor: CollectionEditor = ...

The collection's editor. Provides methods to add, remove and overwrite unit groups.

see

CollectionEditor

Private Readonly groups

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

All groups of the collection arranged in a map.

Methods

Convertible

  • Convertible(value: number, unit: string): 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: string

      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: string

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

    Returns Convertible

    a convertible having the given value and unit

group

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

    see

    Group

    Parameters

    • group: string

      the group's name

    Returns Group

    the group itself

isSupported

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

    Parameters

    • unit: string

      the unit

    Returns boolean

    whether the passed unit is supported

possibilities

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

    Returns string[]

    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: string): Unit
  • Returns the unit object belonging to the given unit.

    see

    Unit

    Parameters

    • unit: string

      the unit as string

    Returns Unit

    the unit object belonging to the given unit string

Generated using TypeDoc