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