clamp es-toolkit
Clamps a number within a specified range.
Usage
clamp(value, maximum)
Use clamp when you want to restrict a number to be at most a given maximum value. If the value exceeds the maximum, it's clamped to the maximum; otherwise, it returns the original value.
Parameters
The number to clamp.
The maximum value.
Returns
Returns the number clamped to be at most the maximum value.
clamp(value, minimum, maximum)
Use clamp when you want to restrict a number within a given minimum and maximum range. If the value falls outside the range, it's clamped to the nearest boundary.
Parameters
The number to clamp.
The minimum value.
The maximum value.
Returns
Returns the number clamped within the specified range.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.