is-what 4.1.10 → 4.1.12

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.
@@ -1,7 +1,7 @@
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>;
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
5
  type TypeGuard<A, B extends A> = (payload: A) => payload is B;
6
6
  /**
7
7
  * Returns the object type of the given payload
@@ -9,42 +9,42 @@ type TypeGuard<A, B extends A> = (payload: A) => payload is B;
9
9
  * @param {*} payload
10
10
  * @returns {string}
11
11
  */
12
- export declare function getType(payload: any): string;
12
+ declare function getType(payload: any): string;
13
13
  /**
14
14
  * Returns whether the payload is undefined
15
15
  *
16
16
  * @param {*} payload
17
17
  * @returns {payload is undefined}
18
18
  */
19
- export declare function isUndefined(payload: any): payload is undefined;
19
+ declare function isUndefined(payload: any): payload is undefined;
20
20
  /**
21
21
  * Returns whether the payload is null
22
22
  *
23
23
  * @param {*} payload
24
24
  * @returns {payload is null}
25
25
  */
26
- export declare function isNull(payload: any): payload is null;
26
+ declare function isNull(payload: any): payload is null;
27
27
  /**
28
28
  * Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
29
29
  *
30
30
  * @param {*} payload
31
31
  * @returns {payload is PlainObject}
32
32
  */
33
- export declare function isPlainObject(payload: any): payload is PlainObject;
33
+ declare function isPlainObject(payload: any): payload is PlainObject;
34
34
  /**
35
35
  * Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
36
36
  *
37
37
  * @param {*} payload
38
38
  * @returns {payload is PlainObject}
39
39
  */
40
- export declare function isObject(payload: any): payload is PlainObject;
40
+ declare function isObject(payload: any): payload is PlainObject;
41
41
  /**
42
42
  * Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
43
43
  *
44
44
  * @param {*} payload
45
45
  * @returns {payload is { [K in any]: never }}
46
46
  */
