@pbroom/color-kitUtilities

clamp

Clamp value to the inclusive range [min, max].

functionimport { clamp } from '@pbroom/color-kit';index.ts:21
function clamp(  value: number, ,  min: number, ,  max: number,): number;

Parameters

valuenumber
Number to clamp
minnumber
Lower bound
maxnumber
Upper bound

Returns

numbervalue limited to [min, max]

Example

TypeScript
import { clamp } from '@pbroom/color-kit';

clamp(1.2, 0, 1); // → 1
clamp(-5, 0, 255); // → 0