is-what 4.1.15 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/getType.d.ts +2 -0
- package/dist/getType.js +4 -0
- package/dist/index.d.ts +41 -334
- package/dist/index.js +37 -135
- package/dist/isAnyObject.d.ts +6 -0
- package/dist/isAnyObject.js +8 -0
- package/dist/isArray.d.ts +2 -0
- package/dist/isArray.js +5 -0
- package/dist/isBlob.d.ts +2 -0
- package/dist/isBlob.js +5 -0
- package/dist/isBoolean.d.ts +2 -0
- package/dist/isBoolean.js +5 -0
- package/dist/isDate.d.ts +2 -0
- package/dist/isDate.js +5 -0
- package/dist/isEmptyArray.d.ts +2 -0
- package/dist/isEmptyArray.js +5 -0
- package/dist/isEmptyObject.d.ts +7 -0
- package/dist/isEmptyObject.js +8 -0
- package/dist/isEmptyString.d.ts +2 -0
- package/dist/isEmptyString.js +4 -0
- package/dist/isError.d.ts +2 -0
- package/dist/isError.js +5 -0
- package/dist/isFile.d.ts +2 -0
- package/dist/isFile.js +5 -0
- package/dist/isFullArray.d.ts +2 -0
- package/dist/isFullArray.js +5 -0
- package/dist/isFullObject.d.ts +6 -0
- package/dist/isFullObject.js +8 -0
- package/dist/isFullString.d.ts +2 -0
- package/dist/isFullString.js +5 -0
- package/dist/isFunction.d.ts +3 -0
- package/dist/isFunction.js +4 -0
- package/dist/isInstanceOf.d.ts +23 -0
- package/dist/isInstanceOf.js +20 -0
- package/dist/isMap.d.ts +2 -0
- package/dist/isMap.js +5 -0
- package/dist/isNaNValue.d.ts +2 -0
- package/dist/isNaNValue.js +5 -0
- package/dist/isNegativeNumber.d.ts +2 -0
- package/dist/isNegativeNumber.js +5 -0
- package/dist/isNull.d.ts +2 -0
- package/dist/isNull.js +5 -0
- package/dist/isNullOrUndefined.d.ts +2 -0
- package/dist/isNullOrUndefined.js +5 -0
- package/dist/isNumber.d.ts +6 -0
- package/dist/isNumber.js +9 -0
- package/dist/isObject.d.ts +6 -0
- package/dist/isObject.js +8 -0
- package/dist/isObjectLike.d.ts +9 -0
- package/dist/isObjectLike.js +11 -0
- package/dist/isOneOf.d.ts +54 -0
- package/dist/isOneOf.js +15 -0
- package/dist/isPlainObject.d.ts +6 -0
- package/dist/isPlainObject.js +11 -0
- package/dist/isPositiveNumber.d.ts +2 -0
- package/dist/isPositiveNumber.js +5 -0
- package/dist/isPrimitive.d.ts +6 -0
- package/dist/isPrimitive.js +19 -0
- package/dist/isPromise.d.ts +2 -0
- package/dist/isPromise.js +5 -0
- package/dist/isRegExp.d.ts +2 -0
- package/dist/isRegExp.js +5 -0
- package/dist/isSet.d.ts +2 -0
- package/dist/isSet.js +5 -0
- package/dist/isString.d.ts +2 -0
- package/dist/isString.js +5 -0
- package/dist/isSymbol.d.ts +2 -0
- package/dist/isSymbol.js +5 -0
- package/dist/isType.d.ts +10 -0
- package/dist/isType.js +19 -0
- package/dist/isUndefined.d.ts +2 -0
- package/dist/isUndefined.js +5 -0
- package/dist/isWeakMap.d.ts +2 -0
- package/dist/isWeakMap.js +5 -0
- package/dist/isWeakSet.d.ts +2 -0
- package/dist/isWeakSet.js +5 -0
- package/package.json +13 -83
- package/dist/cjs/index.cjs +0 -173
- package/dist/cjs/index.d.cts +0 -334
package/package.json
CHANGED
@@ -1,36 +1,25 @@
|
|
1
1
|
{
|
2
2
|
"name": "is-what",
|
3
|
-
"version": "
|
3
|
+
"version": "5.0.0",
|
4
4
|
"description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.",
|
5
5
|
"type": "module",
|
6
6
|
"sideEffects": false,
|
7
|
-
"types": "./dist/index.d.ts",
|
8
|
-
"module": "./dist/index.js",
|
9
|
-
"main": "./dist/index.js",
|
10
7
|
"exports": {
|
11
|
-
".":
|
12
|
-
|
13
|
-
"types": "./dist/cjs/index.d.cts",
|
14
|
-
"default": "./dist/cjs/index.cjs"
|
15
|
-
},
|
16
|
-
"import": {
|
17
|
-
"types": "./dist/index.d.ts",
|
18
|
-
"default": "./dist/index.js"
|
19
|
-
}
|
20
|
-
}
|
8
|
+
".": "./dist/index.js",
|
9
|
+
"./*": "./dist/*"
|
21
10
|
},
|
22
11
|
"files": [
|
23
12
|
"dist"
|
24
13
|
],
|
25
14
|
"engines": {
|
26
|
-
"node": ">=
|
15
|
+
"node": ">=18"
|
27
16
|
},
|
28
17
|
"scripts": {
|
29
18
|
"test": "vitest run",
|
30
|
-
"lint": "tsc --noEmit && eslint ./src
|
31
|
-
"build": "
|
19
|
+
"lint": "tsc --noEmit && eslint ./src",
|
20
|
+
"build": "del-cli dist && tsc",
|
32
21
|
"build:docs": "typedoc",
|
33
|
-
"release": "npm run lint &&
|
22
|
+
"release": "npm run lint && npm run build && np"
|
34
23
|
},
|
35
24
|
"repository": {
|
36
25
|
"type": "git",
|
@@ -60,77 +49,18 @@
|
|
60
49
|
"author": "Luca Ban - Mesqueeb",
|
61
50
|
"funding": "https://github.com/sponsors/mesqueeb",
|
62
51
|
"license": "MIT",
|
63
|
-
"bugs": {
|
64
|
-
"url": "https://github.com/mesqueeb/is-what/issues"
|
65
|
-
},
|
66
52
|
"homepage": "https://github.com/mesqueeb/is-what#readme",
|
67
53
|
"devDependencies": {
|
68
|
-
"@
|
69
|
-
"@
|
70
|
-
"del-cli": "^5.
|
71
|
-
"
|
72
|
-
"
|
73
|
-
"
|
74
|
-
"np": "^8.0.2",
|
75
|
-
"prettier-plugin-jsdoc": "^0.4.2",
|
76
|
-
"prettier": "^2.8.8",
|
77
|
-
"rollup-plugin-dts": "^5.3.0",
|
78
|
-
"rollup-plugin-esbuild": "^5.0.0",
|
79
|
-
"rollup": "^3.22.0",
|
80
|
-
"typedoc": "^0.24.7",
|
81
|
-
"typescript": "^5.0.4",
|
82
|
-
"vitest": "^0.31.1"
|
83
|
-
},
|
84
|
-
"ava": {
|
85
|
-
"extensions": {
|
86
|
-
"ts": "module"
|
87
|
-
},
|
88
|
-
"nodeArguments": [
|
89
|
-
"--loader=ts-node/esm"
|
90
|
-
]
|
54
|
+
"@cycraft/eslint": "^0.0.2",
|
55
|
+
"@cycraft/tsconfig": "^0.1.2",
|
56
|
+
"del-cli": "^5.1.0",
|
57
|
+
"np": "^10.0.5",
|
58
|
+
"typedoc": "^0.25.13",
|
59
|
+
"vitest": "^1.6.0"
|
91
60
|
},
|
92
61
|
"np": {
|
93
62
|
"branch": "production",
|
94
63
|
"publish": false,
|
95
64
|
"yarn": false
|
96
|
-
},
|
97
|
-
"eslintConfig": {
|
98
|
-
"ignorePatterns": [
|
99
|
-
"node_modules",
|
100
|
-
"dist",
|
101
|
-
"scripts",
|
102
|
-
"test"
|
103
|
-
],
|
104
|
-
"root": true,
|
105
|
-
"parser": "@typescript-eslint/parser",
|
106
|
-
"plugins": [
|
107
|
-
"@typescript-eslint",
|
108
|
-
"tree-shaking"
|
109
|
-
],
|
110
|
-
"extends": [
|
111
|
-
"eslint:recommended",
|
112
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
113
|
-
"plugin:@typescript-eslint/recommended",
|
114
|
-
"prettier"
|
115
|
-
],
|
116
|
-
"rules": {
|
117
|
-
"@typescript-eslint/no-empty-function": "off",
|
118
|
-
"@typescript-eslint/no-explicit-any": "off",
|
119
|
-
"@typescript-eslint/ban-ts-ignore": "off",
|
120
|
-
"tree-shaking/no-side-effects-in-initialization": "error",
|
121
|
-
"@typescript-eslint/ban-ts-comment": "off"
|
122
|
-
}
|
123
|
-
},
|
124
|
-
"prettier": {
|
125
|
-
"printWidth": 100,
|
126
|
-
"tabWidth": 2,
|
127
|
-
"singleQuote": true,
|
128
|
-
"trailingComma": "es5",
|
129
|
-
"semi": false,
|
130
|
-
"bracketSpacing": true,
|
131
|
-
"quoteProps": "consistent",
|
132
|
-
"plugins": [
|
133
|
-
"prettier-plugin-jsdoc"
|
134
|
-
]
|
135
65
|
}
|
136
66
|
}
|
package/dist/cjs/index.cjs
DELETED
@@ -1,173 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
function getType(payload) {
|
4
|
-
return Object.prototype.toString.call(payload).slice(8, -1);
|
5
|
-
}
|
6
|
-
function isUndefined(payload) {
|
7
|
-
return getType(payload) === "Undefined";
|
8
|
-
}
|
9
|
-
function isNull(payload) {
|
10
|
-
return getType(payload) === "Null";
|
11
|
-
}
|
12
|
-
function isPlainObject(payload) {
|
13
|
-
if (getType(payload) !== "Object")
|
14
|
-
return false;
|
15
|
-
const prototype = Object.getPrototypeOf(payload);
|
16
|
-
return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
|
17
|
-
}
|
18
|
-
function isObject(payload) {
|
19
|
-
return isPlainObject(payload);
|
20
|
-
}
|
21
|
-
function isEmptyObject(payload) {
|
22
|
-
return isPlainObject(payload) && Object.keys(payload).length === 0;
|
23
|
-
}
|
24
|
-
function isFullObject(payload) {
|
25
|
-
return isPlainObject(payload) && Object.keys(payload).length > 0;
|
26
|
-
}
|
27
|
-
function isAnyObject(payload) {
|
28
|
-
return getType(payload) === "Object";
|
29
|
-
}
|
30
|
-
function isObjectLike(payload) {
|
31
|
-
return isAnyObject(payload);
|
32
|
-
}
|
33
|
-
function isFunction(payload) {
|
34
|
-
return typeof payload === "function";
|
35
|
-
}
|
36
|
-
function isArray(payload) {
|
37
|
-
return getType(payload) === "Array";
|
38
|
-
}
|
39
|
-
function isFullArray(payload) {
|
40
|
-
return isArray(payload) && payload.length > 0;
|
41
|
-
}
|
42
|
-
function isEmptyArray(payload) {
|
43
|
-
return isArray(payload) && payload.length === 0;
|
44
|
-
}
|
45
|
-
function isString(payload) {
|
46
|
-
return getType(payload) === "String";
|
47
|
-
}
|
48
|
-
function isFullString(payload) {
|
49
|
-
return isString(payload) && payload !== "";
|
50
|
-
}
|
51
|
-
function isEmptyString(payload) {
|
52
|
-
return payload === "";
|
53
|
-
}
|
54
|
-
function isNumber(payload) {
|
55
|
-
return getType(payload) === "Number" && !isNaN(payload);
|
56
|
-
}
|
57
|
-
function isPositiveNumber(payload) {
|
58
|
-
return isNumber(payload) && payload > 0;
|
59
|
-
}
|
60
|
-
function isNegativeNumber(payload) {
|
61
|
-
return isNumber(payload) && payload < 0;
|
62
|
-
}
|
63
|
-
function isBoolean(payload) {
|
64
|
-
return getType(payload) === "Boolean";
|
65
|
-
}
|
66
|
-
function isRegExp(payload) {
|
67
|
-
return getType(payload) === "RegExp";
|
68
|
-
}
|
69
|
-
function isMap(payload) {
|
70
|
-
return getType(payload) === "Map";
|
71
|
-
}
|
72
|
-
function isWeakMap(payload) {
|
73
|
-
return getType(payload) === "WeakMap";
|
74
|
-
}
|
75
|
-
function isSet(payload) {
|
76
|
-
return getType(payload) === "Set";
|
77
|
-
}
|
78
|
-
function isWeakSet(payload) {
|
79
|
-
return getType(payload) === "WeakSet";
|
80
|
-
}
|
81
|
-
function isSymbol(payload) {
|
82
|
-
return getType(payload) === "Symbol";
|
83
|
-
}
|
84
|
-
function isDate(payload) {
|
85
|
-
return getType(payload) === "Date" && !isNaN(payload);
|
86
|
-
}
|
87
|
-
function isBlob(payload) {
|
88
|
-
return getType(payload) === "Blob";
|
89
|
-
}
|
90
|
-
function isFile(payload) {
|
91
|
-
return getType(payload) === "File";
|
92
|
-
}
|
93
|
-
function isPromise(payload) {
|
94
|
-
return getType(payload) === "Promise";
|
95
|
-
}
|
96
|
-
function isError(payload) {
|
97
|
-
return getType(payload) === "Error";
|
98
|
-
}
|
99
|
-
function isNaNValue(payload) {
|
100
|
-
return getType(payload) === "Number" && isNaN(payload);
|
101
|
-
}
|
102
|
-
function isPrimitive(payload) {
|
103
|
-
return isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
|
104
|
-
}
|
105
|
-
const isNullOrUndefined = isOneOf(isNull, isUndefined);
|
106
|
-
function isOneOf(a, b, c, d, e) {
|
107
|
-
return (value) => a(value) || b(value) || !!c && c(value) || !!d && d(value) || !!e && e(value);
|
108
|
-
}
|
109
|
-
function isType(payload, type) {
|
110
|
-
if (!(type instanceof Function)) {
|
111
|
-
throw new TypeError("Type must be a function");
|
112
|
-
}
|
113
|
-
if (!Object.prototype.hasOwnProperty.call(type, "prototype")) {
|
114
|
-
throw new TypeError("Type is not a class");
|
115
|
-
}
|
116
|
-
const name = type.name;
|
117
|
-
return getType(payload) === name || Boolean(payload && payload.constructor === type);
|
118
|
-
}
|
119
|
-
function isInstanceOf(value, classOrClassName) {
|
120
|
-
if (typeof classOrClassName === "function") {
|
121
|
-
for (let p = value; p; p = Object.getPrototypeOf(p)) {
|
122
|
-
if (isType(p, classOrClassName)) {
|
123
|
-
return true;
|
124
|
-
}
|
125
|
-
}
|
126
|
-
return false;
|
127
|
-
} else {
|
128
|
-
for (let p = value; p; p = Object.getPrototypeOf(p)) {
|
129
|
-
if (getType(p) === classOrClassName) {
|
130
|
-
return true;
|
131
|
-
}
|
132
|
-
}
|
133
|
-
return false;
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
|
-
exports.getType = getType;
|
138
|
-
exports.isAnyObject = isAnyObject;
|
139
|
-
exports.isArray = isArray;
|
140
|
-
exports.isBlob = isBlob;
|
141
|
-
exports.isBoolean = isBoolean;
|
142
|
-
exports.isDate = isDate;
|
143
|
-
exports.isEmptyArray = isEmptyArray;
|
144
|
-
exports.isEmptyObject = isEmptyObject;
|
145
|
-
exports.isEmptyString = isEmptyString;
|
146
|
-
exports.isError = isError;
|
147
|
-
exports.isFile = isFile;
|
148
|
-
exports.isFullArray = isFullArray;
|
149
|
-
exports.isFullObject = isFullObject;
|
150
|
-
exports.isFullString = isFullString;
|
151
|
-
exports.isFunction = isFunction;
|
152
|
-
exports.isInstanceOf = isInstanceOf;
|
153
|
-
exports.isMap = isMap;
|
154
|
-
exports.isNaNValue = isNaNValue;
|
155
|
-
exports.isNegativeNumber = isNegativeNumber;
|
156
|
-
exports.isNull = isNull;
|
157
|
-
exports.isNullOrUndefined = isNullOrUndefined;
|
158
|
-
exports.isNumber = isNumber;
|
159
|
-
exports.isObject = isObject;
|
160
|
-
exports.isObjectLike = isObjectLike;
|
161
|
-
exports.isOneOf = isOneOf;
|
162
|
-
exports.isPlainObject = isPlainObject;
|
163
|
-
exports.isPositiveNumber = isPositiveNumber;
|
164
|
-
exports.isPrimitive = isPrimitive;
|
165
|
-
exports.isPromise = isPromise;
|
166
|
-
exports.isRegExp = isRegExp;
|
167
|
-
exports.isSet = isSet;
|
168
|
-
exports.isString = isString;
|
169
|
-
exports.isSymbol = isSymbol;
|
170
|
-
exports.isType = isType;
|
171
|
-
exports.isUndefined = isUndefined;
|
172
|
-
exports.isWeakMap = isWeakMap;
|
173
|
-
exports.isWeakSet = isWeakSet;
|
package/dist/cjs/index.d.cts
DELETED
@@ -1,334 +0,0 @@
|
|
1
|
-
type AnyFunction = (...args: any[]) => any;
|
2
|
-
type AnyAsyncFunction = (...args: any[]) => Promise<any>;
|
3
|
-
type AnyClass = new (...args: any[]) => any;
|
4
|
-
type PlainObject = Record<string | number | symbol, any>;
|
5
|
-
type TypeGuard<A, B extends A> = (payload: A) => payload is B;
|
6
|
-
/**
|
7
|
-
* Returns the object type of the given payload
|
8
|
-
*
|
9
|
-
* @param {*} payload
|
10
|
-
* @returns {string}
|
11
|
-
*/
|
12
|
-
declare function getType(payload: any): string;
|
13
|
-
/**
|
14
|
-
* Returns whether the payload is undefined
|
15
|
-
*
|
16
|
-
* @param {*} payload
|
17
|
-
* @returns {payload is undefined}
|
18
|
-
*/
|
19
|
-
declare function isUndefined(payload: any): payload is undefined;
|
20
|
-
/**
|
21
|
-
* Returns whether the payload is null
|
22
|
-
*
|
23
|
-
* @param {*} payload
|
24
|
-
* @returns {payload is null}
|
25
|
-
*/
|
26
|
-
declare function isNull(payload: any): payload is null;
|
27
|
-
/**
|
28
|
-
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
|
29
|
-
*
|
30
|
-
* @param {*} payload
|
31
|
-
* @returns {payload is PlainObject}
|
32
|
-
*/
|
33
|
-
declare function isPlainObject(payload: any): payload is PlainObject;
|
34
|
-
/**
|
35
|
-
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
|
36
|
-
*
|
37
|
-
* @param {*} payload
|
38
|
-
* @returns {payload is PlainObject}
|
39
|
-
*/
|
40
|
-
declare function isObject(payload: any): payload is PlainObject;
|
41
|
-
/**
|
42
|
-
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
43
|
-
*
|
44
|
-
* @param {*} payload
|
45
|
-
* @returns {payload is { [K in any]: never }}
|
46
|
-
*/
|
47
|
-
declare function isEmptyObject(payload: any): payload is {
|
48
|
-
[K in any]: never;
|
49
|
-
};
|
50
|
-
/**
|
51
|
-
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
52
|
-
*
|
53
|
-
* @param {*} payload
|
54
|
-
* @returns {payload is PlainObject}
|
55
|
-
*/
|
56
|
-
declare function isFullObject(payload: any): payload is PlainObject;
|
57
|
-
/**
|
58
|
-
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
|
59
|
-
*
|
60
|
-
* @param {*} payload
|
61
|
-
* @returns {payload is PlainObject}
|
62
|
-
*/
|
63
|
-
declare function isAnyObject(payload: any): payload is PlainObject;
|
64
|
-
/**
|
65
|
-
* Returns whether the payload is an object like a type passed in < >
|
66
|
-
*
|
67
|
-
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop.
|
68
|
-
*
|
69
|
-
* @template T this must be passed in < >
|
70
|
-
* @param {*} payload
|
71
|
-
* @returns {payload is T}
|
72
|
-
*/
|
73
|
-
declare function isObjectLike<T extends PlainObject>(payload: any): payload is T;
|
74
|
-
/**
|
75
|
-
* Returns whether the payload is a function (regular or async)
|
76
|
-
*
|
77
|
-
* @param {*} payload
|
78
|
-
* @returns {payload is AnyFunction}
|
79
|
-
*/
|
80
|
-
declare function isFunction(payload: any): payload is AnyFunction;
|
81
|
-
/**
|
82
|
-
* Returns whether the payload is an array
|
83
|
-
*
|
84
|
-
* @param {any} payload
|
85
|
-
* @returns {payload is any[]}
|
86
|
-
*/
|
87
|
-
declare function isArray(payload: any): payload is any[];
|
88
|
-
/**
|
89
|
-
* Returns whether the payload is a an array with at least 1 item
|
90
|
-
*
|
91
|
-
* @param {*} payload
|
92
|
-
* @returns {payload is any[]}
|
93
|
-
*/
|
94
|
-
declare function isFullArray(payload: any): payload is any[];
|
95
|
-
/**
|
96
|
-
* Returns whether the payload is a an empty array
|
97
|
-
*
|
98
|
-
* @param {*} payload
|
99
|
-
* @returns {payload is []}
|
100
|
-
*/
|
101
|
-
declare function isEmptyArray(payload: any): payload is [];
|
102
|
-
/**
|
103
|
-
* Returns whether the payload is a string
|
104
|
-
*
|
105
|
-
* @param {*} payload
|
106
|
-
* @returns {payload is string}
|
107
|
-
*/
|
108
|
-
declare function isString(payload: any): payload is string;
|
109
|
-
/**
|
110
|
-
* Returns whether the payload is a string, BUT returns false for ''
|
111
|
-
*
|
112
|
-
* @param {*} payload
|
113
|
-
* @returns {payload is string}
|
114
|
-
*/
|
115
|
-
declare function isFullString(payload: any): payload is string;
|
116
|
-
/**
|
117
|
-
* Returns whether the payload is ''
|
118
|
-
*
|
119
|
-
* @param {*} payload
|
120
|
-
* @returns {payload is string}
|
121
|
-
*/
|
122
|
-
declare function isEmptyString(payload: any): payload is string;
|
123
|
-
/**
|
124
|
-
* Returns whether the payload is a number (but not NaN)
|
125
|
-
*
|
126
|
-
* This will return `false` for `NaN`!!
|
127
|
-
*
|
128
|
-
* @param {*} payload
|
129
|
-
* @returns {payload is number}
|
130
|
-
*/
|
131
|
-
declare function isNumber(payload: any): payload is number;
|
132
|
-
/**
|
133
|
-
* Returns whether the payload is a positive number (but not 0)
|
134
|
-
*
|
135
|
-
* @param {*} payload
|
136
|
-
* @returns {payload is number}
|
137
|
-
*/
|
138
|
-
declare function isPositiveNumber(payload: any): payload is number;
|
139
|
-
/**
|
140
|
-
* Returns whether the payload is a negative number (but not 0)
|
141
|
-
*
|
142
|
-
* @param {*} payload
|
143
|
-
* @returns {payload is number}
|
144
|
-
*/
|
145
|
-
declare function isNegativeNumber(payload: any): payload is number;
|
146
|
-
/**
|
147
|
-
* Returns whether the payload is a boolean
|
148
|
-
*
|
149
|
-
* @param {*} payload
|
150
|
-
* @returns {payload is boolean}
|
151
|
-
*/
|
152
|
-
declare function isBoolean(payload: any): payload is boolean;
|
153
|
-
/**
|
154
|
-
* Returns whether the payload is a regular expression (RegExp)
|
155
|
-
*
|
156
|
-
* @param {*} payload
|
157
|
-
* @returns {payload is RegExp}
|
158
|
-
*/
|
159
|
-
declare function isRegExp(payload: any): payload is RegExp;
|
160
|
-
/**
|
161
|
-
* Returns whether the payload is a Map
|
162
|
-
*
|
163
|
-
* @param {*} payload
|
164
|
-
* @returns {payload is Map<any, any>}
|
165
|
-
*/
|
166
|
-
declare function isMap(payload: any): payload is Map<any, any>;
|
167
|
-
/**
|
168
|
-
* Returns whether the payload is a WeakMap
|
169
|
-
*
|
170
|
-
* @param {*} payload
|
171
|
-
* @returns {payload is WeakMap<any, any>}
|
172
|
-
*/
|
173
|
-
declare function isWeakMap(payload: any): payload is WeakMap<any, any>;
|
174
|
-
/**
|
175
|
-
* Returns whether the payload is a Set
|
176
|
-
*
|
177
|
-
* @param {*} payload
|
178
|
-
* @returns {payload is Set<any>}
|
179
|
-
*/
|
180
|
-
declare function isSet(payload: any): payload is Set<any>;
|
181
|
-
/**
|
182
|
-
* Returns whether the payload is a WeakSet
|
183
|
-
*
|
184
|
-
* @param {*} payload
|
185
|
-
* @returns {payload is WeakSet<any>}
|
186
|
-
*/
|
187
|
-
declare function isWeakSet(payload: any): payload is WeakSet<any>;
|
188
|
-
/**
|
189
|
-
* Returns whether the payload is a Symbol
|
190
|
-
*
|
191
|
-
* @param {*} payload
|
192
|
-
* @returns {payload is symbol}
|
193
|
-
*/
|
194
|
-
declare function isSymbol(payload: any): payload is symbol;
|
195
|
-
/**
|
196
|
-
* Returns whether the payload is a Date, and that the date is valid
|
197
|
-
*
|
198
|
-
* @param {*} payload
|
199
|
-
* @returns {payload is Date}
|
200
|
-
*/
|
201
|
-
declare function isDate(payload: any): payload is Date;
|
202
|
-
/**
|
203
|
-
* Returns whether the payload is a Blob
|
204
|
-
*
|
205
|
-
* @param {*} payload
|
206
|
-
* @returns {payload is Blob}
|
207
|
-
*/
|
208
|
-
declare function isBlob(payload: any): payload is Blob;
|
209
|
-
/**
|
210
|
-
* Returns whether the payload is a File
|
211
|
-
*
|
212
|
-
* @param {*} payload
|
213
|
-
* @returns {payload is File}
|
214
|
-
*/
|
215
|
-
declare function isFile(payload: any): payload is File;
|
216
|
-
/**
|
217
|
-
* Returns whether the payload is a Promise
|
218
|
-
*
|
219
|
-
* @param {*} payload
|
220
|
-
* @returns {payload is Promise<any>}
|
221
|
-
*/
|
222
|
-
declare function isPromise(payload: any): payload is Promise<any>;
|
223
|
-
/**
|
224
|
-
* Returns whether the payload is an Error
|
225
|
-
*
|
226
|
-
* @param {*} payload
|
227
|
-
* @returns {payload is Error}
|
228
|
-
*/
|
229
|
-
declare function isError(payload: any): payload is Error;
|
230
|
-
/**
|
231
|
-
* Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)
|
232
|
-
*
|
233
|
-
* @param {*} payload
|
234
|
-
* @returns {payload is typeof NaN}
|
235
|
-
*/
|
236
|
-
declare function isNaNValue(payload: any): payload is typeof NaN;
|
237
|
-
/**
|
238
|
-
* Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
|
239
|
-
*
|
240
|
-
* @param {*} payload
|
241
|
-
* @returns {(payload is boolean | null | undefined | number | string | symbol)}
|
242
|
-
*/
|
243
|
-
declare function isPrimitive(payload: any): payload is boolean | null | undefined | number | string | symbol;
|
244
|
-
/**
|
245
|
-
* Returns true whether the payload is null or undefined
|
246
|
-
*
|
247
|
-
* @param {*} payload
|
248
|
-
* @returns {(payload is null | undefined)}
|
249
|
-
*/
|
250
|
-
declare const isNullOrUndefined: TypeGuard<any, null | undefined>;
|
251
|
-
/**
|
252
|
-
* A factory function that creates a function to check if the payload is one of the given types.
|
253
|
-
* @example
|
254
|
-
* import { isOneOf, isNull, isUndefined } from 'is-what'
|
255
|
-
*
|
256
|
-
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
|
257
|
-
*
|
258
|
-
* isNullOrUndefined(null) // true
|
259
|
-
* isNullOrUndefined(undefined) // true
|
260
|
-
* isNullOrUndefined(123) // false
|
261
|
-
*/
|
262
|
-
declare function isOneOf<A, B extends A, C extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>): TypeGuard<A, B | C>;
|
263
|
-
/**
|
264
|
-
* A factory function that creates a function to check if the payload is one of the given types.
|
265
|
-
* @example
|
266
|
-
* import { isOneOf, isNull, isUndefined } from 'is-what'
|
267
|
-
*
|
268
|
-
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
|
269
|
-
*
|
270
|
-
* isNullOrUndefined(null) // true
|
271
|
-
* isNullOrUndefined(undefined) // true
|
272
|
-
* isNullOrUndefined(123) // false
|
273
|
-
*/
|
274
|
-
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>;
|
275
|
-
/**
|
276
|
-
* A factory function that creates a function to check if the payload is one of the given types.
|
277
|
-
* @example
|
278
|
-
* import { isOneOf, isNull, isUndefined } from 'is-what'
|
279
|
-
*
|
280
|
-
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
|
281
|
-
*
|
282
|
-
* isNullOrUndefined(null) // true
|
283
|
-
* isNullOrUndefined(undefined) // true
|
284
|
-
* isNullOrUndefined(123) // false
|
285
|
-
*/
|
286
|
-
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>;
|
287
|
-
/**
|
288
|
-
* A factory function that creates a function to check if the payload is one of the given types.
|
289
|
-
* @example
|
290
|
-
* import { isOneOf, isNull, isUndefined } from 'is-what'
|
291
|
-
*
|
292
|
-
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
|
293
|
-
*
|
294
|
-
* isNullOrUndefined(null) // true
|
295
|
-
* isNullOrUndefined(undefined) // true
|
296
|
-
* isNullOrUndefined(123) // false
|
297
|
-
*/
|
298
|
-
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>;
|
299
|
-
/**
|
300
|
-
* Does a generic check to check that the given payload is of a given type.
|
301
|
-
* In cases like Number, it will return true for NaN as NaN is a Number (thanks javascript!);
|
302
|
-
* It will, however, differentiate between object and null
|
303
|
-
*
|
304
|
-
* @template T
|
305
|
-
* @param {*} payload
|
306
|
-
* @param {T} type
|
307
|
-
* @throws {TypeError} Will throw type error if type is an invalid type
|
308
|
-
* @returns {payload is T}
|
309
|
-
*/
|
310
|
-
declare function isType<T extends AnyFunction | AnyClass>(payload: any, type: T): payload is T;
|
311
|
-
type GlobalClassName = {
|
312
|
-
[K in keyof typeof globalThis]: (typeof globalThis)[K] extends AnyClass ? K : never;
|
313
|
-
}[keyof typeof globalThis];
|
314
|
-
/**
|
315
|
-
* Checks if a value is an instance of a class or a class name. Useful when you
|
316
|
-
* want to check if a value is an instance of a class that may not be defined in
|
317
|
-
* the current scope. For example, if you want to check if a value is an
|
318
|
-
* `OffscreenCanvas` instance, you might not want to do the song and dance of
|
319
|
-
* using `typeof OffscreenCanvas !== 'undefined'` and then shimming
|
320
|
-
* `OffscreenCanvas` if the types aren't around.
|
321
|
-
*
|
322
|
-
* @example
|
323
|
-
* if (isInstanceOf(value, 'OffscreenCanvas')) {
|
324
|
-
* // value is an OffscreenCanvas
|
325
|
-
* }
|
326
|
-
*
|
327
|
-
* @param value The value to recursively check
|
328
|
-
* @param class_ A string or class that the value should be an instance of
|
329
|
-
*/
|
330
|
-
declare function isInstanceOf<T extends AnyClass>(value: unknown, class_: T): value is T;
|
331
|
-
declare function isInstanceOf<K extends GlobalClassName>(value: unknown, className: K): value is (typeof globalThis)[K];
|
332
|
-
declare function isInstanceOf(value: unknown, className: string): value is object;
|
333
|
-
|
334
|
-
export { AnyAsyncFunction, AnyClass, AnyFunction, PlainObject, getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyArray, isEmptyObject, isEmptyString, isError, isFile, isFullArray, isFullObject, isFullString, isFunction, isInstanceOf, isMap, isNaNValue, isNegativeNumber, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isOneOf, isPlainObject, isPositiveNumber, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };
|