is-what 4.1.9 → 4.1.10-0
Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts
ADDED
@@ -0,0 +1,267 @@
|
|
1
|
+
export type AnyFunction = (...args: any[]) => any;
|
2
|
+
export type AnyAsyncFunction = (...args: any[]) => Promise<any>;
|
3
|
+
export type AnyClass = new (...args: any[]) => any;
|
4
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export declare const isNullOrUndefined: TypeGuard<any, null | undefined>;
|
251
|
+
export declare function isOneOf<A, B extends A, C extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>): TypeGuard<A, B | C>;
|
252
|
+
export declare function isOneOf<A, B extends A, C extends A, D extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>): TypeGuard<A, B | C | D>;
|
253
|
+
export declare function isOneOf<A, B extends A, C extends A, D extends A, E extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>, d: TypeGuard<A, E>): TypeGuard<A, B | C | D | E>;
|
254
|
+
export declare function isOneOf<A, B extends A, C extends A, D extends A, E extends A, F extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>, d: TypeGuard<A, E>, e: TypeGuard<A, F>): TypeGuard<A, B | C | D | E | F>;
|
255
|
+
/**
|
256
|
+
* Does a generic check to check that the given payload is of a given type.
|
257
|
+
* In cases like Number, it will return true for NaN as NaN is a Number (thanks javascript!);
|
258
|
+
* It will, however, differentiate between object and null
|
259
|
+
*
|
260
|
+
* @template T
|
261
|
+
* @param {*} payload
|
262
|
+
* @param {T} type
|
263
|
+
* @throws {TypeError} Will throw type error if type is an invalid type
|
264
|
+
* @returns {payload is T}
|
265
|
+
*/
|
266
|
+
export declare function isType<T extends AnyFunction | AnyClass>(payload: any, type: T): payload is T;
|
267
|
+
export {};
|
package/package.json
CHANGED
@@ -2,16 +2,15 @@
|
|
2
2
|
"name": "is-what",
|
3
3
|
"sideEffects": false,
|
4
4
|
"type": "module",
|
5
|
-
"version": "4.1.
|
5
|
+
"version": "4.1.10-0",
|
6
6
|
"description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.",
|
7
|
-
"module": "./dist/index.
|
8
|
-
"main": "./dist/index.
|
9
|
-
"types": "./dist/
|
7
|
+
"module": "./dist/index.js",
|
8
|
+
"main": "./dist/cjs/index.js",
|
9
|
+
"types": "./dist/index.d.ts",
|
10
10
|
"exports": {
|
11
11
|
".": {
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"require": "./dist/index.cjs"
|
12
|
+
"import": "./dist/index.js",
|
13
|
+
"require": "./dist/cjs/index.js"
|
15
14
|
}
|
16
15
|
},
|
17
16
|
"files": [
|
File without changes
|
File without changes
|
File without changes
|