2026-01-07 16:48:49 +03:00
|
|
|
/**
|
2026-03-02 22:19:13 +03:00
|
|
|
* Clamps a number within a specified range
|
|
|
|
|
*
|
|
|
|
|
* Ensures a value falls between minimum and maximum bounds.
|
|
|
|
|
* Values below min return min, values above max return max.
|
|
|
|
|
*
|
|
|
|
|
* @param value - The number to clamp
|
|
|
|
|
* @param min - Minimum allowed value (inclusive)
|
|
|
|
|
* @param max - Maximum allowed value (inclusive)
|
|
|
|
|
* @returns The clamped number
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```ts
|
|
|
|
|
* clampNumber(5, 0, 10); // 5
|
|
|
|
|
* clampNumber(-5, 0, 10); // 0
|
|
|
|
|
* clampNumber(15, 0, 10); // 10
|
|
|
|
|
* ```
|
2026-01-07 16:48:49 +03:00
|
|
|
*/
|
|
|
|
|
export function clampNumber(value: number, min: number, max: number): number {
|
|
|
|
|
return Math.min(Math.max(value, min), max);
|
|
|
|
|
}
|