Class TypeOfAbstract

Strict type-assertion and runtime type-checking utility. When type-checking variables in the global scope, e.g., window or process, make use of the globalThis object.

Example

Type-check global context:

import { TypeOf } from '@sgrud/core';

TypeOf.process(globalThis.process); // true if running in node context
TypeOf.window(globalThis.window); // true if running in browser context

Constructors

Methods

  • Type-check value for unknown[].

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is unknown[]

    Whether value is of type unknown[].

    Example

    Type-check null for unknown[]:

    import { TypeOf } from '@sgrud/core';

    TypeOf.array(null); // false
  • Type-check value for boolean.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is boolean

    Whether value is of type boolean.

    Example

    Type-check null for boolean:

    import { TypeOf } from '@sgrud/core';

    TypeOf.boolean(null); // false
  • Type-check value for Date.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is Date

    Whether value is of type Date.

    Example

    Type-check null for Date:

    import { TypeOf } from '@sgrud/core';

    TypeOf.date(null); // false
  • Type-check value for Function.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is Function

    Whether value is of type Function.

    Example

    Type-check null for Function:

    import { TypeOf } from '@sgrud/core';

    TypeOf.function(null); // false
  • Type-check value for null.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is null

    Whether value is of type null.

    Example

    Type-check null for null:

    import { TypeOf } from '@sgrud/core';

    TypeOf.null(null); // true
  • Type-check value for number.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is number

    Whether value is of type number.

    Example

    Type-check null for number:

    import { TypeOf } from '@sgrud/core';

    TypeOf.number(null); // false
  • Type-check value for object.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is object

    Whether value is of type object.

    Example

    Type-check null for object:

    import { TypeOf } from '@sgrud/core';

    TypeOf.object(null); // false
  • Type-check value for NodeJS.Process.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is Process

    Whether value is of type NodeJS.Process.

    Example

    Type-check null for NodeJS.Process:

    import { TypeOf } from '@sgrud/core';

    TypeOf.process(null); // false
  • Type-check value for Promise<unknown>.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is Promise<unknown>

    Whether value is of type Promise<unknown>.

    Example

    Type-check null for Promise<unknown>:

    import { TypeOf } from '@sgrud/core';

    TypeOf.promise(null); // false
  • Type-check value for RegExp.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is RegExp

    Whether value is of type RegExp.

    Example

    Type-check null for RegExp:

    import { TypeOf } from '@sgrud/core';

    TypeOf.regex(null); // false
  • Type-check value for string.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is string

    Whether value is of type string.

    Example

    Type-check null for string:

    import { TypeOf } from '@sgrud/core';

    TypeOf.string(null); // false
  • Type-check value for undefined.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is undefined

    Whether value is of type undefined.

    Example

    Type-check null for undefined:

    import { TypeOf } from '@sgrud/core';

    TypeOf.undefined(null); // false
  • Type-check value for URL.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is URL

    Whether value is of type URL.

    Example

    Type-check null for URL:

    import { TypeOf } from '@sgrud/core';

    TypeOf.url(null); // false
  • Type-check value for Window.

    Parameters

    • value: unknown

      The value to type-check.

    Returns value is Window

    Whether value is of type Window.

    Example

    Type-check null for Window:

    import { TypeOf } from '@sgrud/core';

    TypeOf.window(null); // false
  • Type-check value for type.

    Parameters

    • type: string

      The type to check for.

    • value: unknown

      The value to type-check.

    Returns boolean

    Whether value is type.

Generated using TypeDoc