is-what

  • Version 4.0.0
  • Published
  • 52.1 kB
  • No dependencies
  • MIT license

Install

npm i is-what
yarn add is-what
pnpm add is-what

Overview

JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.

Index

Variables

variable isNullOrUndefined

const isNullOrUndefined: TypeGuard<any, null>;
  • Returns true whether the payload is null or undefined

    Parameter payload

    Returns

    {(payload is null | undefined)}

Functions

function getType

getType: (payload: any) => string;
  • Returns the object type of the given payload

    Parameter payload

    Returns

    {string}

function isAnyObject

isAnyObject: (payload: any) => payload is PlainObject;
  • Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)

    Parameter payload

    Returns

    {payload is PlainObject}

function isArray

isArray: (payload: any) => payload is any[];
  • Returns whether the payload is an array

    Parameter payload

    Returns

    {payload is any[]}

function isBlob

isBlob: (payload: any) => payload is Blob;
  • Returns whether the payload is a Blob

    Parameter payload

    Returns

    {payload is Blob}

function isBoolean

isBoolean: (payload: any) => payload is boolean;
  • Returns whether the payload is a boolean

    Parameter payload

    Returns

    {payload is boolean}

function isDate

isDate: (payload: any) => payload is Date;
  • Returns whether the payload is a Date, and that the date is valid

    Parameter payload

    Returns

    {payload is Date}

function isEmptyArray

isEmptyArray: (payload: any) => payload is [];
  • Returns whether the payload is a an empty array

    Parameter payload

    Returns

    {payload is []}

function isEmptyObject

isEmptyObject: (
payload: any
) => payload is { [x: string]: never; [x: number]: never };
  • Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)

    Parameter payload

    Returns

    {payload is { [K in any]: never }}

function isEmptyString

isEmptyString: (payload: any) => payload is string;
  • Returns whether the payload is ''

    Parameter payload

    Returns

    {payload is string}

function isError

isError: (payload: any) => payload is Error;
  • Returns whether the payload is an Error

    Parameter payload

    Returns

    {payload is Error}

function isFile

isFile: (payload: any) => payload is File;
  • Returns whether the payload is a File

    Parameter payload

    Returns

    {payload is File}

function isFullArray

isFullArray: (payload: any) => payload is any[];
  • Returns whether the payload is a an array with at least 1 item

    Parameter payload

    Returns

    {payload is any[]}

function isFullObject

isFullObject: (payload: any) => payload is PlainObject;
  • Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)

    Parameter payload

    Returns

    {payload is PlainObject}

function isFullString

isFullString: (payload: any) => payload is string;
  • Returns whether the payload is a string, BUT returns false for ''

    Parameter payload

    Returns

    {payload is string}

function isFunction

isFunction: (payload: any) => payload is AnyFunction;
  • Returns whether the payload is a function (regular or async)

    Parameter payload

    Returns

    {payload is AnyFunction}

function isMap

isMap: (payload: any) => payload is Map<any, any>;
  • Returns whether the payload is a Map

    Parameter payload

    Returns

    {payload is Map<any, any>}

function isNaNValue

isNaNValue: (payload: any) => payload is number;
  • Returns whether the payload is literally the value NaN (it's NaN and also a number)

    Parameter payload

    Returns

    {payload is typeof NaN}

function isNull

isNull: (payload: any) => payload is null;
  • Returns whether the payload is null

    Parameter payload

    Returns

    {payload is null}

function isNumber

isNumber: (payload: any) => payload is number;
  • Returns whether the payload is a number (but not NaN)

    This will return false for NaN!!

    Parameter payload

    Returns

    {payload is number}

function isObject

isObject: (payload: any) => payload is PlainObject;
  • Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)

    Parameter payload

    Returns

    {payload is PlainObject}

function isObjectLike

isObjectLike: <T extends PlainObject>(payload: any) => payload is T;
  • Returns whether the payload is an object like a type passed in < >

    Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an id prop.

    T this must be passed in < >

    Parameter payload

    Returns

    {payload is T}

