# static isRange()

## `Range.isRange()`

The static `isRange()` method checks whether the [`value`](#value-any) is an instance of [`Range`](https://range.angular-package.dev/range) of any or the given [**minimum**](#min-min), [**maximum**](#max-max) range and [step](#step-step).

{% code title="range.class.ts" %}

```typescript
public static isRange<
  Min extends number,
  Max extends number,
  Step extends number
>(
  value: any,
  min?: Min,
  max?: Max,
  step?: Step
): value is Range<Min, Max, Step> {
  return typeof value === 'object' && value instanceof this
    ? (typeof min === 'number' ? value.min === min : true) &&
        (typeof max === 'number' ? value.max === max : true) &&
        (typeof step === 'number' ? value.step === step : true)
    : false;
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`Min`</mark>`extends`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)

A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number), by default of the value **captured** from the supplied [`min`](#min-min) indicates the **minimum** range type via the [return type](#return-type).

#### <mark style="color:green;">`Max`</mark>`extends`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)

A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number), by default of the value **captured** from the supplied [`max`](#max-max) indicates the **maximum** range type via the [return type](#return-type).

#### <mark style="color:green;">`Step`</mark>`extends`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)

A generic type variable constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number), by default of the value equal to **`1`**, optionally **captured** from the supplied [`step`](#step-step) indicates the range step type via [return type](#return-type).

### Parameters

#### `value:`[<mark style="color:green;">`any`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#any)

The value of [`any`](https://www.typescriptlang.org/docs/handbook/basic-types.html#any) type to test against the [`Range`](https://range.angular-package.dev/range) instance.

#### `min?:`[<mark style="color:green;">`Min`</mark>](#minextendsnumber)

The optional **minimum** range of generic type variable [`Min`](#minextendsnumber) to check whether it's equal to a **minimum** of the given [`value`](#value-any).

#### `max?:`[<mark style="color:green;">`Max`</mark>](#minextendsnumber-1)

The optional **maximum** range of generic type variable [`Max`](#maxextendsnumber) to check whether it's equal to a **maximum** of the given [`value`](#value-any).

#### `step?:`[<mark style="color:green;">`Step`</mark>](#stepextendsnumber-1)

Optional step of generic type variable [`Step`](#stepextendsnumber) to check whether it's equal to the step of the given [`value`](#value-any).

### Return type

#### `value is`[<mark style="color:green;">`Range`</mark>](https://range.angular-package.dev/range)`<`[<mark style="color:green;">`Min`</mark>](#minextendsnumber)`,`[<mark style="color:green;">`Max`</mark>](#maxextendsnumber)`,`[<mark style="color:green;">`Step`</mark>](#stepextendsnumber)`>`

The **return type** is a [`boolean`](https://www.typescriptlang.org/docs/handbook/basic-types.html#boolean) resulting from its statement indicating the [`value`](#value-any) is the [`Range`](https://range.angular-package.dev/range) object that takes the generic type variable [`Min`](#minextendsnumber), [`Max`](#maxextendsnumber) and [`Step`](#stepextendsnumber).

### Returns

The **return value** is a [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) indicating whether the provided [`value`](#value-any) is an instance of [`Range`](https://range.angular-package.dev/range) of any or the given [minimum](#min-min), [maximum](#max-max) range and [`step`](#step-step).

## Example usage

```typescript
// Example usage.
import { Range } from '@angular-package/range';

// Create new instance.
const range = new Range(4, 27, 1.5);

// Returns true of type value is Range<number, number, number>
Range.isRange(range);

// Returns true of type value is Range<4, number, number>
Range.isRange(range, 4);

// Returns true of type value is Range<4, 27, number>
Range.isRange(range, 4, 27);

// Returns true of type value is Range<4, 27, 1.5>
Range.isRange(range, 4, 27, 1.5);

// Returns false of type value is Range<3, number, number>
Range.isRange(range, 3);

// Returns false of type value is Range<3, 26, number>
Range.isRange(range, 3, 26);

// Returns false of type value is Range<3, 26, 1.0>
Range.isRange(range, 3, 26, 1.0);

// Returns true of type value is Range<number, 27, number>
Range.isRange(range, undefined, 27);

// Returns true of type value is Range<number, number, 1.5>
Range.isRange(range, undefined, undefined, 1.5);
```
