Enforces a minimum and/or maximum limit on a number and returns the number or the enforced limit.
function clampNumber(
n: number,
min: number | false,
max?: number | false
)
// Example:
clamp(15, 3, 12) //=> 12
clamp(15, 16, 20) //=> 16
NOTE: You can pass false
for a limit parameter to bypass that limit.