@tempots/std

clampInt() function

Clamps a number to a specified range and returns an integer value.

Signature:

clampInt: (value: number, min: number, max: number) => number

Parameters

Parameter

Type

Description

value

number

The number to clamp.

min

number

The minimum value of the range.

max

number

The maximum value of the range.

Returns: number

The clamped integer value.

Example

clampInt(5, 0, 10) // returns 5
clampInt(15, 0, 10) // returns 10
clampInt(-5, 0, 10) // returns 0