clipNumber<N extends num> function

N? clipNumber<N extends num>(
  1. N? n,
  2. N min,
  3. N max, [
  4. N? def,
])

Clips a number n into it's limits, min and max.

def The default value if n is null.

Implementation

N? clipNumber<N extends num>(N? n, N min, N max, [N? def]) {
  n ??= def;
  if (n == null) return null;
  if (n < min) return min;
  if (n > max) return max;
  return n;
}