TS-Scribe - v0.6.2
    Preparing search index...

    Function clamp

    • Clamps a number within the given range (min, max). If the value is less than the min, it returns the min. If the value is greater than the max, it returns the max. Otherwise, it returns the value itself.

      Parameters

      • value: number

        The number to be clamped.

      • min: number

        The minimum value in the range.

      • max: number

        The maximum value in the range.

      Returns number

      The clamped value, which is guaranteed to be within the [min, max] range.

      clamp(5, 0, 10); // Returns 5
      clamp(-1, 0, 10); // Returns 0
      clamp(15, 0, 10); // Returns 10