From 42cadb47e87a9b3a3961aba12728c32b307b3cea Mon Sep 17 00:00:00 2001 From: mesqueeb Date: Fri, 24 May 2024 10:17:44 +0900 Subject: [PATCH] fix: `unknown` instead of `any`, closes #12 --- README.md | 12 ++++++------ dist/getType.d.ts | 9 ++------- dist/getType.js | 7 +------ dist/index.d.ts | 2 +- dist/isAnyObject.d.ts | 5 +---- dist/isAnyObject.js | 3 --- dist/isArray.d.ts | 9 ++------- dist/isArray.js | 7 +------ dist/isBlob.d.ts | 9 ++------- dist/isBlob.js | 7 +------ dist/isBoolean.d.ts | 9 ++------- dist/isBoolean.js | 7 +------ dist/isDate.d.ts | 9 ++------- dist/isDate.js | 7 +------ dist/isEmptyArray.d.ts | 9 ++------- dist/isEmptyArray.js | 7 +------ dist/isEmptyObject.d.ts | 7 ++----- dist/isEmptyObject.js | 3 --- dist/isEmptyString.d.ts | 9 ++------- dist/isEmptyString.js | 7 +------ dist/isError.d.ts | 9 ++------- dist/isError.js | 7 +------ dist/isFile.d.ts | 9 ++------- dist/isFile.js | 7 +------ dist/isFullArray.d.ts | 9 ++------- dist/isFullArray.js | 7 +------ dist/isFullObject.d.ts | 5 +---- dist/isFullObject.js | 3 --- dist/isFullString.d.ts | 9 ++------- dist/isFullString.js | 7 +------ dist/isFunction.d.ts | 11 +++-------- dist/isFunction.js | 7 +------ dist/isMap.d.ts | 9 ++------- dist/isMap.js | 7 +------ dist/isNaNValue.d.ts | 9 ++------- dist/isNaNValue.js | 7 +------ dist/isNegativeNumber.d.ts | 9 ++------- dist/isNegativeNumber.js | 7 +------ dist/isNull.d.ts | 9 ++------- dist/isNull.js | 7 +------ dist/isNullOrUndefined.d.ts | 9 ++------- dist/isNullOrUndefined.js | 7 +------ dist/isNumber.d.ts | 5 +---- dist/isNumber.js | 3 --- dist/isObject.d.ts | 5 +---- dist/isObject.js | 3 --- dist/isObjectLike.d.ts | 4 +--- dist/isObjectLike.js | 2 -- dist/isPlainObject.d.ts | 7 ++----- dist/isPlainObject.js | 3 --- dist/isPositiveNumber.d.ts | 9 ++------- dist/isPositiveNumber.js | 7 +------ dist/isPrimitive.d.ts | 6 ++---- dist/isPrimitive.js | 4 +--- dist/isPromise.d.ts | 9 ++------- dist/isPromise.js | 7 +------ dist/isRegExp.d.ts | 9 ++------- dist/isRegExp.js | 7 +------ dist/isSet.d.ts | 9 ++------- dist/isSet.js | 7 +------ dist/isString.d.ts | 9 ++------- dist/isString.js | 7 +------ dist/isSymbol.d.ts | 9 ++------- dist/isSymbol.js | 7 +------ dist/isType.d.ts | 8 ++------ dist/isType.js | 4 ---- dist/isUndefined.d.ts | 9 ++------- dist/isUndefined.js | 7 +------ dist/isWeakMap.d.ts | 9 ++------- dist/isWeakMap.js | 7 +------ dist/isWeakSet.d.ts | 9 ++------- dist/isWeakSet.js | 7 +------ package.json | 3 --- src/getType.ts | 9 ++------- src/index.ts | 2 +- src/isAnyObject.ts | 5 +---- src/isArray.ts | 9 ++------- src/isBlob.ts | 9 ++------- src/isBoolean.ts | 9 ++------- src/isDate.ts | 11 +++-------- src/isEmptyArray.ts | 9 ++------- src/isEmptyObject.ts | 7 +++---- src/isEmptyString.ts | 9 ++------- src/isError.ts | 9 ++------- src/isFile.ts | 9 ++------- src/isFullArray.ts | 9 ++------- src/isFullObject.ts | 5 +---- src/isFullString.ts | 9 ++------- src/isFunction.ts | 11 +++-------- src/isMap.ts | 9 ++------- src/isNaNValue.ts | 11 +++-------- src/isNegativeNumber.ts | 9 ++------- src/isNull.ts | 9 ++------- src/isNullOrUndefined.ts | 7 +------ src/isNumber.ts | 7 ++----- src/isObject.ts | 5 +---- src/isObjectLike.ts | 4 +--- src/isOneOf.ts | 20 +++++++++----------- src/isPlainObject.ts | 7 ++----- src/isPositiveNumber.ts | 9 ++------- src/isPrimitive.ts | 6 ++---- src/isPromise.ts | 9 ++------- src/isRegExp.ts | 9 ++------- src/isSet.ts | 9 ++------- src/isString.ts | 9 ++------- src/isSymbol.ts | 9 ++------- src/isType.ts | 10 +++------- src/isUndefined.ts | 9 ++------- src/isWeakMap.ts | 9 ++------- src/isWeakSet.ts | 9 ++------- test/index.test.ts | 2 +- 111 files changed, 181 insertions(+), 652 deletions(-) diff --git a/README.md b/README.md index f5d782a..d07ebbc 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ isInstanceOf(globalThis, ReadableStream) is-what makes TypeScript know the type during if statements. This means that a check returns the type of the payload for TypeScript users. ```ts -function isNumber(payload: any): payload is number { +function isNumber(payload: unknown): payload is number { // return boolean } // As you can see above, all functions return a boolean for JavaScript, but pass the payload type to TypeScript. @@ -215,9 +215,9 @@ function fn(payload: string | number): number { `isPlainObject` and `isAnyObject` with TypeScript will declare the payload to be an object type with any props: ```ts -function isPlainObject(payload: any): payload is { [key: string]: any } -function isAnyObject(payload: any): payload is { [key: string]: any } -// The reason to return `{[key: string]: any}` is to be able to do +function isPlainObject(payload: unknown): payload is { [key: string]: unknown } +function isAnyObject(payload: unknown): payload is { [key: string]: unknown } +// The reason to return `{[key: string]: unknown}` is to be able to do if (isPlainObject(payload) && payload.id) return payload.id // if isPlainObject() would return `payload is object` then it would give an error at `payload.id` ``` @@ -235,7 +235,7 @@ const payload = { name: 'Mesqueeb' } // current type: `{ name: string }` // Without casting: if (isAnyObject(payload)) { - // in here `payload` is casted to: `Record` + // in here `payload` is casted to: `Record` // WE LOOSE THE TYPE! } @@ -251,7 +251,7 @@ Please note: this library will not actually check the shape of the object, you n `isObjectLike` works like this under the hood: ```ts -function isObjectLike(payload: any): payload is T { +function isObjectLike(payload: unknown): payload is T { return isAnyObject(payload) } ``` diff --git a/dist/getType.d.ts b/dist/getType.d.ts index 115b264..fec63ac 100644 --- a/dist/getType.d.ts +++ b/dist/getType.d.ts @@ -1,7 +1,2 @@ -/** - * Returns the object type of the given payload - * - * @param {any} payload - * @returns {string} - */ -export declare function getType(payload: any): string; +/** Returns the object type of the given payload */ +export declare function getType(payload: unknown): string; diff --git a/dist/getType.js b/dist/getType.js index 0bf3d84..8c30500 100644 --- a/dist/getType.js +++ b/dist/getType.js @@ -1,9 +1,4 @@ -/** - * Returns the object type of the given payload - * - * @param {any} payload - * @returns {string} - */ +/** Returns the object type of the given payload */ export function getType(payload) { return Object.prototype.toString.call(payload).slice(8, -1); } diff --git a/dist/index.d.ts b/dist/index.d.ts index 127e2f8..5c6ce59 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,4 +1,4 @@ -export type AnyAsyncFunction = (...args: any[]) => Promise; +export type AnyAsyncFunction = (...args: unknown[]) => Promise; export { getType } from './getType.js'; export { isAnyObject } from './isAnyObject.js'; export { isArray } from './isArray.js'; diff --git a/dist/isAnyObject.d.ts b/dist/isAnyObject.d.ts index 8ac69fc..3eea4a5 100644 --- a/dist/isAnyObject.d.ts +++ b/dist/isAnyObject.d.ts @@ -2,8 +2,5 @@ import { PlainObject } from './isPlainObject.js'; /** * Returns whether the payload is an any kind of object (including special classes or objects with * different prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ -export declare function isAnyObject(payload: any): payload is PlainObject; +export declare function isAnyObject(payload: unknown): payload is PlainObject; diff --git a/dist/isAnyObject.js b/dist/isAnyObject.js index 49239cd..860597f 100644 --- a/dist/isAnyObject.js +++ b/dist/isAnyObject.js @@ -2,9 +2,6 @@ import { getType } from './getType.js'; /** * Returns whether the payload is an any kind of object (including special classes or objects with * different prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ export function isAnyObject(payload) { return getType(payload) === 'Object'; diff --git a/dist/isArray.d.ts b/dist/isArray.d.ts index 432bffc..a02695a 100644 --- a/dist/isArray.d.ts +++ b/dist/isArray.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is an array - * - * @param {any} payload - * @returns {payload is any[]} - */ -export declare function isArray(payload: any): payload is any[]; +/** Returns whether the payload is an array */ +export declare function isArray(payload: unknown): payload is unknown[]; diff --git a/dist/isArray.js b/dist/isArray.js index b41c1b2..c2a6b7c 100644 --- a/dist/isArray.js +++ b/dist/isArray.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is an array - * - * @param {any} payload - * @returns {payload is any[]} - */ +/** Returns whether the payload is an array */ export function isArray(payload) { return getType(payload) === 'Array'; } diff --git a/dist/isBlob.d.ts b/dist/isBlob.d.ts index 45b343d..66a7972 100644 --- a/dist/isBlob.d.ts +++ b/dist/isBlob.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a Blob - * - * @param {any} payload - * @returns {payload is Blob} - */ -export declare function isBlob(payload: any): payload is Blob; +/** Returns whether the payload is a Blob */ +export declare function isBlob(payload: unknown): payload is Blob; diff --git a/dist/isBlob.js b/dist/isBlob.js index 81d9dbf..b43023f 100644 --- a/dist/isBlob.js +++ b/dist/isBlob.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a Blob - * - * @param {any} payload - * @returns {payload is Blob} - */ +/** Returns whether the payload is a Blob */ export function isBlob(payload) { return getType(payload) === 'Blob'; } diff --git a/dist/isBoolean.d.ts b/dist/isBoolean.d.ts index 1a36611..e7c1314 100644 --- a/dist/isBoolean.d.ts +++ b/dist/isBoolean.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a boolean - * - * @param {any} payload - * @returns {payload is boolean} - */ -export declare function isBoolean(payload: any): payload is boolean; +/** Returns whether the payload is a boolean */ +export declare function isBoolean(payload: unknown): payload is boolean; diff --git a/dist/isBoolean.js b/dist/isBoolean.js index 9ed880f..a2f88b3 100644 --- a/dist/isBoolean.js +++ b/dist/isBoolean.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a boolean - * - * @param {any} payload - * @returns {payload is boolean} - */ +/** Returns whether the payload is a boolean */ export function isBoolean(payload) { return getType(payload) === 'Boolean'; } diff --git a/dist/isDate.d.ts b/dist/isDate.d.ts index cff9e83..e52510f 100644 --- a/dist/isDate.d.ts +++ b/dist/isDate.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a Date, and that the date is valid - * - * @param {any} payload - * @returns {payload is Date} - */ -export declare function isDate(payload: any): payload is Date; +/** Returns whether the payload is a Date, and that the date is valid */ +export declare function isDate(payload: unknown): payload is Date; diff --git a/dist/isDate.js b/dist/isDate.js index 8af53e2..6378513 100644 --- a/dist/isDate.js +++ b/dist/isDate.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a Date, and that the date is valid - * - * @param {any} payload - * @returns {payload is Date} - */ +/** Returns whether the payload is a Date, and that the date is valid */ export function isDate(payload) { return getType(payload) === 'Date' && !isNaN(payload); } diff --git a/dist/isEmptyArray.d.ts b/dist/isEmptyArray.d.ts index b7ef562..0993cf2 100644 --- a/dist/isEmptyArray.d.ts +++ b/dist/isEmptyArray.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a an empty array - * - * @param {any} payload - * @returns {payload is []} - */ -export declare function isEmptyArray(payload: any): payload is []; +/** Returns whether the payload is a an empty array */ +export declare function isEmptyArray(payload: unknown): payload is []; diff --git a/dist/isEmptyArray.js b/dist/isEmptyArray.js index 0371a55..4e1b912 100644 --- a/dist/isEmptyArray.js +++ b/dist/isEmptyArray.js @@ -1,10 +1,5 @@ import { isArray } from './isArray.js'; -/** - * Returns whether the payload is a an empty array - * - * @param {any} payload - * @returns {payload is []} - */ +/** Returns whether the payload is a an empty array */ export function isEmptyArray(payload) { return isArray(payload) && payload.length === 0; } diff --git a/dist/isEmptyObject.d.ts b/dist/isEmptyObject.d.ts index 37a6e52..fdac554 100644 --- a/dist/isEmptyObject.d.ts +++ b/dist/isEmptyObject.d.ts @@ -1,10 +1,7 @@ /** * Returns whether the payload is a an empty object (excluding special classes or objects with other * prototypes) - * - * @param {any} payload - * @returns {payload is { [K in any]: never }} */ -export declare function isEmptyObject(payload: any): payload is { - [K in any]: never; +export declare function isEmptyObject(payload: unknown): payload is { + [K in string | symbol | number]: never; }; diff --git a/dist/isEmptyObject.js b/dist/isEmptyObject.js index 6440e10..4edfc65 100644 --- a/dist/isEmptyObject.js +++ b/dist/isEmptyObject.js @@ -2,9 +2,6 @@ import { isPlainObject } from './isPlainObject.js'; /** * Returns whether the payload is a an empty object (excluding special classes or objects with other * prototypes) - * - * @param {any} payload - * @returns {payload is { [K in any]: never }} */ export function isEmptyObject(payload) { return isPlainObject(payload) && Object.keys(payload).length === 0; diff --git a/dist/isEmptyString.d.ts b/dist/isEmptyString.d.ts index 1dc0d51..fc0032e 100644 --- a/dist/isEmptyString.d.ts +++ b/dist/isEmptyString.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is '' - * - * @param {any} payload - * @returns {payload is string} - */ -export declare function isEmptyString(payload: any): payload is string; +/** Returns whether the payload is '' */ +export declare function isEmptyString(payload: unknown): payload is string; diff --git a/dist/isEmptyString.js b/dist/isEmptyString.js index 1ac90f6..62446bc 100644 --- a/dist/isEmptyString.js +++ b/dist/isEmptyString.js @@ -1,9 +1,4 @@ -/** - * Returns whether the payload is '' - * - * @param {any} payload - * @returns {payload is string} - */ +/** Returns whether the payload is '' */ export function isEmptyString(payload) { return payload === ''; } diff --git a/dist/isError.d.ts b/dist/isError.d.ts index dc160ee..2a77c2f 100644 --- a/dist/isError.d.ts +++ b/dist/isError.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is an Error - * - * @param {any} payload - * @returns {payload is Error} - */ -export declare function isError(payload: any): payload is Error; +/** Returns whether the payload is an Error */ +export declare function isError(payload: unknown): payload is Error; diff --git a/dist/isError.js b/dist/isError.js index 097efa0..8c3bca2 100644 --- a/dist/isError.js +++ b/dist/isError.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is an Error - * - * @param {any} payload - * @returns {payload is Error} - */ +/** Returns whether the payload is an Error */ export function isError(payload) { return getType(payload) === 'Error' || payload instanceof Error; } diff --git a/dist/isFile.d.ts b/dist/isFile.d.ts index d330cc1..d03d724 100644 --- a/dist/isFile.d.ts +++ b/dist/isFile.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a File - * - * @param {any} payload - * @returns {payload is File} - */ -export declare function isFile(payload: any): payload is File; +/** Returns whether the payload is a File */ +export declare function isFile(payload: unknown): payload is File; diff --git a/dist/isFile.js b/dist/isFile.js index 910fa02..bf33f7d 100644 --- a/dist/isFile.js +++ b/dist/isFile.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a File - * - * @param {any} payload - * @returns {payload is File} - */ +/** Returns whether the payload is a File */ export function isFile(payload) { return getType(payload) === 'File'; } diff --git a/dist/isFullArray.d.ts b/dist/isFullArray.d.ts index cef0f96..c98b78f 100644 --- a/dist/isFullArray.d.ts +++ b/dist/isFullArray.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a an array with at least 1 item - * - * @param {any} payload - * @returns {payload is any[]} - */ -export declare function isFullArray(payload: any): payload is any[]; +/** Returns whether the payload is a an array with at least 1 item */ +export declare function isFullArray(payload: unknown): payload is unknown[]; diff --git a/dist/isFullArray.js b/dist/isFullArray.js index c8a5afb..5031718 100644 --- a/dist/isFullArray.js +++ b/dist/isFullArray.js @@ -1,10 +1,5 @@ import { isArray } from './isArray.js'; -/** - * Returns whether the payload is a an array with at least 1 item - * - * @param {any} payload - * @returns {payload is any[]} - */ +/** Returns whether the payload is a an array with at least 1 item */ export function isFullArray(payload) { return isArray(payload) && payload.length > 0; } diff --git a/dist/isFullObject.d.ts b/dist/isFullObject.d.ts index a729953..63b50b1 100644 --- a/dist/isFullObject.d.ts +++ b/dist/isFullObject.d.ts @@ -2,8 +2,5 @@ import { PlainObject } from './isPlainObject.js'; /** * Returns whether the payload is a an empty object (excluding special classes or objects with other * prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ -export declare function isFullObject(payload: any): payload is PlainObject; +export declare function isFullObject(payload: unknown): payload is PlainObject; diff --git a/dist/isFullObject.js b/dist/isFullObject.js index 3a9b622..2a435f9 100644 --- a/dist/isFullObject.js +++ b/dist/isFullObject.js @@ -2,9 +2,6 @@ import { isPlainObject } from './isPlainObject.js'; /** * Returns whether the payload is a an empty object (excluding special classes or objects with other * prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ export function isFullObject(payload) { return isPlainObject(payload) && Object.keys(payload).length > 0; diff --git a/dist/isFullString.d.ts b/dist/isFullString.d.ts index 08f3891..2c04d5b 100644 --- a/dist/isFullString.d.ts +++ b/dist/isFullString.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a string, BUT returns false for '' - * - * @param {any} payload - * @returns {payload is string} - */ -export declare function isFullString(payload: any): payload is string; +/** Returns whether the payload is a string, BUT returns false for '' */ +export declare function isFullString(payload: unknown): payload is string; diff --git a/dist/isFullString.js b/dist/isFullString.js index fd76805..42fac0d 100644 --- a/dist/isFullString.js +++ b/dist/isFullString.js @@ -1,10 +1,5 @@ import { isString } from './isString.js'; -/** - * Returns whether the payload is a string, BUT returns false for '' - * - * @param {any} payload - * @returns {payload is string} - */ +/** Returns whether the payload is a string, BUT returns false for '' */ export function isFullString(payload) { return isString(payload) && payload !== ''; } diff --git a/dist/isFunction.d.ts b/dist/isFunction.d.ts index 0befed2..d37eef6 100644 --- a/dist/isFunction.d.ts +++ b/dist/isFunction.d.ts @@ -1,8 +1,3 @@ -export type AnyFunction = (...args: any[]) => any; -/** - * Returns whether the payload is a function (regular or async) - * - * @param {any} payload - * @returns {payload is AnyFunction} - */ -export declare function isFunction(payload: any): payload is AnyFunction; +export type AnyFunction = (...args: unknown[]) => unknown; +/** Returns whether the payload is a function (regular or async) */ +export declare function isFunction(payload: unknown): payload is AnyFunction; diff --git a/dist/isFunction.js b/dist/isFunction.js index 898f941..3c7ea9f 100644 --- a/dist/isFunction.js +++ b/dist/isFunction.js @@ -1,9 +1,4 @@ -/** - * Returns whether the payload is a function (regular or async) - * - * @param {any} payload - * @returns {payload is AnyFunction} - */ +/** Returns whether the payload is a function (regular or async) */ export function isFunction(payload) { return typeof payload === 'function'; } diff --git a/dist/isMap.d.ts b/dist/isMap.d.ts index 1fb8471..04bbd7f 100644 --- a/dist/isMap.d.ts +++ b/dist/isMap.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a Map - * - * @param {any} payload - * @returns {payload is Map} - */ -export declare function isMap(payload: any): payload is Map; +/** Returns whether the payload is a Map */ +export declare function isMap(payload: unknown): payload is Map; diff --git a/dist/isMap.js b/dist/isMap.js index f4b2d50..ac3a0c3 100644 --- a/dist/isMap.js +++ b/dist/isMap.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a Map - * - * @param {any} payload - * @returns {payload is Map} - */ +/** Returns whether the payload is a Map */ export function isMap(payload) { return getType(payload) === 'Map'; } diff --git a/dist/isNaNValue.d.ts b/dist/isNaNValue.d.ts index 70b2949..6f18e06 100644 --- a/dist/isNaNValue.d.ts +++ b/dist/isNaNValue.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`) - * - * @param {any} payload - * @returns {payload is typeof NaN} - */ -export declare function isNaNValue(payload: any): payload is typeof NaN; +/** Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`) */ +export declare function isNaNValue(payload: unknown): payload is typeof NaN; diff --git a/dist/isNaNValue.js b/dist/isNaNValue.js index d50a931..2d72642 100644 --- a/dist/isNaNValue.js +++ b/dist/isNaNValue.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`) - * - * @param {any} payload - * @returns {payload is typeof NaN} - */ +/** Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`) */ export function isNaNValue(payload) { return getType(payload) === 'Number' && isNaN(payload); } diff --git a/dist/isNegativeNumber.d.ts b/dist/isNegativeNumber.d.ts index e7c5482..ca8f694 100644 --- a/dist/isNegativeNumber.d.ts +++ b/dist/isNegativeNumber.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a negative number (but not 0) - * - * @param {any} payload - * @returns {payload is number} - */ -export declare function isNegativeNumber(payload: any): payload is number; +/** Returns whether the payload is a negative number (but not 0) */ +export declare function isNegativeNumber(payload: unknown): payload is number; diff --git a/dist/isNegativeNumber.js b/dist/isNegativeNumber.js index 0cf787b..d858666 100644 --- a/dist/isNegativeNumber.js +++ b/dist/isNegativeNumber.js @@ -1,10 +1,5 @@ import { isNumber } from './isNumber.js'; -/** - * Returns whether the payload is a negative number (but not 0) - * - * @param {any} payload - * @returns {payload is number} - */ +/** Returns whether the payload is a negative number (but not 0) */ export function isNegativeNumber(payload) { return isNumber(payload) && payload < 0; } diff --git a/dist/isNull.d.ts b/dist/isNull.d.ts index fa0bfc2..6995354 100644 --- a/dist/isNull.d.ts +++ b/dist/isNull.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is null - * - * @param {any} payload - * @returns {payload is null} - */ -export declare function isNull(payload: any): payload is null; +/** Returns whether the payload is null */ +export declare function isNull(payload: unknown): payload is null; diff --git a/dist/isNull.js b/dist/isNull.js index 5b913de..ccd3f08 100644 --- a/dist/isNull.js +++ b/dist/isNull.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is null - * - * @param {any} payload - * @returns {payload is null} - */ +/** Returns whether the payload is null */ export function isNull(payload) { return getType(payload) === 'Null'; } diff --git a/dist/isNullOrUndefined.d.ts b/dist/isNullOrUndefined.d.ts index 0ccb8d2..a733a64 100644 --- a/dist/isNullOrUndefined.d.ts +++ b/dist/isNullOrUndefined.d.ts @@ -1,7 +1,2 @@ -/** - * Returns true whether the payload is null or undefined - * - * @param {any} payload - * @returns {(payload is null | undefined)} - */ -export declare const isNullOrUndefined: (payload: any) => payload is null | undefined; +/** Returns true whether the payload is null or undefined */ +export declare const isNullOrUndefined: (payload: unknown) => payload is null | undefined; diff --git a/dist/isNullOrUndefined.js b/dist/isNullOrUndefined.js index c8d69ee..442e268 100644 --- a/dist/isNullOrUndefined.js +++ b/dist/isNullOrUndefined.js @@ -1,10 +1,5 @@ import { isNull } from './isNull.js'; import { /* tree-shaking no-side-effects-when-called */ isOneOf } from './isOneOf.js'; import { isUndefined } from './isUndefined.js'; -/** - * Returns true whether the payload is null or undefined - * - * @param {any} payload - * @returns {(payload is null | undefined)} - */ +/** Returns true whether the payload is null or undefined */ export const isNullOrUndefined = isOneOf(isNull, isUndefined); diff --git a/dist/isNumber.d.ts b/dist/isNumber.d.ts index c806537..5017d5e 100644 --- a/dist/isNumber.d.ts +++ b/dist/isNumber.d.ts @@ -2,8 +2,5 @@ * Returns whether the payload is a number (but not NaN) * * This will return `false` for `NaN`!! - * - * @param {any} payload - * @returns {payload is number} */ -export declare function isNumber(payload: any): payload is number; +export declare function isNumber(payload: unknown): payload is number; diff --git a/dist/isNumber.js b/dist/isNumber.js index b9abc84..11e5ff3 100644 --- a/dist/isNumber.js +++ b/dist/isNumber.js @@ -3,9 +3,6 @@ import { getType } from './getType.js'; * Returns whether the payload is a number (but not NaN) * * This will return `false` for `NaN`!! - * - * @param {any} payload - * @returns {payload is number} */ export function isNumber(payload) { return getType(payload) === 'Number' && !isNaN(payload); diff --git a/dist/isObject.d.ts b/dist/isObject.d.ts index 3e695c5..ca43e31 100644 --- a/dist/isObject.d.ts +++ b/dist/isObject.d.ts @@ -2,8 +2,5 @@ import { PlainObject } from './isPlainObject.js'; /** * Returns whether the payload is a plain JavaScript object (excluding special classes or objects * with other prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ -export declare function isObject(payload: any): payload is PlainObject; +export declare function isObject(payload: unknown): payload is PlainObject; diff --git a/dist/isObject.js b/dist/isObject.js index 1c01c80..42dbf35 100644 --- a/dist/isObject.js +++ b/dist/isObject.js @@ -2,9 +2,6 @@ import { isPlainObject } from './isPlainObject.js'; /** * Returns whether the payload is a plain JavaScript object (excluding special classes or objects * with other prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ export function isObject(payload) { return isPlainObject(payload); diff --git a/dist/isObjectLike.d.ts b/dist/isObjectLike.d.ts index 4a68cc2..ff14f27 100644 --- a/dist/isObjectLike.d.ts +++ b/dist/isObjectLike.d.ts @@ -5,7 +5,5 @@ import { PlainObject } from './isPlainObject.js'; * 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 {any} payload - * @returns {payload is T} */ -export declare function isObjectLike(payload: any): payload is T; +export declare function isObjectLike(payload: unknown): payload is T; diff --git a/dist/isObjectLike.js b/dist/isObjectLike.js index 5df6297..504a57a 100644 --- a/dist/isObjectLike.js +++ b/dist/isObjectLike.js @@ -5,8 +5,6 @@ import { isAnyObject } from './isAnyObject.js'; * 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 {any} payload - * @returns {payload is T} */ export function isObjectLike(payload) { return isAnyObject(payload); diff --git a/dist/isPlainObject.d.ts b/dist/isPlainObject.d.ts index a7e1900..ca18238 100644 --- a/dist/isPlainObject.d.ts +++ b/dist/isPlainObject.d.ts @@ -1,9 +1,6 @@ -export type PlainObject = Record; +export type PlainObject = Record; /** * Returns whether the payload is a plain JavaScript object (excluding special classes or objects * with other prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ -export declare function isPlainObject(payload: any): payload is PlainObject; +export declare function isPlainObject(payload: unknown): payload is PlainObject; diff --git a/dist/isPlainObject.js b/dist/isPlainObject.js index aee3d36..b1e206f 100644 --- a/dist/isPlainObject.js +++ b/dist/isPlainObject.js @@ -2,9 +2,6 @@ import { getType } from './getType.js'; /** * Returns whether the payload is a plain JavaScript object (excluding special classes or objects * with other prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ export function isPlainObject(payload) { if (getType(payload) !== 'Object') diff --git a/dist/isPositiveNumber.d.ts b/dist/isPositiveNumber.d.ts index c3329ff..c745acd 100644 --- a/dist/isPositiveNumber.d.ts +++ b/dist/isPositiveNumber.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a positive number (but not 0) - * - * @param {any} payload - * @returns {payload is number} - */ -export declare function isPositiveNumber(payload: any): payload is number; +/** Returns whether the payload is a positive number (but not 0) */ +export declare function isPositiveNumber(payload: unknown): payload is number; diff --git a/dist/isPositiveNumber.js b/dist/isPositiveNumber.js index 4b47bfd..16fbc9b 100644 --- a/dist/isPositiveNumber.js +++ b/dist/isPositiveNumber.js @@ -1,10 +1,5 @@ import { isNumber } from './isNumber.js'; -/** - * Returns whether the payload is a positive number (but not 0) - * - * @param {any} payload - * @returns {payload is number} - */ +/** Returns whether the payload is a positive number (but not 0) */ export function isPositiveNumber(payload) { return isNumber(payload) && payload > 0; } diff --git a/dist/isPrimitive.d.ts b/dist/isPrimitive.d.ts index d957f69..1d5aa7b 100644 --- a/dist/isPrimitive.d.ts +++ b/dist/isPrimitive.d.ts @@ -1,8 +1,6 @@ /** * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String - * | Symbol) * - * @param {any} payload - * @returns {(payload is boolean | null | undefined | number | string | symbol)} + * | Symbol) */ -export declare function isPrimitive(payload: any): payload is boolean | null | undefined | number | string | symbol; +export declare function isPrimitive(payload: unknown): payload is boolean | null | undefined | number | string | symbol; diff --git a/dist/isPrimitive.js b/dist/isPrimitive.js index 9953fbe..8ca7c95 100644 --- a/dist/isPrimitive.js +++ b/dist/isPrimitive.js @@ -6,10 +6,8 @@ import { isSymbol } from './isSymbol.js'; import { isUndefined } from './isUndefined.js'; /** * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String - * | Symbol) * - * @param {any} payload - * @returns {(payload is boolean | null | undefined | number | string | symbol)} + * | Symbol) */ export function isPrimitive(payload) { return (isBoolean(payload) || diff --git a/dist/isPromise.d.ts b/dist/isPromise.d.ts index 0687398..67ce6c9 100644 --- a/dist/isPromise.d.ts +++ b/dist/isPromise.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a Promise - * - * @param {any} payload - * @returns {payload is Promise} - */ -export declare function isPromise(payload: any): payload is Promise; +/** Returns whether the payload is a Promise */ +export declare function isPromise(payload: unknown): payload is Promise; diff --git a/dist/isPromise.js b/dist/isPromise.js index 786774e..5ac3f2d 100644 --- a/dist/isPromise.js +++ b/dist/isPromise.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a Promise - * - * @param {any} payload - * @returns {payload is Promise} - */ +/** Returns whether the payload is a Promise */ export function isPromise(payload) { return getType(payload) === 'Promise'; } diff --git a/dist/isRegExp.d.ts b/dist/isRegExp.d.ts index 3e0f96a..8390188 100644 --- a/dist/isRegExp.d.ts +++ b/dist/isRegExp.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a regular expression (RegExp) - * - * @param {any} payload - * @returns {payload is RegExp} - */ -export declare function isRegExp(payload: any): payload is RegExp; +/** Returns whether the payload is a regular expression (RegExp) */ +export declare function isRegExp(payload: unknown): payload is RegExp; diff --git a/dist/isRegExp.js b/dist/isRegExp.js index b9b9483..6063bc2 100644 --- a/dist/isRegExp.js +++ b/dist/isRegExp.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a regular expression (RegExp) - * - * @param {any} payload - * @returns {payload is RegExp} - */ +/** Returns whether the payload is a regular expression (RegExp) */ export function isRegExp(payload) { return getType(payload) === 'RegExp'; } diff --git a/dist/isSet.d.ts b/dist/isSet.d.ts index 336f282..d65795d 100644 --- a/dist/isSet.d.ts +++ b/dist/isSet.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a Set - * - * @param {any} payload - * @returns {payload is Set} - */ -export declare function isSet(payload: any): payload is Set; +/** Returns whether the payload is a Set */ +export declare function isSet(payload: unknown): payload is Set; diff --git a/dist/isSet.js b/dist/isSet.js index 469ae4e..834085b 100644 --- a/dist/isSet.js +++ b/dist/isSet.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a Set - * - * @param {any} payload - * @returns {payload is Set} - */ +/** Returns whether the payload is a Set */ export function isSet(payload) { return getType(payload) === 'Set'; } diff --git a/dist/isString.d.ts b/dist/isString.d.ts index ace38d3..6b2b0ec 100644 --- a/dist/isString.d.ts +++ b/dist/isString.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a string - * - * @param {any} payload - * @returns {payload is string} - */ -export declare function isString(payload: any): payload is string; +/** Returns whether the payload is a string */ +export declare function isString(payload: unknown): payload is string; diff --git a/dist/isString.js b/dist/isString.js index e91877a..3c2c58d 100644 --- a/dist/isString.js +++ b/dist/isString.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a string - * - * @param {any} payload - * @returns {payload is string} - */ +/** Returns whether the payload is a string */ export function isString(payload) { return getType(payload) === 'String'; } diff --git a/dist/isSymbol.d.ts b/dist/isSymbol.d.ts index ecd0a75..0358039 100644 --- a/dist/isSymbol.d.ts +++ b/dist/isSymbol.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a Symbol - * - * @param {any} payload - * @returns {payload is symbol} - */ -export declare function isSymbol(payload: any): payload is symbol; +/** Returns whether the payload is a Symbol */ +export declare function isSymbol(payload: unknown): payload is symbol; diff --git a/dist/isSymbol.js b/dist/isSymbol.js index c1955c8..bff16d8 100644 --- a/dist/isSymbol.js +++ b/dist/isSymbol.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a Symbol - * - * @param {any} payload - * @returns {payload is symbol} - */ +/** Returns whether the payload is a Symbol */ export function isSymbol(payload) { return getType(payload) === 'Symbol'; } diff --git a/dist/isType.d.ts b/dist/isType.d.ts index b3a6820..5a232e0 100644 --- a/dist/isType.d.ts +++ b/dist/isType.d.ts @@ -1,14 +1,10 @@ import { AnyFunction } from './isFunction.js'; -export type AnyClass = new (...args: any[]) => any; +export type AnyClass = new (...args: unknown[]) => unknown; /** * 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 {any} payload - * @param {T} type - * @returns {payload is T} * @throws {TypeError} Will throw type error if type is an invalid type */ -export declare function isType(payload: any, type: T): payload is T; +export declare function isType(payload: unknown, type: T): payload is T; diff --git a/dist/isType.js b/dist/isType.js index c8e246d..dfe7baf 100644 --- a/dist/isType.js +++ b/dist/isType.js @@ -4,10 +4,6 @@ import { getType } from './getType.js'; * will return true for NaN as NaN is a Number (thanks javascript!); It will, however, differentiate * between object and null * - * @template T - * @param {any} payload - * @param {T} type - * @returns {payload is T} * @throws {TypeError} Will throw type error if type is an invalid type */ export function isType(payload, type) { diff --git a/dist/isUndefined.d.ts b/dist/isUndefined.d.ts index c717720..94f3f64 100644 --- a/dist/isUndefined.d.ts +++ b/dist/isUndefined.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is undefined - * - * @param {any} payload - * @returns {payload is undefined} - */ -export declare function isUndefined(payload: any): payload is undefined; +/** Returns whether the payload is undefined */ +export declare function isUndefined(payload: unknown): payload is undefined; diff --git a/dist/isUndefined.js b/dist/isUndefined.js index 0135cb7..d96efad 100644 --- a/dist/isUndefined.js +++ b/dist/isUndefined.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is undefined - * - * @param {any} payload - * @returns {payload is undefined} - */ +/** Returns whether the payload is undefined */ export function isUndefined(payload) { return getType(payload) === 'Undefined'; } diff --git a/dist/isWeakMap.d.ts b/dist/isWeakMap.d.ts index 7456afa..9c2a91c 100644 --- a/dist/isWeakMap.d.ts +++ b/dist/isWeakMap.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a WeakMap - * - * @param {any} payload - * @returns {payload is WeakMap} - */ -export declare function isWeakMap(payload: any): payload is WeakMap; +/** Returns whether the payload is a WeakMap */ +export declare function isWeakMap(payload: unknown): payload is WeakMap; diff --git a/dist/isWeakMap.js b/dist/isWeakMap.js index 4c9b053..90d9bf5 100644 --- a/dist/isWeakMap.js +++ b/dist/isWeakMap.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a WeakMap - * - * @param {any} payload - * @returns {payload is WeakMap} - */ +/** Returns whether the payload is a WeakMap */ export function isWeakMap(payload) { return getType(payload) === 'WeakMap'; } diff --git a/dist/isWeakSet.d.ts b/dist/isWeakSet.d.ts index f47ea56..211cf21 100644 --- a/dist/isWeakSet.d.ts +++ b/dist/isWeakSet.d.ts @@ -1,7 +1,2 @@ -/** - * Returns whether the payload is a WeakSet - * - * @param {any} payload - * @returns {payload is WeakSet} - */ -export declare function isWeakSet(payload: any): payload is WeakSet; +/** Returns whether the payload is a WeakSet */ +export declare function isWeakSet(payload: unknown): payload is WeakSet; diff --git a/dist/isWeakSet.js b/dist/isWeakSet.js index 09ff222..485baf5 100644 --- a/dist/isWeakSet.js +++ b/dist/isWeakSet.js @@ -1,10 +1,5 @@ import { getType } from './getType.js'; -/** - * Returns whether the payload is a WeakSet - * - * @param {any} payload - * @returns {payload is WeakSet} - */ +/** Returns whether the payload is a WeakSet */ export function isWeakSet(payload) { return getType(payload) === 'WeakSet'; } diff --git a/package.json b/package.json index 0d71e1b..68a0d4b 100644 --- a/package.json +++ b/package.json @@ -49,9 +49,6 @@ "author": "Luca Ban - Mesqueeb", "funding": "https://github.com/sponsors/mesqueeb", "license": "MIT", - "bugs": { - "url": "https://github.com/mesqueeb/is-what/issues" - }, "homepage": "https://github.com/mesqueeb/is-what#readme", "devDependencies": { "@cycraft/eslint": "^0.0.2", diff --git a/src/getType.ts b/src/getType.ts index f65df87..1ace9f4 100644 --- a/src/getType.ts +++ b/src/getType.ts @@ -1,9 +1,4 @@ -/** - * Returns the object type of the given payload - * - * @param {any} payload - * @returns {string} - */ -export function getType(payload: any): string { +/** Returns the object type of the given payload */ +export function getType(payload: unknown): string { return Object.prototype.toString.call(payload).slice(8, -1) } diff --git a/src/index.ts b/src/index.ts index 5192fc6..3f82ba8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export type AnyAsyncFunction = (...args: any[]) => Promise +export type AnyAsyncFunction = (...args: unknown[]) => Promise export { getType } from './getType.js' export { isAnyObject } from './isAnyObject.js' export { isArray } from './isArray.js' diff --git a/src/isAnyObject.ts b/src/isAnyObject.ts index 906cbf6..8403a5d 100644 --- a/src/isAnyObject.ts +++ b/src/isAnyObject.ts @@ -4,10 +4,7 @@ import { PlainObject } from './isPlainObject.js' /** * Returns whether the payload is an any kind of object (including special classes or objects with * different prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ -export function isAnyObject(payload: any): payload is PlainObject { +export function isAnyObject(payload: unknown): payload is PlainObject { return getType(payload) === 'Object' } diff --git a/src/isArray.ts b/src/isArray.ts index 7356bb2..0064f33 100644 --- a/src/isArray.ts +++ b/src/isArray.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is an array - * - * @param {any} payload - * @returns {payload is any[]} - */ -export function isArray(payload: any): payload is any[] { +/** Returns whether the payload is an array */ +export function isArray(payload: unknown): payload is unknown[] { return getType(payload) === 'Array' } diff --git a/src/isBlob.ts b/src/isBlob.ts index 6e663b0..21e4318 100644 --- a/src/isBlob.ts +++ b/src/isBlob.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a Blob - * - * @param {any} payload - * @returns {payload is Blob} - */ -export function isBlob(payload: any): payload is Blob { +/** Returns whether the payload is a Blob */ +export function isBlob(payload: unknown): payload is Blob { return getType(payload) === 'Blob' } diff --git a/src/isBoolean.ts b/src/isBoolean.ts index 1e2af40..73b069f 100644 --- a/src/isBoolean.ts +++ b/src/isBoolean.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a boolean - * - * @param {any} payload - * @returns {payload is boolean} - */ -export function isBoolean(payload: any): payload is boolean { +/** Returns whether the payload is a boolean */ +export function isBoolean(payload: unknown): payload is boolean { return getType(payload) === 'Boolean' } diff --git a/src/isDate.ts b/src/isDate.ts index e1d4e5e..43ec629 100644 --- a/src/isDate.ts +++ b/src/isDate.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a Date, and that the date is valid - * - * @param {any} payload - * @returns {payload is Date} - */ -export function isDate(payload: any): payload is Date { - return getType(payload) === 'Date' && !isNaN(payload) +/** Returns whether the payload is a Date, and that the date is valid */ +export function isDate(payload: unknown): payload is Date { + return getType(payload) === 'Date' && !isNaN(payload as unknown as number) } diff --git a/src/isEmptyArray.ts b/src/isEmptyArray.ts index 073a1ae..d39c7a9 100644 --- a/src/isEmptyArray.ts +++ b/src/isEmptyArray.ts @@ -1,11 +1,6 @@ import { isArray } from './isArray.js' -/** - * Returns whether the payload is a an empty array - * - * @param {any} payload - * @returns {payload is []} - */ -export function isEmptyArray(payload: any): payload is [] { +/** Returns whether the payload is a an empty array */ +export function isEmptyArray(payload: unknown): payload is [] { return isArray(payload) && payload.length === 0 } diff --git a/src/isEmptyObject.ts b/src/isEmptyObject.ts index 9ffcc5d..51950a1 100644 --- a/src/isEmptyObject.ts +++ b/src/isEmptyObject.ts @@ -3,10 +3,9 @@ import { isPlainObject } from './isPlainObject.js' /** * Returns whether the payload is a an empty object (excluding special classes or objects with other * prototypes) - * - * @param {any} payload - * @returns {payload is { [K in any]: never }} */ -export function isEmptyObject(payload: any): payload is { [K in any]: never } { +export function isEmptyObject( + payload: unknown, +): payload is { [K in string | symbol | number]: never } { return isPlainObject(payload) && Object.keys(payload).length === 0 } diff --git a/src/isEmptyString.ts b/src/isEmptyString.ts index ee892fc..f501e35 100644 --- a/src/isEmptyString.ts +++ b/src/isEmptyString.ts @@ -1,9 +1,4 @@ -/** - * Returns whether the payload is '' - * - * @param {any} payload - * @returns {payload is string} - */ -export function isEmptyString(payload: any): payload is string { +/** Returns whether the payload is '' */ +export function isEmptyString(payload: unknown): payload is string { return payload === '' } diff --git a/src/isError.ts b/src/isError.ts index a3f4ca0..ba2909f 100644 --- a/src/isError.ts +++ b/src/isError.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is an Error - * - * @param {any} payload - * @returns {payload is Error} - */ -export function isError(payload: any): payload is Error { +/** Returns whether the payload is an Error */ +export function isError(payload: unknown): payload is Error { return getType(payload) === 'Error' || payload instanceof Error } diff --git a/src/isFile.ts b/src/isFile.ts index 9ae77e4..8b3e495 100644 --- a/src/isFile.ts +++ b/src/isFile.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a File - * - * @param {any} payload - * @returns {payload is File} - */ -export function isFile(payload: any): payload is File { +/** Returns whether the payload is a File */ +export function isFile(payload: unknown): payload is File { return getType(payload) === 'File' } diff --git a/src/isFullArray.ts b/src/isFullArray.ts index 720f005..a2f2727 100644 --- a/src/isFullArray.ts +++ b/src/isFullArray.ts @@ -1,11 +1,6 @@ import { isArray } from './isArray.js' -/** - * Returns whether the payload is a an array with at least 1 item - * - * @param {any} payload - * @returns {payload is any[]} - */ -export function isFullArray(payload: any): payload is any[] { +/** Returns whether the payload is a an array with at least 1 item */ +export function isFullArray(payload: unknown): payload is unknown[] { return isArray(payload) && payload.length > 0 } diff --git a/src/isFullObject.ts b/src/isFullObject.ts index 6b68fef..30d2aef 100644 --- a/src/isFullObject.ts +++ b/src/isFullObject.ts @@ -3,10 +3,7 @@ import { PlainObject, isPlainObject } from './isPlainObject.js' /** * Returns whether the payload is a an empty object (excluding special classes or objects with other * prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ -export function isFullObject(payload: any): payload is PlainObject { +export function isFullObject(payload: unknown): payload is PlainObject { return isPlainObject(payload) && Object.keys(payload).length > 0 } diff --git a/src/isFullString.ts b/src/isFullString.ts index d1aac76..f5a6c6b 100644 --- a/src/isFullString.ts +++ b/src/isFullString.ts @@ -1,11 +1,6 @@ import { isString } from './isString.js' -/** - * Returns whether the payload is a string, BUT returns false for '' - * - * @param {any} payload - * @returns {payload is string} - */ -export function isFullString(payload: any): payload is string { +/** Returns whether the payload is a string, BUT returns false for '' */ +export function isFullString(payload: unknown): payload is string { return isString(payload) && payload !== '' } diff --git a/src/isFunction.ts b/src/isFunction.ts index 30796a2..bc76ab2 100644 --- a/src/isFunction.ts +++ b/src/isFunction.ts @@ -1,11 +1,6 @@ -export type AnyFunction = (...args: any[]) => any +export type AnyFunction = (...args: unknown[]) => unknown -/** - * Returns whether the payload is a function (regular or async) - * - * @param {any} payload - * @returns {payload is AnyFunction} - */ -export function isFunction(payload: any): payload is AnyFunction { +/** Returns whether the payload is a function (regular or async) */ +export function isFunction(payload: unknown): payload is AnyFunction { return typeof payload === 'function' } diff --git a/src/isMap.ts b/src/isMap.ts index 535b267..c10efde 100644 --- a/src/isMap.ts +++ b/src/isMap.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a Map - * - * @param {any} payload - * @returns {payload is Map} - */ -export function isMap(payload: any): payload is Map { +/** Returns whether the payload is a Map */ +export function isMap(payload: unknown): payload is Map { return getType(payload) === 'Map' } diff --git a/src/isNaNValue.ts b/src/isNaNValue.ts index ce165fc..446067c 100644 --- a/src/isNaNValue.ts +++ b/src/isNaNValue.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`) - * - * @param {any} payload - * @returns {payload is typeof NaN} - */ -export function isNaNValue(payload: any): payload is typeof NaN { - return getType(payload) === 'Number' && isNaN(payload) +/** Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`) */ +export function isNaNValue(payload: unknown): payload is typeof NaN { + return getType(payload) === 'Number' && isNaN(payload as unknown as number) } diff --git a/src/isNegativeNumber.ts b/src/isNegativeNumber.ts index 8cad5ca..dc934ca 100644 --- a/src/isNegativeNumber.ts +++ b/src/isNegativeNumber.ts @@ -1,11 +1,6 @@ import { isNumber } from './isNumber.js' -/** - * Returns whether the payload is a negative number (but not 0) - * - * @param {any} payload - * @returns {payload is number} - */ -export function isNegativeNumber(payload: any): payload is number { +/** Returns whether the payload is a negative number (but not 0) */ +export function isNegativeNumber(payload: unknown): payload is number { return isNumber(payload) && payload < 0 } diff --git a/src/isNull.ts b/src/isNull.ts index 7dec7bc..5a0e487 100644 --- a/src/isNull.ts +++ b/src/isNull.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is null - * - * @param {any} payload - * @returns {payload is null} - */ -export function isNull(payload: any): payload is null { +/** Returns whether the payload is null */ +export function isNull(payload: unknown): payload is null { return getType(payload) === 'Null' } diff --git a/src/isNullOrUndefined.ts b/src/isNullOrUndefined.ts index 282ed81..62513f9 100644 --- a/src/isNullOrUndefined.ts +++ b/src/isNullOrUndefined.ts @@ -2,10 +2,5 @@ import { isNull } from './isNull.js' import { /* tree-shaking no-side-effects-when-called */ isOneOf } from './isOneOf.js' import { isUndefined } from './isUndefined.js' -/** - * Returns true whether the payload is null or undefined - * - * @param {any} payload - * @returns {(payload is null | undefined)} - */ +/** Returns true whether the payload is null or undefined */ export const isNullOrUndefined = isOneOf(isNull, isUndefined) diff --git a/src/isNumber.ts b/src/isNumber.ts index 6dec624..59bbc37 100644 --- a/src/isNumber.ts +++ b/src/isNumber.ts @@ -4,10 +4,7 @@ import { getType } from './getType.js' * Returns whether the payload is a number (but not NaN) * * This will return `false` for `NaN`!! - * - * @param {any} payload - * @returns {payload is number} */ -export function isNumber(payload: any): payload is number { - return getType(payload) === 'Number' && !isNaN(payload) +export function isNumber(payload: unknown): payload is number { + return getType(payload) === 'Number' && !isNaN(payload as unknown as number) } diff --git a/src/isObject.ts b/src/isObject.ts index 9f2f9e1..2292a60 100644 --- a/src/isObject.ts +++ b/src/isObject.ts @@ -3,10 +3,7 @@ import { PlainObject, isPlainObject } from './isPlainObject.js' /** * Returns whether the payload is a plain JavaScript object (excluding special classes or objects * with other prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ -export function isObject(payload: any): payload is PlainObject { +export function isObject(payload: unknown): payload is PlainObject { return isPlainObject(payload) } diff --git a/src/isObjectLike.ts b/src/isObjectLike.ts index ce39555..7eacb35 100644 --- a/src/isObjectLike.ts +++ b/src/isObjectLike.ts @@ -7,9 +7,7 @@ import { PlainObject } from './isPlainObject.js' * 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 {any} payload - * @returns {payload is T} */ -export function isObjectLike(payload: any): payload is T { +export function isObjectLike(payload: unknown): payload is T { return isAnyObject(payload) } diff --git a/src/isOneOf.ts b/src/isOneOf.ts index 6475e01..f2ce23c 100644 --- a/src/isOneOf.ts +++ b/src/isOneOf.ts @@ -1,5 +1,3 @@ -import { AnyFunction } from './isFunction.js' - type TypeGuard = (payload: A) => payload is B /** @@ -16,7 +14,7 @@ type TypeGuard = (payload: A) => payload is B */ export function isOneOf( a: TypeGuard, - b: TypeGuard + b: TypeGuard, ): TypeGuard /** * A factory function that creates a function to check if the payload is one of the given types. @@ -33,7 +31,7 @@ export function isOneOf( export function isOneOf( a: TypeGuard, b: TypeGuard, - c: TypeGuard + c: TypeGuard, ): TypeGuard /** * A factory function that creates a function to check if the payload is one of the given types. @@ -51,7 +49,7 @@ export function isOneOf( a: TypeGuard, b: TypeGuard, c: TypeGuard, - d: TypeGuard + d: TypeGuard, ): TypeGuard /** * A factory function that creates a function to check if the payload is one of the given types. @@ -70,7 +68,7 @@ export function isOneOf, c: TypeGuard, d: TypeGuard, - e: TypeGuard + e: TypeGuard, ): TypeGuard /** * A factory function that creates a function to check if the payload is one of the given types. @@ -85,11 +83,11 @@ export function isOneOf boolean, + b: (...args: unknown[]) => boolean, + c?: (...args: unknown[]) => boolean, + d?: (...args: unknown[]) => boolean, + e?: (...args: unknown[]) => boolean, ): (value: unknown) => boolean { return (value) => a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value)) diff --git a/src/isPlainObject.ts b/src/isPlainObject.ts index 13f1ddd..c1ab956 100644 --- a/src/isPlainObject.ts +++ b/src/isPlainObject.ts @@ -1,15 +1,12 @@ import { getType } from './getType.js' -export type PlainObject = Record +export type PlainObject = Record /** * Returns whether the payload is a plain JavaScript object (excluding special classes or objects * with other prototypes) - * - * @param {any} payload - * @returns {payload is PlainObject} */ -export function isPlainObject(payload: any): payload is PlainObject { +export function isPlainObject(payload: unknown): payload is PlainObject { if (getType(payload) !== 'Object') return false const prototype = Object.getPrototypeOf(payload) return !!prototype && prototype.constructor === Object && prototype === Object.prototype diff --git a/src/isPositiveNumber.ts b/src/isPositiveNumber.ts index 2df1d01..3a9cf0b 100644 --- a/src/isPositiveNumber.ts +++ b/src/isPositiveNumber.ts @@ -1,11 +1,6 @@ import { isNumber } from './isNumber.js' -/** - * Returns whether the payload is a positive number (but not 0) - * - * @param {any} payload - * @returns {payload is number} - */ -export function isPositiveNumber(payload: any): payload is number { +/** Returns whether the payload is a positive number (but not 0) */ +export function isPositiveNumber(payload: unknown): payload is number { return isNumber(payload) && payload > 0 } diff --git a/src/isPrimitive.ts b/src/isPrimitive.ts index 5a3dca1..e76c5cf 100644 --- a/src/isPrimitive.ts +++ b/src/isPrimitive.ts @@ -7,13 +7,11 @@ import { isUndefined } from './isUndefined.js' /** * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String - * | Symbol) * - * @param {any} payload - * @returns {(payload is boolean | null | undefined | number | string | symbol)} + * | Symbol) */ export function isPrimitive( - payload: any + payload: unknown, ): payload is boolean | null | undefined | number | string | symbol { return ( isBoolean(payload) || diff --git a/src/isPromise.ts b/src/isPromise.ts index ef3139d..d7061cf 100644 --- a/src/isPromise.ts +++ b/src/isPromise.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a Promise - * - * @param {any} payload - * @returns {payload is Promise} - */ -export function isPromise(payload: any): payload is Promise { +/** Returns whether the payload is a Promise */ +export function isPromise(payload: unknown): payload is Promise { return getType(payload) === 'Promise' } diff --git a/src/isRegExp.ts b/src/isRegExp.ts index 198710f..dd24ee2 100644 --- a/src/isRegExp.ts +++ b/src/isRegExp.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a regular expression (RegExp) - * - * @param {any} payload - * @returns {payload is RegExp} - */ -export function isRegExp(payload: any): payload is RegExp { +/** Returns whether the payload is a regular expression (RegExp) */ +export function isRegExp(payload: unknown): payload is RegExp { return getType(payload) === 'RegExp' } diff --git a/src/isSet.ts b/src/isSet.ts index ea85c90..f15b21e 100644 --- a/src/isSet.ts +++ b/src/isSet.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a Set - * - * @param {any} payload - * @returns {payload is Set} - */ -export function isSet(payload: any): payload is Set { +/** Returns whether the payload is a Set */ +export function isSet(payload: unknown): payload is Set { return getType(payload) === 'Set' } diff --git a/src/isString.ts b/src/isString.ts index aec74c2..c077d4c 100644 --- a/src/isString.ts +++ b/src/isString.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a string - * - * @param {any} payload - * @returns {payload is string} - */ -export function isString(payload: any): payload is string { +/** Returns whether the payload is a string */ +export function isString(payload: unknown): payload is string { return getType(payload) === 'String' } diff --git a/src/isSymbol.ts b/src/isSymbol.ts index fa16675..8d8a168 100644 --- a/src/isSymbol.ts +++ b/src/isSymbol.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a Symbol - * - * @param {any} payload - * @returns {payload is symbol} - */ -export function isSymbol(payload: any): payload is symbol { +/** Returns whether the payload is a Symbol */ +export function isSymbol(payload: unknown): payload is symbol { return getType(payload) === 'Symbol' } diff --git a/src/isType.ts b/src/isType.ts index 8a95ff4..2a74ab3 100644 --- a/src/isType.ts +++ b/src/isType.ts @@ -1,20 +1,16 @@ import { getType } from './getType.js' import { AnyFunction } from './isFunction.js' -export type AnyClass = new (...args: any[]) => any +export type AnyClass = new (...args: unknown[]) => unknown /** * 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 {any} payload - * @param {T} type - * @returns {payload is T} * @throws {TypeError} Will throw type error if type is an invalid type */ -export function isType(payload: any, type: T): payload is T { +export function isType(payload: unknown, type: T): payload is T { if (!(type instanceof Function)) { throw new TypeError('Type must be a function') } @@ -22,6 +18,6 @@ export function isType(payload: any, type: T): throw new TypeError('Type is not a class') } // Classes usually have names (as functions usually have names) - const name: string | undefined | null = (type as any).name + const name: string | undefined | null = type.name return getType(payload) === name || Boolean(payload && payload.constructor === type) } diff --git a/src/isUndefined.ts b/src/isUndefined.ts index c0f474b..4b3fe88 100644 --- a/src/isUndefined.ts +++ b/src/isUndefined.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is undefined - * - * @param {any} payload - * @returns {payload is undefined} - */ -export function isUndefined(payload: any): payload is undefined { +/** Returns whether the payload is undefined */ +export function isUndefined(payload: unknown): payload is undefined { return getType(payload) === 'Undefined' } diff --git a/src/isWeakMap.ts b/src/isWeakMap.ts index 1eeba6d..85e8d41 100644 --- a/src/isWeakMap.ts +++ b/src/isWeakMap.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a WeakMap - * - * @param {any} payload - * @returns {payload is WeakMap} - */ -export function isWeakMap(payload: any): payload is WeakMap { +/** Returns whether the payload is a WeakMap */ +export function isWeakMap(payload: unknown): payload is WeakMap { return getType(payload) === 'WeakMap' } diff --git a/src/isWeakSet.ts b/src/isWeakSet.ts index d9e585c..c05c2b3 100644 --- a/src/isWeakSet.ts +++ b/src/isWeakSet.ts @@ -1,11 +1,6 @@ import { getType } from './getType.js' -/** - * Returns whether the payload is a WeakSet - * - * @param {any} payload - * @returns {payload is WeakSet} - */ -export function isWeakSet(payload: any): payload is WeakSet { +/** Returns whether the payload is a WeakSet */ +export function isWeakSet(payload: unknown): payload is WeakSet { return getType(payload) === 'WeakSet' } diff --git a/test/index.test.ts b/test/index.test.ts index 38b6d23..64184ae 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -372,7 +372,7 @@ test('type related tests', () => { // } // const a: Record = {} // a[myArray[1]] = myArray[0] - // const myArray: string | any[] = [1, 2, 'a', 'b'] + // const myArray: string | unknown[] = [1, 2, 'a', 'b'] // if (!isArray(myArray)) { // myArray // }