@zakodium/utils
    Preparing search index...

    Function clamp

    • Clamps a numeric value between an optional minimum and maximum bound.

      Parameters

      • value: number

        The value to clamp.

      • min: number = -Infinity

        The lower bound (inclusive). Defaults to -Infinity.

      • max: number = Infinity

        The upper bound (inclusive). Defaults to Infinity.

      Returns number

      value if it lies within [min, max], otherwise the nearest bound.

      clamp(5, 0, 10); // 5
      clamp(-3, 0, 10); // 0
      clamp(15, 0, 10); // 10
      clamp(5); // 5 (no bounds)