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