Skip to content

clamp

Static Badge

Clamp the input parameter num using max as the upper bound and min as the lower bound.

Added in v0.0.6

Usage

ts
import { clamp } from 'parsnip-kit'

clamp(5, 0, 10) // 5
clamp(-5, 0, 10) // 0
clamp(15, 0, 10) // 10

clamp(100) // 100

API

Arguments

ArgTypeOptionalDefaultDescription
numnumberfalseundefinedThe number to clamp
minnumbertrue-InfinityThe minimum
maxnumbertrueInfinityThe maximum

Returns

Type
number