ts-data-forge
    Preparing search index...

    Function isUintInRangeInclusive

    • Creates a type guard that checks if a number is an unsigned integer within a specified inclusive range.

      This function returns a predicate that validates whether a number is:

      • A safe integer (no floating point)
      • Within the range [lowerBound, upperBound] (both bounds inclusive)

      The returned type guard provides precise type narrowing when the bounds are SmallUint literals, useful for validating scores, percentages, or other bounded values.

      Type Parameters

      • L extends
            | 0
            | 1
            | 2
            | 3
            | 4
            | 5
            | 6
            | 7
            | 8
            | 9
            | 10
            | 11
            | 12
            | 13
            | 14
            | 15
            | 16
            | 17
            | 18
            | 19
            | 20
            | 21
            | 22
            | 23
            | 24
            | 25
            | 26
            | 27
            | 28
            | 29
            | 30
            | 31
            | 32
            | 33
            | 34
            | 35
            | 36
            | 37
            | 38
            | 39

        The lower bound as a SmallUint literal type

      • U extends
            | 0
            | 1
            | 2
            | 3
            | 4
            | 5
            | 6
            | 7
            | 8
            | 9
            | 10
            | 11
            | 12
            | 13
            | 14
            | 15
            | 16
            | 17
            | 18
            | 19
            | 20
            | 21
            | 22
            | 23
            | 24
            | 25
            | 26
            | 27
            | 28
            | 29
            | 30
            | 31
            | 32
            | 33
            | 34
            | 35
            | 36
            | 37
            | 38
            | 39

        The upper bound as a SmallUint literal type

      Parameters

      • lowerBound: L

        The minimum value (inclusive)

      • upperBound: U

        The maximum value (inclusive)

      Returns (x: number) => x is RelaxedExclude<LEQ[U], LT[MinImpl<L, []>]>

      A type guard function that validates and narrows number types

      const inclusiveGuard = Num.isUintInRangeInclusive(0, 5);

      assert.ok(inclusiveGuard(5));
      assert.notOk(inclusiveGuard(6));