Socket
Socket
Sign inDemoInstall

is-what

Package Overview
Dependencies
0
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.1.10 to 4.1.11

89

dist/index.d.ts

@@ -1,5 +0,5 @@

export type AnyFunction = (...args: any[]) => any;
export type AnyAsyncFunction = (...args: any[]) => Promise<any>;
export type AnyClass = new (...args: any[]) => any;
export type PlainObject = Record<string | number | symbol, any>;
type AnyFunction = (...args: any[]) => any;
type AnyAsyncFunction = (...args: any[]) => Promise<any>;
type AnyClass = new (...args: any[]) => any;
type PlainObject = Record<string | number | symbol, any>;
type TypeGuard<A, B extends A> = (payload: A) => payload is B;

@@ -12,3 +12,3 @@ /**

*/
export declare function getType(payload: any): string;
declare function getType(payload: any): string;
/**

@@ -20,3 +20,3 @@ * Returns whether the payload is undefined

*/
export declare function isUndefined(payload: any): payload is undefined;
declare function isUndefined(payload: any): payload is undefined;
/**

@@ -28,3 +28,3 @@ * Returns whether the payload is null

*/
export declare function isNull(payload: any): payload is null;
declare function isNull(payload: any): payload is null;
/**

@@ -36,3 +36,3 @@ * Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)

*/
export declare function isPlainObject(payload: any): payload is PlainObject;
declare function isPlainObject(payload: any): payload is PlainObject;
/**

@@ -44,3 +44,3 @@ * Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)

*/
export declare function isObject(payload: any): payload is PlainObject;
declare function isObject(payload: any): payload is PlainObject;
/**

@@ -52,3 +52,3 @@ * Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)

*/
export declare function isEmptyObject(payload: any): payload is {
declare function isEmptyObject(payload: any): payload is {
[K in any]: never;

@@ -62,3 +62,3 @@ };

*/
export declare function isFullObject(payload: any): payload is PlainObject;
declare function isFullObject(payload: any): payload is PlainObject;
/**

@@ -70,3 +70,3 @@ * Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)

*/
export declare function isAnyObject(payload: any): payload is PlainObject;
declare function isAnyObject(payload: any): payload is PlainObject;
/**

@@ -81,3 +81,3 @@ * Returns whether the payload is an object like a type passed in < >

*/
export declare function isObjectLike<T extends PlainObject>(payload: any): payload is T;
declare function isObjectLike<T extends PlainObject>(payload: any): payload is T;
/**

@@ -89,3 +89,3 @@ * Returns whether the payload is a function (regular or async)

*/
export declare function isFunction(payload: any): payload is AnyFunction;
declare function isFunction(payload: any): payload is AnyFunction;
/**

@@ -97,3 +97,3 @@ * Returns whether the payload is an array

*/
export declare function isArray(payload: any): payload is any[];
declare function isArray(payload: any): payload is any[];
/**

@@ -105,3 +105,3 @@ * Returns whether the payload is a an array with at least 1 item

*/
export declare function isFullArray(payload: any): payload is any[];
declare function isFullArray(payload: any): payload is any[];
/**

@@ -113,3 +113,3 @@ * Returns whether the payload is a an empty array

*/
export declare function isEmptyArray(payload: any): payload is [];
declare function isEmptyArray(payload: any): payload is [];
/**

@@ -121,3 +121,3 @@ * Returns whether the payload is a string

*/
export declare function isString(payload: any): payload is string;
declare function isString(payload: any): payload is string;
/**

@@ -129,3 +129,3 @@ * Returns whether the payload is a string, BUT returns false for ''

*/
export declare function isFullString(payload: any): payload is string;
declare function isFullString(payload: any): payload is string;
/**

@@ -137,3 +137,3 @@ * Returns whether the payload is ''

*/
export declare function isEmptyString(payload: any): payload is string;
declare function isEmptyString(payload: any): payload is string;
/**

@@ -147,3 +147,3 @@ * Returns whether the payload is a number (but not NaN)

*/
export declare function isNumber(payload: any): payload is number;
declare function isNumber(payload: any): payload is number;
/**

@@ -155,3 +155,3 @@ * Returns whether the payload is a positive number (but not 0)

*/
export declare function isPositiveNumber(payload: any): payload is number;
declare function isPositiveNumber(payload: any): payload is number;
/**

@@ -163,3 +163,3 @@ * Returns whether the payload is a negative number (but not 0)

*/
export declare function isNegativeNumber(payload: any): payload is number;
declare function isNegativeNumber(payload: any): payload is number;
/**

@@ -171,3 +171,3 @@ * Returns whether the payload is a boolean

*/
export declare function isBoolean(payload: any): payload is boolean;
declare function isBoolean(payload: any): payload is boolean;
/**

@@ -179,3 +179,3 @@ * Returns whether the payload is a regular expression (RegExp)

*/
export declare function isRegExp(payload: any): payload is RegExp;
declare function isRegExp(payload: any): payload is RegExp;
/**

@@ -187,3 +187,3 @@ * Returns whether the payload is a Map

*/
export declare function isMap(payload: any): payload is Map<any, any>;
declare function isMap(payload: any): payload is Map<any, any>;
/**

@@ -195,3 +195,3 @@ * Returns whether the payload is a WeakMap

*/
export declare function isWeakMap(payload: any): payload is WeakMap<any, any>;
declare function isWeakMap(payload: any): payload is WeakMap<any, any>;
/**

@@ -203,3 +203,3 @@ * Returns whether the payload is a Set

*/
export declare function isSet(payload: any): payload is Set<any>;
declare function isSet(payload: any): payload is Set<any>;
/**

@@ -211,3 +211,3 @@ * Returns whether the payload is a WeakSet

*/
export declare function isWeakSet(payload: any): payload is WeakSet<any>;
declare function isWeakSet(payload: any): payload is WeakSet<any>;
/**

@@ -219,3 +219,3 @@ * Returns whether the payload is a Symbol

*/
export declare function isSymbol(payload: any): payload is symbol;
declare function isSymbol(payload: any): payload is symbol;
/**

@@ -227,3 +227,3 @@ * Returns whether the payload is a Date, and that the date is valid

*/
export declare function isDate(payload: any): payload is Date;
declare function isDate(payload: any): payload is Date;
/**

@@ -235,3 +235,3 @@ * Returns whether the payload is a Blob

*/
export declare function isBlob(payload: any): payload is Blob;
declare function isBlob(payload: any): payload is Blob;
/**

@@ -243,3 +243,3 @@ * Returns whether the payload is a File

*/
export declare function isFile(payload: any): payload is File;
declare function isFile(payload: any): payload is File;
/**

@@ -251,3 +251,3 @@ * Returns whether the payload is a Promise

*/
export declare function isPromise(payload: any): payload is Promise<any>;
declare function isPromise(payload: any): payload is Promise<any>;
/**

@@ -259,3 +259,3 @@ * Returns whether the payload is an Error

*/
export declare function isError(payload: any): payload is Error;
declare function isError(payload: any): payload is Error;
/**

@@ -267,3 +267,3 @@ * Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)

*/
export declare function isNaNValue(payload: any): payload is typeof NaN;
declare function isNaNValue(payload: any): payload is typeof NaN;
/**

@@ -275,3 +275,3 @@ * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)

*/
export declare function isPrimitive(payload: any): payload is boolean | null | undefined | number | string | symbol;
declare function isPrimitive(payload: any): payload is boolean | null | undefined | number | string | symbol;
/**

@@ -283,7 +283,7 @@ * Returns true whether the payload is null or undefined

*/
export declare const isNullOrUndefined: TypeGuard<any, null | undefined>;
export declare function isOneOf<A, B extends A, C extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>): TypeGuard<A, B | C>;
export declare function isOneOf<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>;
export declare function isOneOf<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>;
export declare function isOneOf<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>;
declare const isNullOrUndefined: TypeGuard<any, null | undefined>;
declare function isOneOf<A, B extends A, C extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>): TypeGuard<A, B | C>;
declare function isOneOf<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>;
declare function isOneOf<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>;
declare function isOneOf<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>;
/**

@@ -300,3 +300,4 @@ * Does a generic check to check that the given payload is of a given type.

*/
export declare function isType<T extends AnyFunction | AnyClass>(payload: any, type: T): payload is T;
export {};
declare function isType<T extends AnyFunction | AnyClass>(payload: any, type: T): payload is T;
export { AnyAsyncFunction, AnyClass, AnyFunction, PlainObject, getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyArray, isEmptyObject, isEmptyString, isError, isFile, isFullArray, isFullObject, isFullString, isFunction, isMap, isNaNValue, isNegativeNumber, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isOneOf, isPlainObject, isPositiveNumber, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };

