clamp

Commons
stable

Constrains a number to stay within [min, max]. Returns min when value is below range, max when above, otherwise the value itself.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

value
required
number
The number to constrain.
min
number
0
Lower bound. Defaults to 0.
max
number
1
Upper bound. Defaults to 1.

API

Return value

The value returned by this util.

The clamped number within [min, max].

Usage

Examples

Ready-to-paste usage snippets.

Clamping values

typescript