source: node_modules/ramda/es/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: 942 bytes
RevLine 
[d24f17c]1import _curry3 from "./internal/_curry3.js";
2/**
3 * Restricts a number to be within a range.
4 *
5 * Also works for other ordered types such as Strings and Dates.
6 *
7 * @func
8 * @memberOf R
9 * @since v0.20.0
10 * @category Relation
11 * @sig Ord a => a -> a -> a -> a
12 * @param {Number} minimum The lower limit of the clamp (inclusive)
13 * @param {Number} maximum The upper limit of the clamp (inclusive)
14 * @param {Number} value Value to be clamped
15 * @return {Number} Returns `minimum` when `val < minimum`, `maximum` when `val > maximum`, returns `val` otherwise
16 * @example
17 *
18 * R.clamp(1, 10, -5) // => 1
19 * R.clamp(1, 10, 15) // => 10
20 * R.clamp(1, 10, 4) // => 4
21 */
22
23var clamp =
24/*#__PURE__*/
25_curry3(function clamp(min, max, value) {
26 if (min > max) {
27 throw new Error('min must not be greater than max in clamp(min, max, value)');
28 }
29
30 return value < min ? min : value > max ? max : value;
31});
32
33export default clamp;
Note: See TracBrowser for help on using the repository browser.