clamp.js•784 B
var _curry3 = require('./internal/_curry3');
/**
* Restricts a number to be within a range.
*
* Also works for other ordered types such as Strings and Dates.
*
* @func
* @memberOf R
* @since v0.20.0
* @category Relation
* @sig Ord a => a -> a -> a -> a
* @param {Number} minimum number
* @param {Number} maximum number
* @param {Number} value to be clamped
* @return {Number} Returns the clamped value
* @example
*
* R.clamp(1, 10, -1) // => 1
* R.clamp(1, 10, 11) // => 10
* R.clamp(1, 10, 4) // => 4
*/
module.exports = _curry3(function clamp(min, max, value) {
if (min > max) {
throw new Error('min must not be greater than max in clamp(min, max, value)');
}
return value < min ? min :
value > max ? max :
value;
});