summaryrefslogtreecommitdiff
path: root/javascript/videojs/src/js/utils/num.js
blob: 8ec1bf66b21aa7594e85dd8a104744c9f6a6bb7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * @file num.js
 * @module num
 */

/**
 * Keep a number between a min and a max value
 *
 * @param {number} number
 *        The number to clamp
 *
 * @param {number} min
 *        The minimum value
 * @param {number} max
 *        The maximum value
 *
 * @return {number}
 *         the clamped number
 */
export function clamp(number, min, max) {
  number = Number(number);

  return Math.min(max, Math.max(min, isNaN(number) ? min : number));
}