Envelope Pattern TypeScript - v1.0.0-alpha.20
    Preparing search index...

    Class Interval

    Represents an inclusive interval with a minimum value and an optional maximum value.

    When the maximum is undefined, the interval is considered unbounded above.

    // Single value interval
    const exact = new Interval(3, 3); // Matches exactly 3

    // Bounded range
    const range = new Interval(1, 5); // Matches 1 to 5 inclusive

    // Unbounded range
    const unbounded = new Interval(2); // Matches 2 or more
    Index

    Constructors

    • Creates a new Interval.

      Parameters

      • min: number

        The minimum value (inclusive)

      • Optionalmax: number

        The maximum value (inclusive), or undefined for unbounded

      Returns Interval

    Methods

    • Creates an interval from a range specification.

      Parameters

      • start: number

        The start of the range (inclusive)

      • Optionalend: number

        The end of the range (inclusive), or undefined for unbounded

      Returns Interval

      A new Interval

    • Creates an interval for exactly n occurrences.

      Parameters

      • n: number

        The exact count

      Returns Interval

      A new Interval with min = max = n

    • Creates an interval for at least n occurrences.

      Parameters

      • n: number

        The minimum count

      Returns Interval

      A new Interval with min = n and no maximum

    • Creates an interval for at most n occurrences.

      Parameters

      • n: number

        The maximum count

      Returns Interval

      A new Interval with min = 0 and max = n

    • Creates an interval for zero or more occurrences (0..).

      Returns Interval

      A new Interval representing *

    • Creates an interval for one or more occurrences (1..).

      Returns Interval

      A new Interval representing +

    • Creates an interval for zero or one occurrence (0..=1).

      Returns Interval

      A new Interval representing ?

    • Returns the minimum value of the interval.

      Returns number

    • Returns the maximum value of the interval, or undefined if unbounded.

      Returns number | undefined

    • Checks if the given count falls within this interval.

      Parameters

      • count: number

        The count to check

      Returns boolean

      true if count is within the interval

    • Checks if the interval represents a single value (i.e., min equals max).

      Returns boolean

    • Checks if the interval is unbounded (i.e., has no maximum value).

      Returns boolean

    • Returns a string representation of the interval using standard range notation.

      Returns string

      The range notation string

      new Interval(3, 3).rangeNotation()  // "{3}"
      new Interval(1, 5).rangeNotation() // "{1,5}"
      new Interval(2).rangeNotation() // "{2,}"
    • Returns a string representation of the interval using shorthand notation where applicable.

      Returns string

      The shorthand notation string

      new Interval(0, 1).shorthandNotation()  // "?"
      new Interval(0).shorthandNotation() // "*"
      new Interval(1).shorthandNotation() // "+"
      new Interval(1, 5).shorthandNotation() // "{1,5}"
    • Returns a string representation using range notation.

      Returns string

    • Checks equality with another Interval.

      Parameters

      Returns boolean