Function toNumWithBounds

Returns the given number bound by min and/or max value.

If the value is not a valid number, then defaultValue is returned if given (including if it is null), otherwise limits.min if given and not null, otherwise limits.max if given and not null, or finally 0.

If the value is outside the bounds, then:

  • if defaultValue is given, defaultValue is returned (including if it is null)
  • otherwise, the min or the max value (whichever one is violated) is returned
  • Type Parameters

    • D extends null | number | false = number

    Parameters

    • value: unknown
    • limits: AtLeastOne<{ max: null | number; min: null | number }>
    • OptionaldefaultValue: D

    Returns number | D