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