Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

clamp

v1.0.0arrow_drop_down
v1.0.0
v0.0.1
STATUS
Passing
DOWNLOADS
26
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
2 years ago
SIZE
490 B
Returns a number whose value is limited to the given range.
2 contributors
Use clamp in your project ?
Copied
npm i @bit/bit.utils.number.clamp
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
React
React
Vue
Angular
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';
revert changes
reload
toggle layout
maximize
clamp(50, 5, 10); // => 5
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