47
- export declare function isEmptyObject(payload: any): payload is {
47
+ declare function isEmptyObject(payload: any): payload is {
48
48
  [K in any]: never;
49
49
  };
50
50
  /**
@@ -53,14 +53,14 @@ export declare function isEmptyObject(payload: any): payload is {
53
53
  * @param {*} payload
54
54
  * @returns {payload is PlainObject}
55
55
  */
56
- export declare function isFullObject(payload: any): payload is PlainObject;
56
+ declare function isFullObject(payload: any): payload is PlainObject;
57
57
  /**
58
58
  * Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
59
59
  *
60
60
  * @param {*} payload
61
61
  * @returns {payload is PlainObject}
62
62
  */
63
- export declare function isAnyObject(payload: any): payload is PlainObject;
63
+ declare function isAnyObject(payload: any): payload is PlainObject;
64
64
  /**
65
65
  * Returns whether the payload is an object like a type passed in < >
66
66
  *
@@ -70,56 +70,56 @@ export declare function isAnyObject(payload: any): payload is PlainObject;
70
70
  * @param {*} payload
71
71
  * @returns {payload is T}
72
72
  */
73
- export declare function isObjectLike<T extends PlainObject>(payload: any): payload is T;
73
+ declare function isObjectLike<T extends PlainObject>(payload: any): payload is T;
74
74
  /**
75
75
  * Returns whether the payload is a function (regular or async)
76
76
  *
77
77
  * @param {*} payload
78
78
  * @returns {payload is AnyFunction}
79
79
  */
80
- export declare function isFunction(payload: any): payload is AnyFunction;
80
+ declare function isFunction(payload: any): payload is AnyFunction;
81
81
  /**
82
82
  * Returns whether the payload is an array
83
83
  *
84
84
  * @param {any} payload
85
85
  * @returns {payload is any[]}
86
86
  */
87
- export declare function isArray(payload: any): payload is any[];
87
+ declare function isArray(payload: any): payload is any[];
88
88
  /**
89
89
  * Returns whether the payload is a an array with at least 1 item
90
90
  *
91
91
  * @param {*} payload
92
92
  * @returns {payload is any[]}
93
93
  */
94
- export declare function isFullArray(payload: any): payload is any[];
94
+ declare function isFullArray(payload: any): payload is any[];
95
95
  /**
96
96
  * Returns whether the payload is a an empty array
97
97
  *
98
98
  * @param {*} payload
99
99
  * @returns {payload is []}
100
100
  */
101
- export declare function isEmptyArray(payload: any): payload is [];
101
+ declare function isEmptyArray(payload: any): payload is [];
102
102
  /**
103
103
  * Returns whether the payload is a string
104
104
  *
105
105
  * @param {*} payload
106
106
  * @returns {payload is string}
107
107
  */
108
- export declare function isString(payload: any): payload is string;
108
+ declare function isString(payload: any): payload is string;
109
109
  /**
110
110
  * Returns whether the payload is a string, BUT returns false for ''
111
111
  *
112
112
  * @param {*} payload
113
113
  * @returns {payload is string}
114
114
  */
115
- export declare function isFullString(payload: any): payload is string;
115
+ declare function isFullString(payload: any): payload is string;
116
116
  /**
117
117
  * Returns whether the payload is ''
118
118
  *
119
119
  * @param {*} payload
120
120
  * @returns {payload is string}
121
121
  */
122
- export declare function isEmptyString(payload: any): payload is string;
122
+ declare function isEmptyString(payload: any): payload is string;
123
123
  /**
124
124
  * Returns whether the payload is a number (but not NaN)
125
125
  *
@@ -128,130 +128,174 @@ export declare function isEmptyString(payload: any): payload is string;
128
128
  * @param {*} payload
129
129
  * @returns {payload is number}
130
130
  */
131
- export declare function isNumber(payload: any): payload is number;
131
+ declare function isNumber(payload: any): payload is number;
132
132
  /**
133
133
  * Returns whether the payload is a positive number (but not 0)
134
134
  *
135
135
  * @param {*} payload
136
136
  * @returns {payload is number}
137
137
  */
138
- export declare function isPositiveNumber(payload: any): payload is number;
138
+ declare function isPositiveNumber(payload: any): payload is number;
139
139
  /**
140
140
  * Returns whether the payload is a negative number (but not 0)
141
141
  *
142
142
  * @param {*} payload
143
143
  * @returns {payload is number}
144
144
  */
145
- export declare function isNegativeNumber(payload: any): payload is number;
145
+ declare function isNegativeNumber(payload: any): payload is number;
146
146
  /**
147
147
  * Returns whether the payload is a boolean
148
148
  *
149
149
  * @param {*} payload
150
150
  * @returns {payload is boolean}
151
151
  */
152
- export declare function isBoolean(payload: any): payload is boolean;
152
+ declare function isBoolean(payload: any): payload is boolean;
153
153
  /**
154
154
  * Returns whether the payload is a regular expression (RegExp)
155
155
  *
156
156
  * @param {*} payload
157
157
  * @returns {payload is RegExp}
158
158
  */
159
- export declare function isRegExp(payload: any): payload is RegExp;
159
+ declare function isRegExp(payload: any): payload is RegExp;
160
160
  /**
161
161
  * Returns whether the payload is a Map
162
162
  *
163
163
  * @param {*} payload
164
164
  * @returns {payload is Map<any, any>}
165
165
  */
166
- export declare function isMap(payload: any): payload is Map<any, any>;
166
+ declare function isMap(payload: any): payload is Map<any, any>;
167
167
  /**
168
168
  * Returns whether the payload is a WeakMap
169
169
  *
170
170
  * @param {*} payload
171
171
  * @returns {payload is WeakMap<any, any>}
172
172
  */
173
- export declare function isWeakMap(payload: any): payload is WeakMap<any, any>;
173
+ declare function isWeakMap(payload: any): payload is WeakMap<any, any>;
174
174
  /**
175
175
  * Returns whether the payload is a Set
176
176
  *
177
177
  * @param {*} payload
178
178
  * @returns {payload is Set<any>}
179
179
  */
180
- export declare function isSet(payload: any): payload is Set<any>;
180
+ declare function isSet(payload: any): payload is Set<any>;
181
181
  /**
182
182
  * Returns whether the payload is a WeakSet
183
183
  *
184
184
  * @param {*} payload
185
185
  * @returns {payload is WeakSet<any>}
186
186
  */
187
- export declare function isWeakSet(payload: any): payload is WeakSet<any>;
187
+ declare function isWeakSet(payload: any): payload is WeakSet<any>;
188
188
  /**
189
189
  * Returns whether the payload is a Symbol
190
190
  *
191
191
  * @param {*} payload
192
192
  * @returns {payload is symbol}
193
193
  */
194
- export declare function isSymbol(payload: any): payload is symbol;
194
+ declare function isSymbol(payload: any): payload is symbol;
195
195
  /**
196
196
  * Returns whether the payload is a Date, and that the date is valid
197
197
  *
198
198
  * @param {*} payload
199
199
  * @returns {payload is Date}
200
200
  */
201
- export declare function isDate(payload: any): payload is Date;
201
+ declare function isDate(payload: any): payload is Date;
202
202
  /**
203
203
  * Returns whether the payload is a Blob
204
204
  *
205
205
  * @param {*} payload
206
206
  * @returns {payload is Blob}
207
207
  */
208
- export declare function isBlob(payload: any): payload is Blob;
208
+ declare function isBlob(payload: any): payload is Blob;
209
209
  /**
210
210
  * Returns whether the payload is a File
211
211
  *
212
212
  * @param {*} payload
213
213
  * @returns {payload is File}
214
214
  */
215
- export declare function isFile(payload: any): payload is File;
215
+ declare function isFile(payload: any): payload is File;
216
216
  /**
217
217
  * Returns whether the payload is a Promise
218
218
  *
219
219
  * @param {*} payload
220
220
  * @returns {payload is Promise<any>}
221
221
  */
222
- export declare function isPromise(payload: any): payload is Promise<any>;
222
+ declare function isPromise(payload: any): payload is Promise<any>;
223
223
  /**
224
224
  * Returns whether the payload is an Error
225
225
  *
226
226
  * @param {*} payload
227
227
  * @returns {payload is Error}
228
228
  */
229
- export declare function isError(payload: any): payload is Error;
229
+ declare function isError(payload: any): payload is Error;
230
230
  /**
231
231
  * Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)
232
232
  *
233
233
  * @param {*} payload
234
234
  * @returns {payload is typeof NaN}
235
235
  */
236
- export declare function isNaNValue(payload: any): payload is typeof NaN;
236
+ declare function isNaNValue(payload: any): payload is typeof NaN;
237
237
  /**
238
238
  * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
239
239
  *
240
240
  * @param {*} payload
241
241
  * @returns {(payload is boolean | null | undefined | number | string | symbol)}
242
242
  */
243
- export declare function isPrimitive(payload: any): payload is boolean | null | undefined | number | string | symbol;
243
+ declare function isPrimitive(payload: any): payload is boolean | null | undefined | number | string | symbol;
244
244
  /**
245
245
  * Returns true whether the payload is null or undefined
246
246
  *
247
247
  * @param {*} payload
248
248
  * @returns {(payload is null | undefined)}
249
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>;
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>;
255
299
  /**
256
300
  * Does a generic check to check that the given payload is of a given type.
257
301
  * In cases like Number, it will return true for NaN as NaN is a Number (thanks javascript!);
@@ -263,5 +307,28 @@ export declare function isOneOf<A, B extends A, C extends A, D extends A, E exte
263
307
  * @throws {TypeError} Will throw type error if type is an invalid type
264
308
  * @returns {payload is T}
265
309
  */
266
- export declare function isType<T extends AnyFunction | AnyClass>(payload: any, type: T): payload is T;
267
- export {};
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 };