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.
API
Parameters
Input parameters accepted by this util.
- valuerequirednumber
- The number to constrain.
- minnumber0
- Lower bound. Defaults to 0.
- maxnumber1
- 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