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/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:
|
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:
|
219
|
-
function isAnyObject(payload:
|
220
|
-
// The reason to return `{[key: string]:
|
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,
|
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:
|
254
|
+
function isObjectLike<T extends object>(payload: unknown): payload is T {
|
255
255
|
return isAnyObject(payload)
|
256
256
|
}
|
257
257
|
```
|
package/dist/getType.js
ADDED
package/dist/index.d.ts
CHANGED
@@ -1,380 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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 };
|
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,171 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
}
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
}
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
}
|
39
|
-
|
40
|
-
function isEmptyString(payload) {
|
41
|
-
return payload === "";
|
42
|
-
}
|
43
|
-
|
44
|
-
function isError(payload) {
|
45
|
-
return getType(payload) === "Error" || payload instanceof Error;
|
46
|
-
}
|
47
|
-
|
48
|
-
function isFile(payload) {
|
49
|
-
return getType(payload) === "File";
|
50
|
-
}
|
51
|
-
|
52
|
-
function isFullArray(payload) {
|
53
|
-
return isArray(payload) && payload.length > 0;
|
54
|
-
}
|
55
|
-
|
56
|
-
function isFullObject(payload) {
|
57
|
-
return isPlainObject(payload) && Object.keys(payload).length > 0;
|
58
|
-
}
|
59
|
-
|
60
|
-
function isString(payload) {
|
61
|
-
return getType(payload) === "String";
|
62
|
-
}
|
63
|
-
|
64
|
-
function isFullString(payload) {
|
65
|
-
return isString(payload) && payload !== "";
|
66
|
-
}
|
67
|
-
|
68
|
-
function isFunction(payload) {
|
69
|
-
return typeof payload === "function";
|
70
|
-
}
|
71
|
-
|
72
|
-
function isType(payload, type) {
|
73
|
-
if (!(type instanceof Function)) {
|
74
|
-
throw new TypeError("Type must be a function");
|
75
|
-
}
|
76
|
-
if (!Object.prototype.hasOwnProperty.call(type, "prototype")) {
|
77
|
-
throw new TypeError("Type is not a class");
|
78
|
-
}
|
79
|
-
const name = type.name;
|
80
|
-
return getType(payload) === name || Boolean(payload && payload.constructor === type);
|
81
|
-
}
|
82
|
-
|
83
|
-
function isInstanceOf(value, classOrClassName) {
|
84
|
-
if (typeof classOrClassName === "function") {
|
85
|
-
for (let p = value; p; p = Object.getPrototypeOf(p)) {
|
86
|
-
if (isType(p, classOrClassName)) {
|
87
|
-
return true;
|
88
|
-
}
|
89
|
-
}
|
90
|
-
return false;
|
91
|
-
} else {
|
92
|
-
for (let p = value; p; p = Object.getPrototypeOf(p)) {
|
93
|
-
if (getType(p) === classOrClassName) {
|
94
|
-
return true;
|
95
|
-
}
|
96
|
-
}
|
97
|
-
return false;
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
function isMap(payload) {
|
102
|
-
return getType(payload) === "Map";
|
103
|
-
}
|
104
|
-
|
105
|
-
function isNaNValue(payload) {
|
106
|
-
return getType(payload) === "Number" && isNaN(payload);
|
107
|
-
}
|
108
|
-
|
109
|
-
function isNumber(payload) {
|
110
|
-
return getType(payload) === "Number" && !isNaN(payload);
|
111
|
-
}
|
112
|
-
|
113
|
-
function isNegativeNumber(payload) {
|
114
|
-
return isNumber(payload) && payload < 0;
|
115
|
-
}
|
116
|
-
|
117
|
-
function isNull(payload) {
|
118
|
-
return getType(payload) === "Null";
|
119
|
-
}
|
120
|
-
|
121
|
-
function isOneOf(a, b, c, d, e) {
|
122
|
-
return (value) => a(value) || b(value) || !!c && c(value) || !!d && d(value) || !!e && e(value);
|
123
|
-
}
|
124
|
-
|
125
|
-
function isUndefined(payload) {
|
126
|
-
return getType(payload) === "Undefined";
|
127
|
-
}
|
128
|
-
|
129
|
-
const isNullOrUndefined = isOneOf(isNull, isUndefined);
|
130
|
-
|
131
|
-
function isObject(payload) {
|
132
|
-
return isPlainObject(payload);
|
133
|
-
}
|
134
|
-
|
135
|
-
function isObjectLike(payload) {
|
136
|
-
return isAnyObject(payload);
|
137
|
-
}
|
138
|
-
|
139
|
-
function isPositiveNumber(payload) {
|
140
|
-
return isNumber(payload) && payload > 0;
|
141
|
-
}
|
142
|
-
|
143
|
-
function isSymbol(payload) {
|
144
|
-
return getType(payload) === "Symbol";
|
145
|
-
}
|
146
|
-
|
147
|
-
function isPrimitive(payload) {
|
148
|
-
return isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
|
149
|
-
}
|
150
|
-
|
151
|
-
function isPromise(payload) {
|
152
|
-
return getType(payload) === "Promise";
|
153
|
-
}
|
154
|
-
|
155
|
-
function isRegExp(payload) {
|
156
|
-
return getType(payload) === "RegExp";
|
157
|
-
}
|
158
|
-
|
159
|
-
function isSet(payload) {
|
160
|
-
return getType(payload) === "Set";
|
161
|
-
}
|
162
|
-
|
163
|
-
function isWeakMap(payload) {
|
164
|
-
return getType(payload) === "WeakMap";
|
165
|
-
}
|
166
|
-
|
167
|
-
function isWeakSet(payload) {
|
168
|
-
return getType(payload) === "WeakSet";
|
169
|
-
}
|
170
|
-
|
171
|
-
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';
|