clamp

🗜️ Clamps a number between a specified minimum and maximum value.

Syntax

TypeScript
import { clamp } from '@opentf/std';
clamp(val: number, options: { min: number; max: number }): number

Parameters

  • val: The number to clamp.

  • options.min: The lower bound of the range.

  • options.max: The upper bound of the range.

Returns

The clamped number.

Examples

TypeScript
clamp(10, { min: -5, max: 5 }) //=> 5

clamp(0, { min: 1000, max: 1366 }) //=> 1000

clamp(1001, { min: 1000, max: 1366 }) //=> 1001

clamp(1500, { min: 1000, max: 1366 }) //=> 1366

Try it

Last updated on
Edit this page