Class HNum

Haystack number with units.

Hierarchy

  • HNum

Implements

Accessors

Methods

  • Compares two values.

    Parameters

    • value: unknown

      The number to compare.

    Returns number

    The sort order as negative, 0, or positive

  • Convert the number to another unit.

    Please note, the unit to convert to must be compatible otherwise an error is thrown.

    If the current number does not have a unit then return a number with the specified unit and value.

    Parameters

    • unit: HUnit

      The unit to convert too.

    Returns HNum

    The new number with the new unit.

    Throws

    An error if the number can't be converted with the unit.

  • Divide this number by another.

    Parameters

    • num: HNum

      The number to divide by.

    Returns HNum

    The new number.

    Throws

    An error if the units are incompatible.

  • Value equality check.

    Parameters

    • value: unknown

      The value to test.

    Returns boolean

    True if the value is the same.

  • Dump the value to the local console output.

    Parameters

    • Optional message: string

      An optional message to display before the value.

    Returns HNum

    The value instance.

  • Returns true if the number is a type of duration.

    Returns boolean

    True if the number is a duration.

  • Compares the value's kind.

    Parameters

    • kind: Kind

      The kind to compare against.

    Returns boolean

    True if the kind matches.

  • Returns true if the haystack filter matches the value.

    Parameters

    • filter: string | Node

      The filter to test.

    • Optional cx: Partial<EvalContext>

      Optional haystack filter evaluation context.

    Returns boolean

    True if the filter matches ok.

  • Subtract a number from this number.

    Parameters

    • num: HNum

      The number to subtract.

    Returns HNum

    The new number.

    Throws

    An error if the units are incompatible.

  • Multiply this number by another.

    Parameters

    • num: HNum

      The number to multiply by.

    Returns HNum

    The new number.

    Throws

    An error if the units are incompatible.

  • Add a number to this number.

    Parameters

    • num: HNum

      The number to add.

    Returns HNum

    The new number.

    Throws

    An error if the units are incompatible.

  • Encodes to an encoded zinc value that can be used in a haystack filter string.

    The encoding for a haystack filter is mostly zinc but contains some exceptions.

    Returns string

    The encoded value that can be used in a haystack filter.

  • Return the number as a readable string.

    Parameters

    • precision: number = DEFAULT_PRECISION

      Optional precision. Default is 1 decimal place.

    Returns string

    A string representation of the value.

  • Encodes to an encoding zinc value.

    Returns string

    The encoded zinc string.

  • Makes a haystack number.

    Parameters

    • value: number | HaysonNum | HNum

      The value or a hayson number object.

    • Optional unit: string | HUnit

      Optional units.

    Returns HNum

    A haystack number.

Generated using TypeDoc