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.
Files changed (80) hide show
  1. package/README.md +6 -6
  2. package/dist/getType.d.ts +2 -0
  3. package/dist/getType.js +4 -0
  4. package/dist/index.d.ts +41 -334
  5. package/dist/index.js +37 -135
  6. package/dist/isAnyObject.d.ts +6 -0
  7. package/dist/isAnyObject.js +8 -0
  8. package/dist/isArray.d.ts +2 -0
  9. package/dist/isArray.js +5 -0
  10. package/dist/isBlob.d.ts +2 -0
  11. package/dist/isBlob.js +5 -0
  12. package/dist/isBoolean.d.ts +2 -0
  13. package/dist/isBoolean.js +5 -0
  14. package/dist/isDate.d.ts +2 -0
  15. package/dist/isDate.js +5 -0
  16. package/dist/isEmptyArray.d.ts +2 -0
  17. package/dist/isEmptyArray.js +5 -0
  18. package/dist/isEmptyObject.d.ts +7 -0
  19. package/dist/isEmptyObject.js +8 -0
  20. package/dist/isEmptyString.d.ts +2 -0
  21. package/dist/isEmptyString.js +4 -0
  22. package/dist/isError.d.ts +2 -0
  23. package/dist/isError.js +5 -0
  24. package/dist/isFile.d.ts +2 -0
  25. package/dist/isFile.js +5 -0
  26. package/dist/isFullArray.d.ts +2 -0
  27. package/dist/isFullArray.js +5 -0
  28. package/dist/isFullObject.d.ts +6 -0
  29. package/dist/isFullObject.js +8 -0
  30. package/dist/isFullString.d.ts +2 -0
  31. package/dist/isFullString.js +5 -0
  32. package/dist/isFunction.d.ts +3 -0
  33. package/dist/isFunction.js +4 -0
  34. package/dist/isInstanceOf.d.ts +23 -0
  35. package/dist/isInstanceOf.js +20 -0
  36. package/dist/isMap.d.ts +2 -0
  37. package/dist/isMap.js +5 -0
  38. package/dist/isNaNValue.d.ts +2 -0
  39. package/dist/isNaNValue.js +5 -0
  40. package/dist/isNegativeNumber.d.ts +2 -0
  41. package/dist/isNegativeNumber.js +5 -0
  42. package/dist/isNull.d.ts +2 -0
  43. package/dist/isNull.js +5 -0
  44. package/dist/isNullOrUndefined.d.ts +2 -0
  45. package/dist/isNullOrUndefined.js +5 -0
  46. package/dist/isNumber.d.ts +6 -0
  47. package/dist/isNumber.js +9 -0
  48. package/dist/isObject.d.ts +6 -0
  49. package/dist/isObject.js +8 -0
  50. package/dist/isObjectLike.d.ts +9 -0
  51. package/dist/isObjectLike.js +11 -0
  52. package/dist/isOneOf.d.ts +54 -0
  53. package/dist/isOneOf.js +15 -0
  54. package/dist/isPlainObject.d.ts +6 -0
  55. package/dist/isPlainObject.js +11 -0
  56. package/dist/isPositiveNumber.d.ts +2 -0
  57. package/dist/isPositiveNumber.js +5 -0
  58. package/dist/isPrimitive.d.ts +6 -0
  59. package/dist/isPrimitive.js +19 -0
  60. package/dist/isPromise.d.ts +2 -0
  61. package/dist/isPromise.js +5 -0
  62. package/dist/isRegExp.d.ts +2 -0
  63. package/dist/isRegExp.js +5 -0
  64. package/dist/isSet.d.ts +2 -0
  65. package/dist/isSet.js +5 -0
  66. package/dist/isString.d.ts +2 -0
  67. package/dist/isString.js +5 -0
  68. package/dist/isSymbol.d.ts +2 -0
  69. package/dist/isSymbol.js +5 -0
  70. package/dist/isType.d.ts +10 -0
  71. package/dist/isType.js +19 -0
  72. package/dist/isUndefined.d.ts +2 -0
  73. package/dist/isUndefined.js +5 -0
  74. package/dist/isWeakMap.d.ts +2 -0
  75. package/dist/isWeakMap.js +5 -0
  76. package/dist/isWeakSet.d.ts +2 -0
  77. package/dist/isWeakSet.js +5 -0
  78. package/package.json +13 -83
  79. package/dist/cjs/index.cjs +0 -173
  80. package/dist/cjs/index.d.cts +0 -334
package/README.md CHANGED
@@ -197,7 +197,7 @@ isInstanceOf(globalThis, ReadableStream)
197
197
  is-what makes TypeScript know the type during if statements. This means that a check returns the type of the payload for TypeScript users.
198
198
 
199
199
  ```ts
200
- function isNumber(payload: any): payload is number {
200
+ function isNumber(payload: unknown): payload is number {
201
201
  // return boolean
202
202
  }
203
203
  // As you can see above, all functions return a boolean for JavaScript, but pass the payload type to TypeScript.
@@ -215,9 +215,9 @@ function fn(payload: string | number): number {
215
215
  `isPlainObject` and `isAnyObject` with TypeScript will declare the payload to be an object type with any props:
216
216
 
217
217
  ```ts
218
- function isPlainObject(payload: any): payload is { [key: string]: any }
219
- function isAnyObject(payload: any): payload is { [key: string]: any }
220
- // The reason to return `{[key: string]: any}` is to be able to do
218
+ function isPlainObject(payload: unknown): payload is { [key: string]: unknown }
219
+ function isAnyObject(payload: unknown): payload is { [key: string]: unknown }
220
+ // The reason to return `{[key: string]: unknown}` is to be able to do
221
221
  if (isPlainObject(payload) && payload.id) return payload.id
222
222
  // if isPlainObject() would return `payload is object` then it would give an error at `payload.id`
223
223
  ```
@@ -235,7 +235,7 @@ const payload = { name: 'Mesqueeb' } // current type: `{ name: string }`
235
235
 
236
236
  // Without casting:
237
237
  if (isAnyObject(payload)) {
238
- // in here `payload` is casted to: `Record<string | number | symbol, any>`
238
+ // in here `payload` is casted to: `Record<string | number | symbol, unknown>`
239
239
  // WE LOOSE THE TYPE!
240
240
  }
241
241
 
@@ -251,7 +251,7 @@ Please note: this library will not actually check the shape of the object, you n
251
251
  `isObjectLike<T>` works like this under the hood:
252
252
 
253
253
  ```ts
254
- function isObjectLike<T extends object>(payload: any): payload is T {
254
+ function isObjectLike<T extends object>(payload: unknown): payload is T {
255
255
  return isAnyObject(payload)
256
256
  }
257
257
  ```
@@ -0,0 +1,2 @@
1
+ /** Returns the object type of the given payload */
2
+ export declare function getType(payload: unknown): string;
@@ -0,0 +1,4 @@
1
+ /** Returns the object type of the given payload */
2
+ export function getType(payload) {
3
+ return Object.prototype.toString.call(payload).slice(8, -1);
4
+ }
package/dist/index.d.ts CHANGED
@@ -1,334 +1,41 @@
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 };
1
+ export type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
2
+ export { getType } from './getType.js';
3
+ export { isAnyObject } from './isAnyObject.js';
4
+ export { isArray } from './isArray.js';
5
+ export { isBlob } from './isBlob.js';
6
+ export { isBoolean } from './isBoolean.js';
7
+ export { isDate } from './isDate.js';
8
+ export { isEmptyArray } from './isEmptyArray.js';
9
+ export { isEmptyObject } from './isEmptyObject.js';
10
+ export { isEmptyString } from './isEmptyString.js';
11
+ export { isError } from './isError.js';
12
+ export { isFile } from './isFile.js';
13
+ export { isFullArray } from './isFullArray.js';
14
+ export { isFullObject } from './isFullObject.js';
15
+ export { isFullString } from './isFullString.js';
16
+ export { isFunction } from './isFunction.js';
17
+ export type { AnyFunction } from './isFunction.js';
18
+ export { isInstanceOf } from './isInstanceOf.js';
19
+ export { isMap } from './isMap.js';
20
+ export { isNaNValue } from './isNaNValue.js';
21
+ export { isNegativeNumber } from './isNegativeNumber.js';
22
+ export { isNull } from './isNull.js';
23
+ export { isNullOrUndefined } from './isNullOrUndefined.js';
24
+ export { isNumber } from './isNumber.js';
25
+ export { isObject } from './isObject.js';
26
+ export { isObjectLike } from './isObjectLike.js';
27
+ export { isOneOf } from './isOneOf.js';
28
+ export { isPlainObject } from './isPlainObject.js';
29
+ export type { PlainObject } from './isPlainObject.js';
30
+ export { isPositiveNumber } from './isPositiveNumber.js';
31
+ export { isPrimitive } from './isPrimitive.js';
32
+ export { isPromise } from './isPromise.js';
33
+ export { isRegExp } from './isRegExp.js';
34
+ export { isSet } from './isSet.js';
35
+ export { isString } from './isString.js';
36
+ export { isSymbol } from './isSymbol.js';
37
+ export { isType } from './isType.js';
38
+ export type { AnyClass } from './isType.js';
39
+ export { isUndefined } from './isUndefined.js';
40
+ export { isWeakMap } from './isWeakMap.js';
41
+ export { isWeakSet } from './isWeakSet.js';
package/dist/index.js CHANGED
@@ -1,135 +1,37 @@
1
- function getType(payload) {
2
- return Object.prototype.toString.call(payload).slice(8, -1);
3
- }
4
- function isUndefined(payload) {
5
- return getType(payload) === "Undefined";
6
- }
7
- function isNull(payload) {
8
- return getType(payload) === "Null";
9
- }
10
- function isPlainObject(payload) {
11
- if (getType(payload) !== "Object")
12
- return false;
13
- const prototype = Object.getPrototypeOf(payload);
14
- return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
15
- }
16
- function isObject(payload) {
17
- return isPlainObject(payload);
18
- }
19
- function isEmptyObject(payload) {
20
- return isPlainObject(payload) && Object.keys(payload).length === 0;
21
- }
22
- function isFullObject(payload) {
23
- return isPlainObject(payload) && Object.keys(payload).length > 0;
24
- }
25
- function isAnyObject(payload) {
26
- return getType(payload) === "Object";
27
- }
28
- function isObjectLike(payload) {
29
- return isAnyObject(payload);
30
- }
31
- function isFunction(payload) {
32
- return typeof payload === "function";
33
- }
34
- function isArray(payload) {
35
- return getType(payload) === "Array";
36
- }
37
- function isFullArray(payload) {
38
- return isArray(payload) && payload.length > 0;
39
- }
40
- function isEmptyArray(payload) {
41
- return isArray(payload) && payload.length === 0;
42
- }
43
- function isString(payload) {
44
- return getType(payload) === "String";
45
- }
46
- function isFullString(payload) {
47
- return isString(payload) && payload !== "";
48
- }
49
- function isEmptyString(payload) {
50
- return payload === "";
51
- }
52
- function isNumber(payload) {
53
- return getType(payload) === "Number" && !isNaN(payload);
54
- }
55
- function isPositiveNumber(payload) {
56
- return isNumber(payload) && payload > 0;
57
- }
58
- function isNegativeNumber(payload) {
59
- return isNumber(payload) && payload < 0;
60
- }
61
- function isBoolean(payload) {
62
- return getType(payload) === "Boolean";
63
- }
64
- function isRegExp(payload) {
65
- return getType(payload) === "RegExp";
66
- }
67
- function isMap(payload) {
68
- return getType(payload) === "Map";
69
- }
70
- function isWeakMap(payload) {
71
- return getType(payload) === "WeakMap";
72
- }
73
- function isSet(payload) {
74
- return getType(payload) === "Set";
75
- }
76
- function isWeakSet(payload) {
77
- return getType(payload) === "WeakSet";
78
- }
79
- function isSymbol(payload) {
80
- return getType(payload) === "Symbol";
81
- }
82
- function isDate(payload) {
83
- return getType(payload) === "Date" && !isNaN(payload);
84
- }
85
- function isBlob(payload) {
86
- return getType(payload) === "Blob";
87
- }
88
- function isFile(payload) {
89
- return getType(payload) === "File";
90
- }
91
- function isPromise(payload) {
92
- return getType(payload) === "Promise";
93
- }
94
- function isError(payload) {
95
- return getType(payload) === "Error";
96
- }
97
- function isNaNValue(payload) {
98
- return getType(payload) === "Number" && isNaN(payload);
99
- }
100
- function isPrimitive(payload) {
101
- return isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
102
- }
103
- const isNullOrUndefined = isOneOf(isNull, isUndefined);
104
- function isOneOf(a, b, c, d, e) {
105
- return (value) => a(value) || b(value) || !!c && c(value) || !!d && d(value) || !!e && e(value);
106
- }
107
- function isType(payload, type) {
108
- if (!(type instanceof Function)) {
109
- throw new TypeError("Type must be a function");
110
- }
111
- if (!Object.prototype.hasOwnProperty.call(type, "prototype")) {
112
- throw new TypeError("Type is not a class");
113
- }
114
- const name = type.name;
115
- return getType(payload) === name || Boolean(payload && payload.constructor === type);
116
- }
117
- function isInstanceOf(value, classOrClassName) {
118
- if (typeof classOrClassName === "function") {
119
- for (let p = value; p; p = Object.getPrototypeOf(p)) {
120
- if (isType(p, classOrClassName)) {
121
- return true;
122
- }
123
- }
124
- return false;
125
- } else {
126
- for (let p = value; p; p = Object.getPrototypeOf(p)) {
127
- if (getType(p) === classOrClassName) {
128
- return true;
129
- }
130
- }
131
- return false;
132
- }
133
- }
134
-
135
- export { 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 };
1
+ export { getType } from './getType.js';
2
+ export { isAnyObject } from './isAnyObject.js';
3
+ export { isArray } from './isArray.js';
4
+ export { isBlob } from './isBlob.js';
5
+ export { isBoolean } from './isBoolean.js';
6
+ export { isDate } from './isDate.js';
7
+ export { isEmptyArray } from './isEmptyArray.js';
8
+ export { isEmptyObject } from './isEmptyObject.js';
9
+ export { isEmptyString } from './isEmptyString.js';
10
+ export { isError } from './isError.js';
11
+ export { isFile } from './isFile.js';
12
+ export { isFullArray } from './isFullArray.js';
13
+ export { isFullObject } from './isFullObject.js';
14
+ export { isFullString } from './isFullString.js';
15
+ export { isFunction } from './isFunction.js';
16
+ export { isInstanceOf } from './isInstanceOf.js';
17
+ export { isMap } from './isMap.js';
18
+ export { isNaNValue } from './isNaNValue.js';
19
+ export { isNegativeNumber } from './isNegativeNumber.js';
20
+ export { isNull } from './isNull.js';
21
+ export { isNullOrUndefined } from './isNullOrUndefined.js';
22
+ export { isNumber } from './isNumber.js';
23
+ export { isObject } from './isObject.js';
24
+ export { isObjectLike } from './isObjectLike.js';
25
+ export { isOneOf } from './isOneOf.js';
26
+ export { isPlainObject } from './isPlainObject.js';
27
+ export { isPositiveNumber } from './isPositiveNumber.js';
28
+ export { isPrimitive } from './isPrimitive.js';
29
+ export { isPromise } from './isPromise.js';
30
+ export { isRegExp } from './isRegExp.js';
31
+ export { isSet } from './isSet.js';
32
+ export { isString } from './isString.js';
33
+ export { isSymbol } from './isSymbol.js';
34
+ export { isType } from './isType.js';
35
+ export { isUndefined } from './isUndefined.js';
36
+ export { isWeakMap } from './isWeakMap.js';
37
+ export { isWeakSet } from './isWeakSet.js';
@@ -0,0 +1,6 @@
1
+ import { PlainObject } from './isPlainObject.js';
2
+ /**
3
+ * Returns whether the payload is an any kind of object (including special classes or objects with
4
+ * different prototypes)
5
+ */
6
+ export declare function isAnyObject(payload: unknown): payload is PlainObject;
@@ -0,0 +1,8 @@
1
+ import { getType } from './getType.js';
2
+ /**
3
+ * Returns whether the payload is an any kind of object (including special classes or objects with
4
+ * different prototypes)
5
+ */
6
+ export function isAnyObject(payload) {
7
+ return getType(payload) === 'Object';
8
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is an array */
2
+ export declare function isArray(payload: unknown): payload is unknown[];
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is an array */
3
+ export function isArray(payload) {
4
+ return getType(payload) === 'Array';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a Blob */
2
+ export declare function isBlob(payload: unknown): payload is Blob;
package/dist/isBlob.js ADDED
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a Blob */
3
+ export function isBlob(payload) {
4
+ return getType(payload) === 'Blob';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a boolean */
2
+ export declare function isBoolean(payload: unknown): payload is boolean;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a boolean */
3
+ export function isBoolean(payload) {
4
+ return getType(payload) === 'Boolean';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a Date, and that the date is valid */
2
+ export declare function isDate(payload: unknown): payload is Date;
package/dist/isDate.js ADDED
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a Date, and that the date is valid */
3
+ export function isDate(payload) {
4
+ return getType(payload) === 'Date' && !isNaN(payload);
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a an empty array */
2
+ export declare function isEmptyArray(payload: unknown): payload is [];