Share your code. Components are building blocks, you are the architect.

utils/clamp
v1.0.0
1.0.0
MIT
PUBLIC
0
1     DEPENDENCIES
Build: none
BuildNone
Restricts a number to be within a range

Please configure Bit as a scoped registry to install components with NPM.Learn more

npm config set '@bit:registry' https://node.bitsrc.io
Use utils/clamp in your project
npm i @bit/bit.ramda.utils.clamp
Copied

clamp (minimum:Number, maximum:Number, value:Number) : Number

Restricts a number to be within a range.

Also works for other ordered types such as Strings and Dates.

Example

R.clamp(1, 10, -5) // => 1
     R.clamp(1, 10, 15) // => 10
     R.clamp(1, 10, 4)  // => 4

Arguments

minimum: Number

The lower limit of the clamp (inclusive)

maximum: Number

The upper limit of the clamp (inclusive)

value: Number

Value to be clamped

Returns

Number

Returns `minimum` when `val < minimum`, `maximum` when `val > maximum`, returns `val` otherwise