@sensimods/utility-lab
    Preparing search index...

    Function clamp

    • Clamps a number between a minimum and maximum value. Essential companion for math utilities. Ensures that a value does not exceed specified bounds, which is crucial for things like UI dimensions, game mechanics, or any scenario where you want to enforce limits.

      Parameters

      • val: number

        The number to clamp.

      • min: number

        The minimum allowed value.

      • max: number

        The maximum allowed value.

      Returns number

      The clamped value, guaranteed to be between min and max.

      clamp(5, 1, 10) // 5 (within range)
      clamp(-3, 0, 100) // 0 (clamped to minimum)
      clamp(150, 0, 100) // 100 (clamped to maximum)