source: node_modules/ramda/src/clamp.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 962 bytes
RevLine 
[d24f17c]1var _curry3 =
2/*#__PURE__*/
3require("./internal/_curry3.js");
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;
Note: See TracBrowser for help on using the repository browser.