@tempots/std
clamp() function
clamp
restricts a value within the specified range.
Signature:
clamp: (value: number, min: number, max: number) => number
Parameters
Parameter |
Type |
Description |
---|---|---|
value |
number |
The value to clamp. |
min |
number |
The minimum value. |
max |
number |
The maximum value. |
Returns: number
The clamped value.
Example
clamp(1.3, 0, 1) // returns 1
clamp(0.8, 0, 1) // returns 0.8
clamp(-0.5, 0, 1) // returns 0.0