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

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

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

API

Valeur de retour

La valeur retournée par cet util.

The clamped number within [min, max].

Usage

Exemples

Extraits de code prêts à coller.

Clamping values

typescript