Skip to content

clamp() ​

clamp(value, min, max): number

Defined in: utils/math/clamp.ts:15

Clamps a number to a specified range.

Parameters ​

value ​

number

The number to clamp.

min ​

number

The minimum value.

max ​

number

The maximum value.

Returns ​

number

The clamped value. Returns NaN if inputs are invalid.

Example ​

tsx
const clamped = clamp(15, 0, 10); // 10
const clamped = clamp(-5, 0, 10); // 0

Released under the MIT License.