Skip to content
Jason Godesky edited this page Jul 11, 2026 · 1 revision

clamp is a method that returns a value clamped to a given range.

Parameters

val: number

The requested value.

min: number

The bottom of the permitted range.

max: number

The top of the permitted range.

Returns

  • If val is between min and max (inclusive), clamp returns val
  • If val is less than min, clamp returns min
  • If val is greater than max, clamp returns max

Examples

import { clamp } from '@revolutionarygamesco/common'

clamp(0, 1, 10) // 1
clamp(1, 1, 10) // 1
clamp(5, 1, 10) // 5
clamp(10, 1, 10) // 10
clamp(11, 1, 10) // 10

Clone this wiki locally