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.
- package/README.md +6 -6
- package/dist/getType.d.ts +2 -0
- package/dist/getType.js +4 -0
- package/dist/index.d.ts +41 -334
- package/dist/index.js +37 -135
- 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 +13 -83
- package/dist/cjs/index.cjs +0 -173
- 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:
|
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,334 +1,41 @@
|
|
1
|
-
type
|
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
|
-
* 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
|
-
|
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
|
-
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';
|
package/dist/isArray.js
ADDED
package/dist/isBlob.d.ts
ADDED
package/dist/isBlob.js
ADDED
package/dist/isDate.d.ts
ADDED
package/dist/isDate.js
ADDED