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