ts-data-forge
    Preparing search index...

    Function clamp

    • Clamps a value within the given range. If the target value is invalid (not finite), returns the lower bound.

      Provides two usage patterns for maximum flexibility:

      • Direct usage: Pass all three arguments to get the clamped value immediately
      • Curried usage: Pass bounds to get a reusable clamping function

      Parameters

      • target: number
      • lowerBound: number
      • upperBound: number

      Returns number

      assert(Num.clamp(150, 0, 100) === 100);
      assert(Num.clamp(-50, 0, 100) === 0);

      const clampToPercentage = Num.clamp(0, 100);

      assert(clampToPercentage(75) === 75);
      assert(clampToPercentage(150) === 100);
    • Clamps a value within the given range. If the target value is invalid (not finite), returns the lower bound.

      Provides two usage patterns for maximum flexibility:

      • Direct usage: Pass all three arguments to get the clamped value immediately
      • Curried usage: Pass bounds to get a reusable clamping function

      Parameters

      • lowerBound: number
      • upperBound: number

      Returns (target: number) => number

      assert(Num.clamp(150, 0, 100) === 100);
      assert(Num.clamp(-50, 0, 100) === 0);

      const clampToPercentage = Num.clamp(0, 100);

      assert(clampToPercentage(75) === 75);
      assert(clampToPercentage(150) === 100);