Function constrain

  • Ensure n is an integer within [0,MAX_SAFE_INTEGER] range.

    Parameters

    • n: number

      Input number.

    • typeName: string

      Description of the number type.

    Returns number

    RangeError Thrown if n is out of valid range.

  • Ensure n is an integer within [0,max] range.

    Parameters

    • n: number

      Input number.

    • typeName: string

      Description of the number type.

    • max: number

      Maximum allowed value (inclusive).

    Returns number

    RangeError Thrown if n is out of valid range.

  • Ensure n is an integer within [min,max] range.

    Parameters

    • n: number

      Input number.

    • typeName: string

      Description of the number type.

    • min: number

      Minimum allowed value (inclusive).

    • max: number

      Maximum allowed value (inclusive).

    Returns number

    RangeError Thrown if n is out of valid range.