clamp
Clamps a number between a minimum and maximum value.
Installation
npm install @madeinhaus/utils
Import
import { clamp } from '@madeinhaus/utils';
Parameters
value
(number): The number to clamp.min
(number): The minimum value to clamp to.max
(number): The maximum value to clamp to.
Returns
(number)
: The clamped value.
Usage
import { clamp } from '@madeinhaus/utils';
const value = 10;
const min = 0;
const max = 5;
const clampedValue = clamp(value, min, max); // 5
In this example, we import the clamp
function from the @madeinhaus/utils
package and use it to clamp a value between a minimum and maximum value.