UNPKG

959 BJavaScriptView Raw
1var _curry3 =
2/*#__PURE__*/
3require("./internal/_curry3");
4/**
5 * Restricts a number to be within a range.
6 *
7 * Also works for other ordered types such as Strings and Dates.
8 *
9 * @func
10 * @memberOf R
11 * @since v0.20.0
12 * @category Relation
13 * @sig Ord a => a -> a -> a -> a
14 * @param {Number} minimum The lower limit of the clamp (inclusive)
15 * @param {Number} maximum The upper limit of the clamp (inclusive)
16 * @param {Number} value Value to be clamped
17 * @return {Number} Returns `minimum` when `val < minimum`, `maximum` when `val > maximum`, returns `val` otherwise
18 * @example
19 *
20 * R.clamp(1, 10, -5) // => 1
21 * R.clamp(1, 10, 15) // => 10
22 * R.clamp(1, 10, 4) // => 4
23 */
24
25
26var clamp =
27/*#__PURE__*/
28_curry3(function clamp(min, max, value) {
29 if (min > max) {
30 throw new Error('min must not be greater than max in clamp(min, max, value)');
31 }
32
33 return value < min ? min : value > max ? max : value;
34});
35
36module.exports = clamp;
\No newline at end of file