Class Range

The Range class provides utility methods for working with numeric ranges. It allows you to generate a range of numbers, check if a value is within a specified range, and create aliases for the range methods.

Example

const numericRange = Range.range(1, 5, 2);
console.log(numericRange); // Output: [1, 3, 5]

const isInRange = Range.inRange(3, 1, 5);
console.log(isInRange); // Output: true

Since

version 1.0.4

Author

Manuel Santos ney.br.santos@gmail.com

Constructors

Methods

  • Checks if a value is within the specified numeric range.

    Parameters

    • value: number

      The value to check.

    • start: number

      The start of the range.

    • end: number

      The end of the range.

    Returns boolean

    True if the value is within the range, false otherwise.

    Example

    const isInRange = Ranges.inRange(3, 1, 5);
    console.log(isInRange); // Output: true
  • Creates an array representing a range of numbers from start to end (inclusive) with an optional step.

    Parameters

    • start: number

      The start of the range.

    • end: number

      The end of the range.

    • Optional step: number = 1

      The step between elements. Defaults to 1.

    Returns readonly number[]

    An array representing the range of numbers.

    Example

    const numericRange = Ranges.range(1, 5, 2);
    console.log(numericRange); // Output: [1, 3, 5]
  • Creates an array representing a range of numbers from start to end (inclusive) with an optional step. Alias for the range method.

    Parameters

    • start: number

      The start of the range.

    • end: number

      The end of the range.

    • Optional step: number = 1

      The step between elements. Defaults to 1.

    Returns readonly number[]

    An array representing the range of numbers.

    Example

    const numericRange = Ranges.rangeTo(1, 5, 2);
    console.log(numericRange); // Output: [1, 3, 5]
  • Creates an array representing a range of numbers from start to (end - 1) with an optional step.

    Parameters

    • start: number

      The start of the range.

    • end: number

      The end of the range.

    • Optional step: number = 1

      The step between elements. Defaults to 1.

    Returns readonly number[]

    An array representing the range of numbers.

    Example

    const numericRange = Ranges.rangeUntil(1, 5, 2);
    console.log(numericRange); // Output: [1, 3]

Generated using TypeDoc