@oazmi/kitchensink - v0.9.13
    Preparing search index...

    Function clamp

    • clamp a number to inclusive min and max intervals.

      you can also provide a type alias for the output interval OutInterval number through the use of the generic parameter.

      Type Parameters

      • OutInterval extends number = number

      Parameters

      • value: number

        value to clamp

      • min: OutInterval = ...

        inclusive minimum of the interval

      • max: OutInterval = ...

        inclusive maximum of the interval

      Returns OutInterval

      import { assertEquals } from "jsr:@std/assert"

      assertEquals(clamp(-5, -1, 10), -1)
      assertEquals(clamp(5, -1, 10), 5)
      assertEquals(clamp(15, -1, 10), 10)