Skip to content

mathClamp

type: function
since: v2.10.0

The mathClamp function Clamps a number to be within a specified range

Usage

import { mathClamp } from '@mustib/utils'
mathClamp(1,2,3) // 2
mathClamp(2,1,3) // 2
mathClamp(1,3,2) // 2

Definition

function mathClamp(
minValue: number,
currentValue: number,
maxValue: number
): number

Parameters

  1. minValue
    type minValue = number;
    • The minimum allowed value for the number.
  2. currentValue
    type currentValue = number;
    • The current value of the number.
  3. currentValue
    type currentValue = number;
    • The maximum allowed value for the number.

Returns

type T = number;
  • The clamped value, which is within the specified range [minValue, maxValue]