function isOneOf

isOneOf: {
<A, B extends A, C extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>): TypeGuard<
A,
B | C
>;
<A, B extends A, C extends A, D extends A>(
a: TypeGuard<A, B>,
b: TypeGuard<A, C>,
c: TypeGuard<A, D>
): TypeGuard<A, B | C | D>;
<A, B extends A, C extends A, D extends A, E extends A>(
a: TypeGuard<A, B>,
b: TypeGuard<A, C>,
c: TypeGuard<A, D>,
d: TypeGuard<A, E>
): TypeGuard<A, B | C | D | E>;
<A, B extends A, C extends A, D extends A, E extends A, F extends A>(
a: TypeGuard<A, B>,
b: TypeGuard<A, C>,
c: TypeGuard<A, D>,
d: TypeGuard<A, E>,
e: TypeGuard<A, F>
): TypeGuard<A, B | C | D | E | F>;
};

    function isPlainObject

    isPlainObject: (payload: any) => payload is PlainObject;
    • Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)

      Parameter payload

      Returns

      {payload is PlainObject}

    function isPrimitive

    isPrimitive: (payload: any) => payload is string | number | boolean | symbol;
    • Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)

      Parameter payload

      Returns

      {(payload is boolean | null | undefined | number | string | symbol)}

    function isPromise

    isPromise: (payload: any) => payload is Promise<any>;
    • Returns whether the payload is a Promise

      Parameter payload

      Returns

      {payload is Promise}

    function isRegExp

    isRegExp: (payload: any) => payload is RegExp;
    • Returns whether the payload is a regular expression (RegExp)

      Parameter payload

      Returns

      {payload is RegExp}

    function isSet

    isSet: (payload: any) => payload is Set<any>;
    • Returns whether the payload is a Set

      Parameter payload

      Returns

      {payload is Set}

    function isString

    isString: (payload: any) => payload is string;
    • Returns whether the payload is a string

      Parameter payload

      Returns

      {payload is string}

    function isSymbol

    isSymbol: (payload: any) => payload is symbol;
    • Returns whether the payload is a Symbol

      Parameter payload

      Returns

      {payload is symbol}

    function isType

    isType: <T extends AnyFunction | AnyClass>(
    payload: any,
    type: T
    ) => payload is T;
    • Does a generic check to check that the given payload is of a given type. In cases like Number, it will return true for NaN as NaN is a Number (thanks javascript!); It will, however, differentiate between object and null

      T

      Parameter payload

      Parameter type

      Returns

      {payload is T}

      Throws

      {TypeError} Will throw type error if type is an invalid type

    function isUndefined

    isUndefined: (payload: any) => payload is undefined;
    • Returns whether the payload is undefined

      Parameter payload

      Returns

      {payload is undefined}

    function isWeakMap

    isWeakMap: (payload: any) => payload is WeakMap<any, any>;
    • Returns whether the payload is a WeakMap

      Parameter payload

      Returns

      {payload is WeakMap<any, any>}

    function isWeakSet

    isWeakSet: (payload: any) => payload is WeakSet<any>;
    • Returns whether the payload is a WeakSet

      Parameter payload

      Returns

      {payload is WeakSet}

    Type Aliases

    type AnyAsyncFunction

    type AnyAsyncFunction = (...args: any[]) => Promise<any>;

      type AnyClass

      type AnyClass = new (...args: any[]) => any;

        type AnyFunction

        type AnyFunction = (...args: any[]) => any;

          type PlainObject

          type PlainObject = Record<string | number | symbol, any>;

            Package Files (1)

            Dependencies (0)

            No dependencies.

            Dev Dependencies (17)

            Peer Dependencies (0)

            No peer dependencies.

            Badge

            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/is-what.

            • Markdown
              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/is-what)
            • HTML
              <a href="https://www.jsdocs.io/package/is-what"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>