clamp
Clamp a number between two values
Installation
$ npm install @f/clamp
Usage
var clamp = require('@f/clamp')
clamp(1, 2, 3) === 2
clamp(3, 1, 2) === 2
clamp(2, 1, 3) === 2
API
clamp(n, min, max)
-
n
- The number to be clamped -
min
- The minimum value -
max
- The maximum value
Returns: If n is between min and max, returns n. If n is greater than max, returns max. If n is less than min, returns min.
License
MIT