# isNumberBetween()

## `isNumberBetween()`

Checks if [`any`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any) value is a [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) type or an instance of [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)(by using [`isNumber()`](/type-draft/is/isnumber.md)) between a specified range.

{% code title="is-number-between.func.ts" %}

```typescript
const isNumberBetween = <
  Type extends AnyNumber = number,
  Min extends number = number,
  Max extends number = number,
  Payload extends object = object
>(
  value: any,
  min: Min,
  max: Max,
  callback: ResultCallback<
    any,
    { min: Min; max: Max } & Payload
  > = resultCallback,
  payload?: Payload
): value is NumberBetween<Min, Max, Type> =>
  callback(
    isNumber(value)
      ? (isNumberType(min) ? value.valueOf() >= min : false) &&
          (isNumberType(max) ? value.valueOf() <= max : false)
      : false,
    value,
    { ...payload, min, max } as any
  );
```

{% endcode %}

{% embed url="<https://github.com/angular-package/type/blob/main/src/is/lib/is-number-between.func.ts>" %}

### Generic type variables

#### <mark style="color:green;">`Type`</mark>`extends`<mark style="color:green;">`AnyNumber`</mark>`=`<mark style="color:green;">`number`</mark>

A generic type variable `Type` constrained by [`AnyNumber`](/type-draft/type/anynumber.md) indicates the number type of the given [`value`](#value-any) via the [return type](#return-type), by default [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number).

#### <mark style="color:green;">`Min`</mark>`extends`<mark style="color:green;">`number`</mark>`=`<mark style="color:green;">`number`</mark>

A generic type variable `Min` constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number) type, by default of value captured from the supplied [`min`](#min-min) indicates the **minimum** range of the provided [`value`](#value-any) via the [return type](#return-type) and the fixed shape of optional [`payload`](/type-draft/type/resultcallback.md#payload-payload) parameter of the provided [`callback`](#callback-resultcallback-less-than-any-min-min-max-max-and-payload-greater-than) function.

#### <mark style="color:green;">`Max`</mark>`extends`<mark style="color:green;">`number`</mark>`=`<mark style="color:green;">`number`</mark>

A generic type variable `Max` constrained by the [`number`](https://www.typescriptlang.org/docs/handbook/basic-types.html#number) type, by default of value captured from the supplied [`max`](#max-max) indicates the **maximum** range of the provided [`value`](#value-any) via the [return type](#return-type) and the fixed shape of optional [`payload`](/type-draft/type/resultcallback.md#payload-payload) parameter of the provided [`callback`](#callback-resultcallback-less-than-any-min-min-max-max-and-payload-greater-than) function.

#### <mark style="color:green;">**`Payload`**</mark>**`extends`**<mark style="color:green;">**`object`**</mark>**`=`**<mark style="color:green;">**`object`**</mark>

The `Payload` generic type variable constrained by [`object`](https://www.typescriptlang.org/docs/handbook/basic-types.html#object) indicates the type of optional parameter [`payload`](/type-draft/type/resultcallback.md#payload-payload) of the supplied [`callback`](#callback-resultcallback-less-than-any-min-min-max-max-and-payload-greater-than) function and [`payload`](#payload-payload) optional parameter of the [`isNumberBetween()`](#isnumberbetween) function from which it captures its value.

### Parameters

#### `value: any`

The value of [`any`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any) type to check.

#### `min: Min`

The **minimum** range of generic type variable [`Min`](#minextendsnumber-number) for a given [`value`](#value-any).

#### `max: Max`

The **maximum** range of generic type variable [`Max`](#maxextendsnumber-number) for a given [`value`](#value-any).

#### `callback: ResultCallback<any, { min: Min; max: Max } & Payload>`

A callback `function` of [`ResultCallback`](/type-draft/type/resultcallback.md) type with parameters, the [`value`](#value-any) that has been checked, the [`result`](/type-draft/type/resultcallback.md#result-boolean) of this check, and [`payload`](/type-draft/type/resultcallback.md#payload-payload) of generic type variable [`Payload`](#payloadextendsobject-object) with optional properties from the provided [`payload`](#payload-payload), to handle them before the [`result`](/type-draft/type/resultcallback.md#result-boolean) return. By default, it uses [`resultCallback()`](/type-draft/helper/resultcallback.md) function.

{% hint style="info" %}
The [`payload`](/type-draft/type/resultcallback.md#payload-payload) parameter of the [`callback`](/type-draft/type/resultcallback.md) function consists of the [`min`](#min-min) and [`max`](#max-max) properties given in parameters of the core function, and they can't be overwritten by the given [`payload`](#payload-payload) parameter of the core function.
{% endhint %}

#### `payload?: Payload`

An optional [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) of the generic type variable [`Payload`](#payloadextendsobject-object) is assigned to the [`payload`](/type-draft/type/resultcallback.md#payload-payload) of the given [`callback`](#callback-resultcallback-less-than-any-min-min-max-max-and-payload-greater-than) function.

### Return type

#### `value is NumberBetween<Min, Max, Type>`

The **return type** is a [`boolean`](https://www.typescriptlang.org/docs/handbook/basic-types.html#boolean) as the result of its statement indicating the [`value`](#value-any) is a generic type [`NumberBetween`](/type-draft/type/numberbetween.md) that takes generic type variables [`Min`](#minextendsnumber-number) and [`Max`](#maxextendsnumber-number) as a **range** of the supplied [`value`](#value-any) and [`Type`](#typeextendsanynumber-number) as the type of the supplied [`value`](#value-any).

### Returns

The **return value** is a [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) indicating whether the [`value`](#value-any) is a finite [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) of a [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) type or an instance of [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) between a specified range.

## Example usage

### Type

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

const age = 13;

// true; The return type `value is NumberBetween<0, 13, number>`
isNumberBetween(age, 0, 13);
// false; The return type `value is NumberBetween<14, 28, number>`
isNumberBetween(age, 14, 28);
// false; The return type `value is NumberBetween<0, 12, number>`
isNumberBetween(age, 0, 12);
// true; The return type `value is NumberBetween<13, 13, number>`
isNumberBetween(age, 13, 13);
```

### Instance

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

const ageBox = new Number(age);

// true; The return type `value is NumberBetween<0, 13, Number>`
isNumberBetween(ageBox, 0, 13);
// false; The return type `value is NumberBetween<14, 28, Number>`
isNumberBetween(ageBox, 14, 28);
// false; The return type `value is NumberBetween<0, 12, Number>`
isNumberBetween(ageBox, 0, 12);
// true; The return type `value is NumberBetween<13, 13, Number>`
isNumberBetween(ageBox, 13, 13);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://type.angular-package.dev/type-draft/is/isnumberbetween.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
