Options
All
  • Public
  • Public/Protected
  • All
Menu

A collection of groups and their units with the logic on how to convert between groups with differing base units.

A class is essentially something like "Length" where base units are "inches" and "millimeters" and there are various other groups based off of these base groups like "feet", "centimeters", and "meters".

A class is responsible for being the sole place where conversion is done between different groups in the same class.

see

Class.convert

Hierarchy

  • Class

Index

Constructors

constructor

  • Creates a new instance of Class given the name of the class and optionally the groups of the class.

    Parameters

    • name: string

      The unique name of the class.

    • Optional groups: GroupDefinition[]

      The optional list of groups to populate the class with.

    Returns Class

Properties

converters

converters: ConverterDoubleMap

A map of functions which convert one unit value to another unit value. It is used by invoking converters[ fromUnit ][ toUnit ]( value ).

see

Class.setBaseConversion

see

Class.convert

groupMap

groupMap: GroupMap

A map of groups by their units. This map contains the expected case of each unit as well as the lowercase version of the unit as long as it doesn't overwrite another group. Unit case may be important so it has priority.

groups

groups: GroupList

A list of the groups in this class.

name

name: string

The name of the class.

Methods

addGroup

addGroupUnit

  • addGroupUnit(unit: string, group: Group): this
  • Adds the unit to this class for the given group. If the lowercase version of the unit has not been mapped yet it will be mapped to the given group.

    Parameters

    • unit: string

      The unit to map to the group.

    • group: Group

      The group which has the unit.

    Returns this

    The reference to this instance.

addGroups

  • Adds the group definitions to this class.

    see

    Class.addGroup

    Parameters

    Returns this

    The reference to this instance.

convert

  • convert(value: number, from: Group, to: Group, invalid?: number): number
  • Converts the given number from a given group to a given group. If the two groups are the same or one or both of the groups are not provided then the value provided is returned. If the two groups have differing base units the Class.converters map is used to convert the value over to the proper base. If the Class.converters map is missing a base conversion zero is returned. This might happen if a group is passed to this function which does not belong to this class OR if the user has impromperly setup their own classes.

    Parameters

    • value: number

      The number to convert.

    • from: Group

      The group of the number to convert from.

    • to: Group

      The group to convert to.

    • Default value invalid: number = 0

      The value to return if a conversion between the two groups could not be made.

    Returns number

    The converted number or zero if a base conversion could not be found.

getVisibleGroups

  • getVisibleGroups(transform: Transform, reverse: boolean, relatedGroup: Group, callback: function): void
  • Determines which groups in this class are visible according to the given transform. The groups can be iterated in reverse and can optionally take a related group into consideration (when the system is GIVEN, we want to return the groups with the same system).

    see

    Transform.isVisibleGroup

    Parameters

    • transform: Transform

      The transform which decides what groups are visible.

    • reverse: boolean

      If the groups of this class should be iterated in reverse.

    • relatedGroup: Group

      A related group which may be used for visibility if the Transform.system is System.GIVEN.

    • callback: function

      A function to invoke with all visible groups found and the index of that group in the set of visible groups. If false is returned by the function iteration of visible groups ceases.

        • (group: Group, index: number): any
        • Parameters

          • group: Group

            The current visible group.

          • index: number

            The index of the current visible group.

          Returns any

    Returns void

removeGroupUnit

  • removeGroupUnit(unit: string, group: Group): this
  • Removes the given unit associated to the given group from the class. If the group is not mapped to this unit then this has no effect.

    Parameters

    • unit: string

      The unit to remove from this class.

    • group: Group

      The group which has the unit.

    Returns this

    The reference to this instance.

setBaseConversion

  • setBaseConversion(fromUnit: string, toUnit: string, converter: Converter): this
  • Sets the conversion function between the two base units.

    Parameters

    • fromUnit: string

      The base unit to convert from.

    • toUnit: string

      The base unit to convert to.

    • converter: Converter

      The function to pass the value to convert.

    Returns this

    The reference to this instance.

setClassScales

  • setClassScales(): this
  • Updates the Group.classScale value in each group in this class so that there is a baseline for comparing one group to another no matter the base unit. For comparing in the same base, you can use Group.baseScale.

    Returns this

    The reference to this instance.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc