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 };
|