Class HUnit

Hierarchy

  • HUnit

Constructors

Properties

_isHUnit: true = true

Used for a type guard check.

Accessors

  • get quantity(): undefined | string
  • Returns undefined | string

    The unit's quantity or undefined if none available.

  • get quantities(): string[]
  • Returns string[]

    A list of all the quantities available.

Methods

  • Convert the unit to the new scalar.

    Parameters

    • scalar: number

      The new scalar value.

    • to: HUnit

      The new unit to convert too.

    Returns number

    The new scalar value.

  • Return a unit that can be used when dividing two numbers together.

    Parameters

    • unit: HUnit

      The unit to divide.

    Returns HUnit

    The unit to divide by.

    Throws

    An error if the units can't be divided.

  • Equality for units.

    Parameters

    • Optional unit: HUnit

      The value to compare against.

    Returns boolean

    True if the units are equal.

  • Return a unit that can be used when multiplying two numbers together.

    Parameters

    • unit: HUnit

      The unit to multiply.

    Returns HUnit

    The unit to multiply by.

    Throws

    An error if the units can't be multiplied.

  • Defines a unit in the database.

    Parameters

    Returns HUnit

    The unit instance.

    Throws

    An error if the unit is already registered.

  • Return a unit from the database via its id or undefined if it can't be found.

    Parameters

    • id: string

      The id of the unit to look up.

    Returns undefined | HUnit

    The unit or undefined.

  • Return the units for the quantity.

    Parameters

    • quanity: string

      The quantity to search for.

    Returns readonly HUnit[]

    An array of quantities. An empty array is returned if the quantity can't be found.

  • Dump the current state of the unit database to the console output.

    Returns void

  • Returns true if the two numbers approximately match.

    Parameters

    • a: number

      The first number.

    • b: number

      The second number.

    Returns boolean

    True if the two numbers match.

  • Parse the database and return all of the units.

    Parameters

    • text: string

      The text from units.txt to parse.

    Returns UnitData[]

    All parsed units.

  • Parse some text to see if contains some quantity information. Return the quantity or undefined if it can't be found.

    Parameters

    • text: string

      The text to parse.

    Returns string

    The quantity or undefined if it can't be found.

  • Parse a line from units.txt as follows...

    unit := [";" [";" [";" ]]] names := ("," )* id := * idChar := 'a'-'z' | 'A'-'Z' | '_' | '%' | '/' | any char > 128 dim := ["" ] // no whitespace allowed ratio := base := "kg" | "m" | "sec" | "K" | "A" | "mol" | "cd" exp := scale := offset :=

    Parameters

    • text: string

      The text to parse.

    Returns undefined | UnitData

    The unit data or undefined if no unit data is found.

    Throws

    An error if unit data is found but the format is invalid.

Generated using TypeDoc