mirror of
https://github.com/swc-project/swc.git
synced 2024-12-22 05:01:42 +03:00
37 lines
1014 B
TypeScript
37 lines
1014 B
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/clamp.js
|
|
|
|
|
|
import _curry3 from './internal/_curry3.js';
|
|
|
|
/**
|
|
* 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 The lower limit of the clamp (inclusive)
|
|
* @param {Number} maximum The upper limit of the clamp (inclusive)
|
|
* @param {Number} value Value to be clamped
|
|
* @return {Number} Returns `minimum` when `val < minimum`, `maximum` when `val > maximum`, returns `val` otherwise
|
|
* @example
|
|
*
|
|
* R.clamp(1, 10, -5) // => 1
|
|
* R.clamp(1, 10, 15) // => 10
|
|
* R.clamp(1, 10, 4) // => 4
|
|
*/
|
|
var clamp = _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;
|
|
});
|
|
export default clamp;
|