@@ -1,344 +0,118 @@

/**
* Returns the object type of the given payload
*
* @param {*} payload
* @returns {string}
*/
function getType(payload) {
return Object.prototype.toString.call(payload).slice(8, -1);
return Object.prototype.toString.call(payload).slice(8, -1);
}
/**
* Returns whether the payload is undefined
*
* @param {*} payload
* @returns {payload is undefined}
*/
function isUndefined(payload) {
return getType(payload) === 'Undefined';
return getType(payload) === "Undefined";
}
/**
* Returns whether the payload is null
*
* @param {*} payload
* @returns {payload is null}
*/
function isNull(payload) {
return getType(payload) === 'Null';
return getType(payload) === "Null";
}
/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isPlainObject(payload) {
if (getType(payload) !== 'Object')
return false;
const prototype = Object.getPrototypeOf(payload);
return prototype.constructor === Object && prototype === Object.prototype;
if (getType(payload) !== "Object")
return false;
const prototype = Object.getPrototypeOf(payload);
return prototype.constructor === Object && prototype === Object.prototype;
}
/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isObject(payload) {
return isPlainObject(payload);
return isPlainObject(payload);
}
/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is { [K in any]: never }}
*/
function isEmptyObject(payload) {
return isPlainObject(payload) && Object.keys(payload).length === 0;
return isPlainObject(payload) && Object.keys(payload).length === 0;
}
/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isFullObject(payload) {
return isPlainObject(payload) && Object.keys(payload).length > 0;
return isPlainObject(payload) && Object.keys(payload).length > 0;
}
/**
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isAnyObject(payload) {
return getType(payload) === 'Object';
return getType(payload) === "Object";
}
/**
* 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.
*
* @template T this must be passed in < >
* @param {*} payload
* @returns {payload is T}
*/
function isObjectLike(payload) {
return isAnyObject(payload);
return isAnyObject(payload);
}
/**
* Returns whether the payload is a function (regular or async)
*
* @param {*} payload
* @returns {payload is AnyFunction}
*/
function isFunction(payload) {
return typeof payload === 'function';
return typeof payload === "function";
}
/**
* Returns whether the payload is an array
*
* @param {any} payload
* @returns {payload is any[]}
*/
function isArray(payload) {
return getType(payload) === 'Array';
return getType(payload) === "Array";
}
/**
* Returns whether the payload is a an array with at least 1 item
*
* @param {*} payload
* @returns {payload is any[]}
*/
function isFullArray(payload) {
return isArray(payload) && payload.length > 0;
return isArray(payload) && payload.length > 0;
}
/**
* Returns whether the payload is a an empty array
*
* @param {*} payload
* @returns {payload is []}
*/
function isEmptyArray(payload) {
return isArray(payload) && payload.length === 0;
return isArray(payload) && payload.length === 0;
}
/**
* Returns whether the payload is a string
*
* @param {*} payload
* @returns {payload is string}
*/
function isString(payload) {
return getType(payload) === 'String';
return getType(payload) === "String";
}
/**
* Returns whether the payload is a string, BUT returns false for ''
*
* @param {*} payload
* @returns {payload is string}
*/
function isFullString(payload) {
return isString(payload) && payload !== '';
return isString(payload) && payload !== "";
}
/**
* Returns whether the payload is ''
*
* @param {*} payload
* @returns {payload is string}
*/
function isEmptyString(payload) {
return payload === '';
return payload === "";
}
/**
* Returns whether the payload is a number (but not NaN)
*
* This will return `false` for `NaN`!!
*
* @param {*} payload
* @returns {payload is number}
*/
function isNumber(payload) {
return getType(payload) === 'Number' && !isNaN(payload);
return getType(payload) === "Number" && !isNaN(payload);
}
/**
* Returns whether the payload is a positive number (but not 0)
*
* @param {*} payload
* @returns {payload is number}
*/
function isPositiveNumber(payload) {
return isNumber(payload) && payload > 0;
return isNumber(payload) && payload > 0;
}
/**
* Returns whether the payload is a negative number (but not 0)
*
* @param {*} payload
* @returns {payload is number}
*/
function isNegativeNumber(payload) {
return isNumber(payload) && payload < 0;
return isNumber(payload) && payload < 0;
}
/**
* Returns whether the payload is a boolean
*
* @param {*} payload
* @returns {payload is boolean}
*/
function isBoolean(payload) {
return getType(payload) === 'Boolean';
return getType(payload) === "Boolean";
}
/**
* Returns whether the payload is a regular expression (RegExp)
*
* @param {*} payload
* @returns {payload is RegExp}
*/
function isRegExp(payload) {
return getType(payload) === 'RegExp';
return getType(payload) === "RegExp";
}
/**
* Returns whether the payload is a Map
*
* @param {*} payload
* @returns {payload is Map<any, any>}
*/
function isMap(payload) {
return getType(payload) === 'Map';
return getType(payload) === "Map";
}
/**
* Returns whether the payload is a WeakMap
*
* @param {*} payload
* @returns {payload is WeakMap<any, any>}
*/
function isWeakMap(payload) {
return getType(payload) === 'WeakMap';
return getType(payload) === "WeakMap";
}
/**
* Returns whether the payload is a Set
*
* @param {*} payload
* @returns {payload is Set<any>}
*/
function isSet(payload) {
return getType(payload) === 'Set';
return getType(payload) === "Set";
}
/**
* Returns whether the payload is a WeakSet
*
* @param {*} payload
* @returns {payload is WeakSet<any>}
*/
function isWeakSet(payload) {
return getType(payload) === 'WeakSet';
return getType(payload) === "WeakSet";
}
/**
* Returns whether the payload is a Symbol
*
* @param {*} payload
* @returns {payload is symbol}
*/
function isSymbol(payload) {
return getType(payload) === 'Symbol';
return getType(payload) === "Symbol";
}
/**
* Returns whether the payload is a Date, and that the date is valid
*
* @param {*} payload
* @returns {payload is Date}
*/
function isDate(payload) {
return getType(payload) === 'Date' && !isNaN(payload);
return getType(payload) === "Date" && !isNaN(payload);
}
/**
* Returns whether the payload is a Blob
*
* @param {*} payload
* @returns {payload is Blob}
*/
function isBlob(payload) {
return getType(payload) === 'Blob';
return getType(payload) === "Blob";
}
/**
* Returns whether the payload is a File
*
* @param {*} payload
* @returns {payload is File}
*/
function isFile(payload) {
return getType(payload) === 'File';
return getType(payload) === "File";
}
/**
* Returns whether the payload is a Promise
*
* @param {*} payload
* @returns {payload is Promise<any>}
*/
function isPromise(payload) {
return getType(payload) === 'Promise';
return getType(payload) === "Promise";
}
/**
* Returns whether the payload is an Error
*
* @param {*} payload
* @returns {payload is Error}
*/
function isError(payload) {
return getType(payload) === 'Error';
return getType(payload) === "Error";
}
/**
* Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)
*
* @param {*} payload
* @returns {payload is typeof NaN}
*/
function isNaNValue(payload) {
return getType(payload) === 'Number' && isNaN(payload);
return getType(payload) === "Number" && isNaN(payload);
}
/**
* Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
*
* @param {*} payload
* @returns {(payload is boolean | null | undefined | number | string | symbol)}
*/
function isPrimitive(payload) {
return (isBoolean(payload) ||
isNull(payload) ||
isUndefined(payload) ||
isNumber(payload) ||
isString(payload) ||
isSymbol(payload));
return isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
}
/**
* Returns true whether the payload is null or undefined
*
* @param {*} payload
* @returns {(payload is null | undefined)}
*/
const isNullOrUndefined = isOneOf(isNull, isUndefined);
function isOneOf(a, b, c, d, e) {
return (value) => a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value));
return (value) => a(value) || b(value) || !!c && c(value) || !!d && d(value) || !!e && e(value);
}
/**
* 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
*
* @template T
* @param {*} payload
* @param {T} type
* @throws {TypeError} Will throw type error if type is an invalid type
* @returns {payload is T}
*/
function isType(payload, type) {
if (!(type instanceof Function)) {
throw new TypeError('Type must be a function');
}
if (!Object.prototype.hasOwnProperty.call(type, 'prototype')) {
throw new TypeError('Type is not a class');
}
// Classes usually have names (as functions usually have names)
const name = type.name;
return getType(payload) === name || Boolean(payload && payload.constructor === type);
if (!(type instanceof Function)) {
throw new TypeError("Type must be a function");
}
if (!Object.prototype.hasOwnProperty.call(type, "prototype")) {
throw new TypeError("Type is not a class");
}
const name = type.name;
return getType(payload) === name || Boolean(payload && payload.constructor === type);
}
export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyArray, isEmptyObject, isEmptyString, isError, isFile, isFullArray, isFullObject, isFullString, isFunction, isMap, isNaNValue, isNegativeNumber, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isOneOf, isPlainObject, isPositiveNumber, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };
{
"name": "is-what",
"version": "4.1.11",
"description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.",
"type": "module",
"sideEffects": false,
"type": "module",
"version": "4.1.10",
"description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.",
"types": "./dist/index.d.ts",

@@ -31,3 +31,3 @@ "module": "./dist/index.js",

"lint": "tsc --noEmit && eslint ./src --ext .ts",
"build": "rollup -c ./scripts/rollup.config.js",
"build": "rollup -c ./rollup.config.js",
"release": "npm run lint && del dist && npm run build && np"

@@ -77,3 +77,4 @@ },

"rollup": "^3.22.0",
"rollup-plugin-typescript2": "^0.34.1",
"rollup-plugin-dts": "^5.3.0",
"rollup-plugin-esbuild": "^5.0.0",
"typescript": "^5.0.4",

@@ -80,0 +81,0 @@ "vitest": "^0.31.1"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc