Class Number

Additional static members for the native Number class.

Does not extend the native Number class.

Constructors

Properties

Methods

Constructors

Properties

REGEXP: Readonly<RegExp> = ...

An immutable RegExp instance, representing a string in Number format.

Methods

  • Verify the type of number given, throwing if it does not match.

    Given a number and a “type”, test to see if the argument is of that type. Mainly used for parameter validation, when the type number is not specific enough. The acceptable “types”, which are not mutually exclusive, are members of NumericType. If no type is given, this method just asserts the number is not NaN.

    If the argument matches the described type, this method returns void instead of true. If the argument does not match, this method throws an error instead of returning false. This pattern is helpful where an error message is more descriptive than a boolean.

    Parameters

    • num: number

      the argument to test

    • Optional type: NumericType

      one of the enum members listed above

    Returns void

    Throws

    if the argument does not match the described type

    Throws

    if the argument is NaN

  • Parameters

    • num: number

      the given number

    Returns "integer" | "float"

    one of the strings described above

    Deprecated

    use xjs_Number.assertType Specify the type of number given.

    If the number is finite, return one of the following strings:

    • 'integer' : the number is an integer, that is, num % 1 === 0
    • 'float' : the number is not an integer

    Else, throw a RangeError (the argument is of the correct type but does not qualify).

    Throws

    if the given arguemnt was not a finite number