clamp
@guoba-ai/utils / number / clamp
Function: clamp()
function clamp(
value,
min,
max): number;Defined in: number.ts:15
Clamp a number between a minimum and maximum value.
Parameters
value
number
The number to clamp
min
number
The lower bound
max
number
The upper bound
Returns
number
value when it is within bounds, otherwise the nearest bound
Example
clamp(5, 0, 10) // 5
clamp(-1, 0, 10) // 0
clamp(11, 0, 10) // 10