clamp()
clamp(
min
,max
,value
):number
Clamps a number within the specified bounds.
Parameters
min
number
The lower bound to clamp to.
max
number
The upper bound to clamp to.
value
number
The number value to clamp to the given range.
Returns
number
Throws
Throws if min > max.
Example
const value = clamp(5, 15, 10); // 10
const value = clamp(5, 15, 2); // 5
const value = clamp(5, 15, 20); // 15
const value = clamp(15, 5, 10); // RangeError