- 1 :
/**
- 2 :
* Keep a number between a min and a max value
- 3 :
*
- 4 :
* @param {number} number
- 5 :
* The number to clamp
- 6 :
*
- 7 :
* @param {number} min
- 8 :
* The minimum value
- 9 :
* @param {number} max
- 10 :
* The maximum value
- 11 :
*
- 12 :
* @return {number}
- 13 :
* the clamped number
- 14 :
*/
- 15 :
const clamp = function(number, min, max) {
- 16 :
number = Number(number);
- 17 :
- 18 :
return Math.min(max, Math.max(min, isNaN(number) ? min : number));
- 19 :
};
- 20 :
- 21 :
export default clamp;