clamp

v1.0.0arrow_drop_down
v1.0.0
v0.0.1
STATUS
Passing
DOWNLOADS
26
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
7 years ago
SIZE
490 B
Returns a number whose value is limited to the given range.
2 contributors
Install clamp as a package?
Copied
npm i @bit/bit.utils.number.clamp
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
clamp (
value:number,
min:number,
max:number
) : number

Returns a number whose value is limited to the given range.

Example
clamp(50, 5, 10) // => 5
Arguments
value: number

The value to be clamped

min: number

The lower boundary of the output range

max: number

The upper boundary of the output range

Returns
number

A number in the range [min, max]

Test Summary

number/clamp should return the max number (10)

Pass

number/clamp should return the min number (5)

Pass

number/clamp should return the passed number as its within range

Pass
Help and resources