Function numberTest

Checks if t is not a number or within specified range. Returns [false, reason:string] if invalid or [true] if valid. Use throwNumberTest to throw an error rather than return result.

Alternatives: integerTest for additional integer check, percentTest for percentage-range.

  • (empty, default): must be a number type and not NaN.
  • finite: must be a number, not NaN and not infinite
  • positive: must be at least zero
  • negative: must be zero or lower
  • aboveZero: must be above zero
  • belowZero: must be below zero
  • percentage: must be within 0-1, inclusive
  • nonZero: can be anything except zero
  • bipolar: can be -1 to 1, inclusive
  • Parameters

    • Optionalvalue: unknown

      Value to check

    • range: NumberGuardRange = ...

      Range to enforce

    • parameterName: string = ...

      Name of parameter (for more helpful exception messages)

    Returns GuardResult