@hypernym/utils 3.4.4 → 3.4.6
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/LICENSE.txt +2 -1
- package/README.md +371 -13
- package/dist/fs/{index.d.mts → index.d.ts} +115 -108
- package/dist/fs/index.js +161 -0
- package/dist/{index.d.mts → index.d.ts} +139 -66
- package/dist/index.iife.js +1 -1
- package/dist/index.js +437 -0
- package/dist/index.min.js +1 -0
- package/dist/index.umd.js +1 -1
- package/package.json +24 -25
- package/dist/fs/index.mjs +0 -59
- package/dist/index.min.mjs +0 -1
- package/dist/index.mjs +0 -40
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/base/index.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* An empty arrow function that performs no operation.
|
|
3
4
|
*
|
|
@@ -18,20 +19,42 @@ declare const noop: () => void;
|
|
|
18
19
|
* ```ts
|
|
19
20
|
* import { toString } from '@hypernym/utils'
|
|
20
21
|
*
|
|
21
|
-
* toString({}) //
|
|
22
|
+
* toString({}) // 'Object'
|
|
22
23
|
* ```
|
|
23
24
|
*/
|
|
24
25
|
declare const toString: (v: any) => string;
|
|
25
|
-
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/types/base/index.d.ts
|
|
26
28
|
/**
|
|
27
29
|
* Matches any primitive value.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import type { Primitive } from '@hypernym/utils'
|
|
35
|
+
*
|
|
36
|
+
* type OnlyPrimitives<T> = T extends Primitive ? T : never
|
|
37
|
+
*
|
|
38
|
+
* type Filtered = OnlyPrimitives<string | number | {} | Date> // string | number
|
|
39
|
+
* ```
|
|
28
40
|
*/
|
|
29
41
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
30
42
|
/**
|
|
31
43
|
* Matches any `Primitive`, `Date` or `RegExp` value.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* import type { BuiltIn } from '@hypernym/utils'
|
|
49
|
+
*
|
|
50
|
+
* type OnlyBuiltIns<T> = T extends BuiltIn ? T : never
|
|
51
|
+
*
|
|
52
|
+
* type Filtered = OnlyBuiltIns<string | Date | {} | RegExp> // string | Date | RegExp
|
|
53
|
+
* ```
|
|
32
54
|
*/
|
|
33
55
|
type BuiltIn = Primitive | Date | RegExp;
|
|
34
|
-
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/is/index.d.ts
|
|
35
58
|
/**
|
|
36
59
|
* Checks if the code is running in the browser.
|
|
37
60
|
*
|
|
@@ -52,7 +75,7 @@ declare const isBrowser: boolean;
|
|
|
52
75
|
* ```ts
|
|
53
76
|
* import { isNull } from '@hypernym/utils'
|
|
54
77
|
*
|
|
55
|
-
* isNull(null) //
|
|
78
|
+
* isNull(null) // true
|
|
56
79
|
* ```
|
|
57
80
|
*/
|
|
58
81
|
declare const isNull: (v: any) => v is null;
|
|
@@ -64,7 +87,7 @@ declare const isNull: (v: any) => v is null;
|
|
|
64
87
|
* ```ts
|
|
65
88
|
* import { isUndefined } from '@hypernym/utils'
|
|
66
89
|
*
|
|
67
|
-
* isUndefined(undefined) //
|
|
90
|
+
* isUndefined(undefined) // true
|
|
68
91
|
* ```
|
|
69
92
|
*/
|
|
70
93
|
declare const isUndefined: (v: any) => v is undefined;
|
|
@@ -76,7 +99,7 @@ declare const isUndefined: (v: any) => v is undefined;
|
|
|
76
99
|
* ```ts
|
|
77
100
|
* import { isString } from '@hypernym/utils'
|
|
78
101
|
*
|
|
79
|
-
* isString('@hypernym/utils') //
|
|
102
|
+
* isString('@hypernym/utils') // true
|
|
80
103
|
* ```
|
|
81
104
|
*/
|
|
82
105
|
declare const isString: (v: any) => v is string;
|
|
@@ -88,7 +111,7 @@ declare const isString: (v: any) => v is string;
|
|
|
88
111
|
* ```ts
|
|
89
112
|
* import { isStringEmpty } from '@hypernym/utils'
|
|
90
113
|
*
|
|
91
|
-
* isStringEmpty('') //
|
|
114
|
+
* isStringEmpty('') // true
|
|
92
115
|
* ```
|
|
93
116
|
*/
|
|
94
117
|
declare const isStringEmpty: (v: any) => v is string;
|
|
@@ -100,7 +123,7 @@ declare const isStringEmpty: (v: any) => v is string;
|
|
|
100
123
|
* ```ts
|
|
101
124
|
* import { isBoolean } from '@hypernym/utils'
|
|
102
125
|
*
|
|
103
|
-
* isBoolean(true) //
|
|
126
|
+
* isBoolean(true) // true
|
|
104
127
|
* ```
|
|
105
128
|
*/
|
|
106
129
|
declare const isBoolean: (v: any) => v is boolean;
|
|
@@ -112,7 +135,7 @@ declare const isBoolean: (v: any) => v is boolean;
|
|
|
112
135
|
* ```ts
|
|
113
136
|
* import { isTrue } from '@hypernym/utils'
|
|
114
137
|
*
|
|
115
|
-
* isTrue(true) //
|
|
138
|
+
* isTrue(true) // true
|
|
116
139
|
* ```
|
|
117
140
|
*/
|
|
118
141
|
declare const isTrue: (v: any) => v is true;
|
|
@@ -124,7 +147,7 @@ declare const isTrue: (v: any) => v is true;
|
|
|
124
147
|
* ```ts
|
|
125
148
|
* import { isFalse } from '@hypernym/utils'
|
|
126
149
|
*
|
|
127
|
-
* isFalse(false) //
|
|
150
|
+
* isFalse(false) // true
|
|
128
151
|
* ```
|
|
129
152
|
*/
|
|
130
153
|
declare const isFalse: (v: any) => v is false;
|
|
@@ -136,7 +159,7 @@ declare const isFalse: (v: any) => v is false;
|
|
|
136
159
|
* ```ts
|
|
137
160
|
* import { isNumber } from '@hypernym/utils'
|
|
138
161
|
*
|
|
139
|
-
* isNumber(33) //
|
|
162
|
+
* isNumber(33) // true
|
|
140
163
|
* ```
|
|
141
164
|
*/
|
|
142
165
|
declare const isNumber: (v: any) => v is number;
|
|
@@ -148,7 +171,7 @@ declare const isNumber: (v: any) => v is number;
|
|
|
148
171
|
* ```ts
|
|
149
172
|
* import { isArray } from '@hypernym/utils'
|
|
150
173
|
*
|
|
151
|
-
* isArray([]) //
|
|
174
|
+
* isArray([]) // true
|
|
152
175
|
* ```
|
|
153
176
|
*/
|
|
154
177
|
declare const isArray: (v: any) => v is any[];
|
|
@@ -160,7 +183,7 @@ declare const isArray: (v: any) => v is any[];
|
|
|
160
183
|
* ```ts
|
|
161
184
|
* import { isArrayEmpty } from '@hypernym/utils'
|
|
162
185
|
*
|
|
163
|
-
* isArrayEmpty([]) //
|
|
186
|
+
* isArrayEmpty([]) // true
|
|
164
187
|
* ```
|
|
165
188
|
*/
|
|
166
189
|
declare const isArrayEmpty: (v: any) => v is any[];
|
|
@@ -172,7 +195,7 @@ declare const isArrayEmpty: (v: any) => v is any[];
|
|
|
172
195
|
* ```ts
|
|
173
196
|
* import { isObject } from '@hypernym/utils'
|
|
174
197
|
*
|
|
175
|
-
* isObject({}) //
|
|
198
|
+
* isObject({}) // true
|
|
176
199
|
* ```
|
|
177
200
|
*/
|
|
178
201
|
declare const isObject: (v: any) => v is object;
|
|
@@ -184,7 +207,7 @@ declare const isObject: (v: any) => v is object;
|
|
|
184
207
|
* ```ts
|
|
185
208
|
* import { isObjectEmpty } from '@hypernym/utils'
|
|
186
209
|
*
|
|
187
|
-
* isObjectEmpty({}) //
|
|
210
|
+
* isObjectEmpty({}) // true
|
|
188
211
|
* ```
|
|
189
212
|
*/
|
|
190
213
|
declare const isObjectEmpty: (v: any) => v is object;
|
|
@@ -196,7 +219,7 @@ declare const isObjectEmpty: (v: any) => v is object;
|
|
|
196
219
|
* ```ts
|
|
197
220
|
* import { isFunction } from '@hypernym/utils'
|
|
198
221
|
*
|
|
199
|
-
* isFunction(() => {}) //
|
|
222
|
+
* isFunction(() => {}) // true
|
|
200
223
|
* ```
|
|
201
224
|
*/
|
|
202
225
|
declare const isFunction: (v: any) => v is (...args: any[]) => unknown;
|
|
@@ -208,7 +231,7 @@ declare const isFunction: (v: any) => v is (...args: any[]) => unknown;
|
|
|
208
231
|
* ```ts
|
|
209
232
|
* import { isNaNValue } from '@hypernym/utils'
|
|
210
233
|
*
|
|
211
|
-
* isNaNValue(NaN) //
|
|
234
|
+
* isNaNValue(NaN) // true
|
|
212
235
|
* ```
|
|
213
236
|
*/
|
|
214
237
|
declare const isNaNValue: (v: any) => v is typeof NaN;
|
|
@@ -220,7 +243,7 @@ declare const isNaNValue: (v: any) => v is typeof NaN;
|
|
|
220
243
|
* ```ts
|
|
221
244
|
* import { isRegExp } from '@hypernym/utils'
|
|
222
245
|
*
|
|
223
|
-
* isRegExp(/^hypernym/) //
|
|
246
|
+
* isRegExp(/^hypernym/) // true
|
|
224
247
|
* ```
|
|
225
248
|
*/
|
|
226
249
|
declare const isRegExp: (v: any) => v is RegExp;
|
|
@@ -232,7 +255,7 @@ declare const isRegExp: (v: any) => v is RegExp;
|
|
|
232
255
|
* ```ts
|
|
233
256
|
* import { isMap } from '@hypernym/utils'
|
|
234
257
|
*
|
|
235
|
-
* isMap(new Map()) //
|
|
258
|
+
* isMap(new Map()) // true
|
|
236
259
|
* ```
|
|
237
260
|
*/
|
|
238
261
|
declare const isMap: (v: any) => v is Map<any, any>;
|
|
@@ -244,7 +267,7 @@ declare const isMap: (v: any) => v is Map<any, any>;
|
|
|
244
267
|
* ```ts
|
|
245
268
|
* import { isWeakMap } from '@hypernym/utils'
|
|
246
269
|
*
|
|
247
|
-
* isWeakMap(new WeakMap()) //
|
|
270
|
+
* isWeakMap(new WeakMap()) // true
|
|
248
271
|
* ```
|
|
249
272
|
*/
|
|
250
273
|
declare const isWeakMap: (v: any) => v is WeakMap<any, any>;
|
|
@@ -256,7 +279,7 @@ declare const isWeakMap: (v: any) => v is WeakMap<any, any>;
|
|
|
256
279
|
* ```ts
|
|
257
280
|
* import { isSet } from '@hypernym/utils'
|
|
258
281
|
*
|
|
259
|
-
* isSet(new Set()) //
|
|
282
|
+
* isSet(new Set()) // true
|
|
260
283
|
* ```
|
|
261
284
|
*/
|
|
262
285
|
declare const isSet: (v: any) => v is Set<any>;
|
|
@@ -268,7 +291,7 @@ declare const isSet: (v: any) => v is Set<any>;
|
|
|
268
291
|
* ```ts
|
|
269
292
|
* import { isWeakSet } from '@hypernym/utils'
|
|
270
293
|
*
|
|
271
|
-
* isWeakSet(new WeakSet()) //
|
|
294
|
+
* isWeakSet(new WeakSet()) // true
|
|
272
295
|
* ```
|
|
273
296
|
*/
|
|
274
297
|
declare const isWeakSet: (v: any) => v is WeakSet<any>;
|
|
@@ -280,7 +303,7 @@ declare const isWeakSet: (v: any) => v is WeakSet<any>;
|
|
|
280
303
|
* ```ts
|
|
281
304
|
* import { isSymbol } from '@hypernym/utils'
|
|
282
305
|
*
|
|
283
|
-
* isSymbol(Symboly('hypernym')) //
|
|
306
|
+
* isSymbol(Symboly('hypernym')) // true
|
|
284
307
|
* ```
|
|
285
308
|
*/
|
|
286
309
|
declare const isSymbol: (v: any) => v is symbol;
|
|
@@ -292,7 +315,7 @@ declare const isSymbol: (v: any) => v is symbol;
|
|
|
292
315
|
* ```ts
|
|
293
316
|
* import { isDate } from '@hypernym/utils'
|
|
294
317
|
*
|
|
295
|
-
* isDate(new Date()) //
|
|
318
|
+
* isDate(new Date()) // true
|
|
296
319
|
* ```
|
|
297
320
|
*/
|
|
298
321
|
declare const isDate: (v: any) => v is Date;
|
|
@@ -304,7 +327,7 @@ declare const isDate: (v: any) => v is Date;
|
|
|
304
327
|
* ```ts
|
|
305
328
|
* import { isBigInt } from '@hypernym/utils'
|
|
306
329
|
*
|
|
307
|
-
* isBigInt(1n) //
|
|
330
|
+
* isBigInt(1n) // true
|
|
308
331
|
* ```
|
|
309
332
|
*/
|
|
310
333
|
declare const isBigInt: (v: any) => v is bigint;
|
|
@@ -316,7 +339,7 @@ declare const isBigInt: (v: any) => v is bigint;
|
|
|
316
339
|
* ```ts
|
|
317
340
|
* import { isInfinity } from '@hypernym/utils'
|
|
318
341
|
*
|
|
319
|
-
* isInfinity(Infinity) //
|
|
342
|
+
* isInfinity(Infinity) // true
|
|
320
343
|
* ```
|
|
321
344
|
*/
|
|
322
345
|
declare const isInfinity: (v: any) => v is number;
|
|
@@ -328,7 +351,7 @@ declare const isInfinity: (v: any) => v is number;
|
|
|
328
351
|
* ```ts
|
|
329
352
|
* import { isURL } from '@hypernym/utils'
|
|
330
353
|
*
|
|
331
|
-
* isURL(new URL('https://localhost:3000')) //
|
|
354
|
+
* isURL(new URL('https://localhost:3000')) // true
|
|
332
355
|
* ```
|
|
333
356
|
*/
|
|
334
357
|
declare const isURL: (v: any) => v is URL;
|
|
@@ -340,7 +363,7 @@ declare const isURL: (v: any) => v is URL;
|
|
|
340
363
|
* ```ts
|
|
341
364
|
* import { isError } from '@hypernym/utils'
|
|
342
365
|
*
|
|
343
|
-
* isError(new Error()) //
|
|
366
|
+
* isError(new Error()) // true
|
|
344
367
|
* ```
|
|
345
368
|
*/
|
|
346
369
|
declare const isError: (v: any) => v is Error;
|
|
@@ -352,7 +375,7 @@ declare const isError: (v: any) => v is Error;
|
|
|
352
375
|
* ```ts
|
|
353
376
|
* import { isPrimitive } from '@hypernym/utils'
|
|
354
377
|
*
|
|
355
|
-
* isPrimitive(true) //
|
|
378
|
+
* isPrimitive(true) // true
|
|
356
379
|
* ```
|
|
357
380
|
*/
|
|
358
381
|
declare const isPrimitive: (v: any) => v is Primitive;
|
|
@@ -364,7 +387,7 @@ declare const isPrimitive: (v: any) => v is Primitive;
|
|
|
364
387
|
* ```ts
|
|
365
388
|
* import { isElement } from '@hypernym/utils'
|
|
366
389
|
*
|
|
367
|
-
* isElement(el) //
|
|
390
|
+
* isElement(el) // true
|
|
368
391
|
* ```
|
|
369
392
|
*/
|
|
370
393
|
declare const isElement: (v: any) => v is Element;
|
|
@@ -376,7 +399,7 @@ declare const isElement: (v: any) => v is Element;
|
|
|
376
399
|
* ```ts
|
|
377
400
|
* import { isHtmlElement } from '@hypernym/utils'
|
|
378
401
|
*
|
|
379
|
-
* isHtmlElement(htmlEl) //
|
|
402
|
+
* isHtmlElement(htmlEl) // true
|
|
380
403
|
* ```
|
|
381
404
|
*/
|
|
382
405
|
declare const isHtmlElement: (v: any) => v is HTMLElement;
|
|
@@ -388,7 +411,7 @@ declare const isHtmlElement: (v: any) => v is HTMLElement;
|
|
|
388
411
|
* ```ts
|
|
389
412
|
* import { isSvgElement } from '@hypernym/utils'
|
|
390
413
|
*
|
|
391
|
-
* isSvgElement(svgEl) //
|
|
414
|
+
* isSvgElement(svgEl) // true
|
|
392
415
|
* ```
|
|
393
416
|
*/
|
|
394
417
|
declare const isSvgElement: (v: any) => v is SVGElement;
|
|
@@ -400,7 +423,7 @@ declare const isSvgElement: (v: any) => v is SVGElement;
|
|
|
400
423
|
* ```ts
|
|
401
424
|
* import { isNodeList } from '@hypernym/utils'
|
|
402
425
|
*
|
|
403
|
-
* isNodeList(document.querySelectorAll('div')) //
|
|
426
|
+
* isNodeList(document.querySelectorAll('div')) // true
|
|
404
427
|
* ```
|
|
405
428
|
*/
|
|
406
429
|
declare const isNodeList: (v: any) => v is NodeList;
|
|
@@ -412,7 +435,7 @@ declare const isNodeList: (v: any) => v is NodeList;
|
|
|
412
435
|
* ```ts
|
|
413
436
|
* import { isNodeListEmpty } from '@hypernym/utils'
|
|
414
437
|
*
|
|
415
|
-
* isNodeListEmpty(document.querySelectorAll('divs')) //
|
|
438
|
+
* isNodeListEmpty(document.querySelectorAll('divs')) // true
|
|
416
439
|
* ```
|
|
417
440
|
*/
|
|
418
441
|
declare const isNodeListEmpty: (v: any) => v is NodeList;
|
|
@@ -424,7 +447,7 @@ declare const isNodeListEmpty: (v: any) => v is NodeList;
|
|
|
424
447
|
* ```ts
|
|
425
448
|
* import { isHtmlCollection } from '@hypernym/utils'
|
|
426
449
|
*
|
|
427
|
-
* isHtmlCollection(document.getElementsByClassName('el')) //
|
|
450
|
+
* isHtmlCollection(document.getElementsByClassName('el')) // true
|
|
428
451
|
* ```
|
|
429
452
|
*/
|
|
430
453
|
declare const isHtmlCollection: (v: any) => v is HTMLCollection;
|
|
@@ -434,67 +457,117 @@ declare const isHtmlCollection: (v: any) => v is HTMLCollection;
|
|
|
434
457
|
* ```ts
|
|
435
458
|
* import { isHtmlCollectionEmpty } from '@hypernym/utils'
|
|
436
459
|
*
|
|
437
|
-
* isHtmlCollectionEmpty(document.getElementsByClassName('els')) //
|
|
460
|
+
* isHtmlCollectionEmpty(document.getElementsByClassName('els')) // true
|
|
438
461
|
* ```
|
|
439
462
|
*/
|
|
440
463
|
declare const isHtmlCollectionEmpty: (v: any) => v is HTMLCollection;
|
|
441
|
-
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/types/is/index.d.ts
|
|
442
466
|
/**
|
|
443
467
|
* Returns a boolean if the given type is a `null`.
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
*
|
|
471
|
+
* ```ts
|
|
472
|
+
* import type { IsNull } from '@hypernym/utils'
|
|
473
|
+
*
|
|
474
|
+
* type A = IsNull<null> // true
|
|
475
|
+
* type B = IsNull<string> // false
|
|
476
|
+
* type C = IsNull<undefined> // false
|
|
477
|
+
* ```
|
|
444
478
|
*/
|
|
445
479
|
type IsNull<T> = [T] extends [null] ? true : false;
|
|
446
480
|
/**
|
|
447
481
|
* Returns a boolean if the given type is a `any`.
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
*
|
|
485
|
+
* ```ts
|
|
486
|
+
* import type { IsAny } from '@hypernym/utils'
|
|
487
|
+
*
|
|
488
|
+
* type A = IsAny<any> // true
|
|
489
|
+
* type B = IsAny<string> // false
|
|
490
|
+
* type C = IsAny<unknown> // false
|
|
491
|
+
* ```
|
|
448
492
|
*/
|
|
449
493
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
450
494
|
/**
|
|
451
495
|
* Returns a boolean if the given type is a `never`.
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
*
|
|
499
|
+
* ```ts
|
|
500
|
+
* import type { IsNever } from '@hypernym/utils'
|
|
501
|
+
*
|
|
502
|
+
* type A = IsNever<never> // true
|
|
503
|
+
* type B = IsNever<number> // false
|
|
504
|
+
* type C = IsNever<undefined> // false
|
|
505
|
+
* ```
|
|
452
506
|
*/
|
|
453
507
|
type IsNever<T> = [T] extends [never] ? true : false;
|
|
454
|
-
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/types/partial-deep/index.d.ts
|
|
455
510
|
type PartialOptions = {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
511
|
+
/**
|
|
512
|
+
* Enables recursive mode for arrays and tuples.
|
|
513
|
+
*
|
|
514
|
+
* @default true
|
|
515
|
+
*/
|
|
516
|
+
readonly arrays?: boolean;
|
|
462
517
|
};
|
|
463
518
|
/**
|
|
464
519
|
* Constructs a type by recursively setting all properties as optional.
|
|
465
520
|
*
|
|
466
521
|
* Use `Partial<T>` for one level.
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
*
|
|
525
|
+
* ```ts
|
|
526
|
+
* import type { PartialDeep } from '@hypernym/utils'
|
|
527
|
+
*
|
|
528
|
+
* type PartialObject = PartialDeep<Object>
|
|
529
|
+
*
|
|
530
|
+
* // Disables recursive mode for arrays and tuples.
|
|
531
|
+
* type PartialObject = PartialDeep<Object, { arrays: false }>
|
|
532
|
+
* ```
|
|
467
533
|
*/
|
|
468
534
|
type PartialDeep<T, Options extends PartialOptions = {
|
|
469
|
-
|
|
470
|
-
}> = T extends BuiltIn ? T | undefined : T extends Map<infer K, infer V> ? Map<PartialDeep<K, Options>, PartialDeep<V, Options>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<PartialDeep<K, Options>, PartialDeep<V, Options>> : T extends WeakMap<infer K, infer V> ? WeakMap<Partial<K>, PartialDeep<V, Options>> : T extends Set<infer V> ? Set<PartialDeep<V, Options>> : T extends ReadonlySet<infer V> ? ReadonlySet<PartialDeep<V, Options>> : T extends WeakSet<infer V> ? WeakSet<Partial<V>> : T extends Promise<infer V> ? Promise<PartialDeep<V, Options>> : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends ReadonlyArray<infer V> ? Options['arrays'] extends true ? V[] extends T ? readonly V[] extends T ? ReadonlyArray<PartialDeep<V, Options>> : Array<PartialDeep<V, Options>> : PartialObjectDeep<T, Options> : T | undefined : PartialObjectDeep<T, Options> : unknown;
|
|
535
|
+
arrays: true;
|
|
536
|
+
}> = T extends BuiltIn ? T | undefined : T extends Map<infer K, infer V> ? Map<PartialDeep<K, Options>, PartialDeep<V, Options>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<PartialDeep<K, Options>, PartialDeep<V, Options>> : T extends WeakMap<infer K, infer V> ? WeakMap<Partial<K>, PartialDeep<V, Options>> : T extends Set<infer V> ? Set<PartialDeep<V, Options>> : T extends ReadonlySet<infer V> ? ReadonlySet<PartialDeep<V, Options>> : T extends WeakSet<infer V> ? WeakSet<Partial<V>> : T extends Promise<infer V> ? Promise<PartialDeep<V, Options>> : T extends ((...args: any[]) => unknown) ? T | undefined : T extends object ? T extends ReadonlyArray<infer V> ? Options['arrays'] extends true ? V[] extends T ? readonly V[] extends T ? ReadonlyArray<PartialDeep<V, Options>> : Array<PartialDeep<V, Options>> : PartialObjectDeep<T, Options> : T | undefined : PartialObjectDeep<T, Options> : unknown;
|
|
471
537
|
type PartialObjectDeep<T extends object, Options extends PartialOptions = {
|
|
472
|
-
|
|
473
|
-
}> = {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
538
|
+
arrays: true;
|
|
539
|
+
}> = { [K in keyof T]?: PartialDeep<T[K], Options> };
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region src/types/required-deep/index.d.ts
|
|
477
542
|
type RequiredOptions = {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
543
|
+
/**
|
|
544
|
+
* Enables recursive mode for arrays and tuples.
|
|
545
|
+
*
|
|
546
|
+
* @default true
|
|
547
|
+
*/
|
|
548
|
+
readonly arrays?: boolean;
|
|
484
549
|
};
|
|
485
550
|
/**
|
|
486
551
|
* Constructs a type by recursively setting all properties as required.
|
|
487
552
|
*
|
|
488
553
|
* Use `Required<T>` for one level.
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
*
|
|
557
|
+
* ```ts
|
|
558
|
+
* import type { RequiredDeep } from '@hypernym/utils'
|
|
559
|
+
*
|
|
560
|
+
* type RequiredObject = RequiredDeep<Object>
|
|
561
|
+
*
|
|
562
|
+
* // Disables recursive mode for arrays and tuples.
|
|
563
|
+
* type RequiredObject = RequiredDeep<Object, { arrays: false }>
|
|
564
|
+
* ```
|
|
489
565
|
*/
|
|
490
566
|
type RequiredDeep<T, Options extends RequiredOptions = {
|
|
491
|
-
|
|
492
|
-
}> = T extends BuiltIn ? Exclude<T, undefined> : T extends Map<infer K, infer V> ? Map<RequiredDeep<K, Options>, RequiredDeep<V, Options>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<RequiredDeep<K, Options>, RequiredDeep<V, Options>> : T extends WeakMap<infer K, infer V> ? WeakMap<RequiredDeep<K, Options>, RequiredDeep<V, Options>> : T extends Set<infer V> ? Set<RequiredDeep<V, Options>> : T extends ReadonlySet<infer V> ? ReadonlySet<RequiredDeep<V, Options>> : T extends WeakSet<infer V> ? WeakSet<RequiredDeep<V, Options>> : T extends Promise<infer V> ? Promise<RequiredDeep<V, Options>> : T extends (...args: any[]) => unknown ? Exclude<T, undefined> : T extends object ? T extends ReadonlyArray<infer V> ? Options['arrays'] extends true ? V[] extends T ? readonly V[] extends T ? ReadonlyArray<RequiredDeep<Exclude<V, undefined>, Options>> : Array<RequiredDeep<Exclude<V, undefined>, Options>> : RequiredObjectDeep<T, Options> : Exclude<T, undefined> : RequiredObjectDeep<T, Options> : unknown;
|
|
567
|
+
arrays: true;
|
|
568
|
+
}> = T extends BuiltIn ? Exclude<T, undefined> : T extends Map<infer K, infer V> ? Map<RequiredDeep<K, Options>, RequiredDeep<V, Options>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<RequiredDeep<K, Options>, RequiredDeep<V, Options>> : T extends WeakMap<infer K, infer V> ? WeakMap<RequiredDeep<K, Options>, RequiredDeep<V, Options>> : T extends Set<infer V> ? Set<RequiredDeep<V, Options>> : T extends ReadonlySet<infer V> ? ReadonlySet<RequiredDeep<V, Options>> : T extends WeakSet<infer V> ? WeakSet<RequiredDeep<V, Options>> : T extends Promise<infer V> ? Promise<RequiredDeep<V, Options>> : T extends ((...args: any[]) => unknown) ? Exclude<T, undefined> : T extends object ? T extends ReadonlyArray<infer V> ? Options['arrays'] extends true ? V[] extends T ? readonly V[] extends T ? ReadonlyArray<RequiredDeep<Exclude<V, undefined>, Options>> : Array<RequiredDeep<Exclude<V, undefined>, Options>> : RequiredObjectDeep<T, Options> : Exclude<T, undefined> : RequiredObjectDeep<T, Options> : unknown;
|
|
493
569
|
type RequiredObjectDeep<T extends object, Options extends RequiredOptions = {
|
|
494
|
-
|
|
495
|
-
}> = {
|
|
496
|
-
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
export { isArray, isArrayEmpty, isBigInt, isBoolean, isBrowser, isDate, isElement, isError, isFalse, isFunction, isHtmlCollection, isHtmlCollectionEmpty, isHtmlElement, isInfinity, isMap, isNaNValue, isNodeList, isNodeListEmpty, isNull, isNumber, isObject, isObjectEmpty, isPrimitive, isRegExp, isSet, isString, isStringEmpty, isSvgElement, isSymbol, isTrue, isURL, isUndefined, isWeakMap, isWeakSet, noop, toString };
|
|
500
|
-
export type { BuiltIn, IsAny, IsNever, IsNull, PartialDeep, Primitive, RequiredDeep };
|
|
570
|
+
arrays: true;
|
|
571
|
+
}> = { [K in keyof T]-?: RequiredDeep<T[K], Options> };
|
|
572
|
+
//#endregion
|
|
573
|
+
export { BuiltIn, IsAny, IsNever, IsNull, PartialDeep, Primitive, RequiredDeep, isArray, isArrayEmpty, isBigInt, isBoolean, isBrowser, isDate, isElement, isError, isFalse, isFunction, isHtmlCollection, isHtmlCollectionEmpty, isHtmlElement, isInfinity, isMap, isNaNValue, isNodeList, isNodeListEmpty, isNull, isNumber, isObject, isObjectEmpty, isPrimitive, isRegExp, isSet, isString, isStringEmpty, isSvgElement, isSymbol, isTrue, isURL, isUndefined, isWeakMap, isWeakSet, noop, toString };
|
package/dist/index.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Hyperutils=function(e){
|
|
1
|
+
var Hyperutils=(function(e){let t=()=>{},n=e=>Object.prototype.toString.call(e).slice(8,-1),r=typeof window<`u`,i=e=>e===null,a=e=>e===void 0,o=e=>typeof e==`string`,s=e=>o(e)&&e.trim().length===0,c=e=>typeof e==`boolean`,l=e=>e===!0,u=e=>e===!1,d=e=>typeof e==`number`&&!isNaN(e),f=e=>Array.isArray(e),p=e=>f(e)&&e.length===0,m=e=>n(e)===`Object`,h=e=>m(e)&&Object.keys(e).length===0,g=e=>e instanceof Function,_=e=>typeof e==`number`&&isNaN(e),v=e=>e instanceof RegExp,y=e=>e instanceof Map,b=e=>e instanceof WeakMap,x=e=>e instanceof Set,S=e=>e instanceof WeakSet,C=e=>n(e)===`Symbol`,w=e=>e instanceof Date&&!isNaN(e.valueOf()),T=e=>typeof e==`bigint`,E=e=>e===1/0||e===-1/0,D=e=>e instanceof URL,O=e=>e instanceof Error,k=e=>o(e)||d(e)||T(e)||c(e)||C(e)||i(e)||a(e),A=e=>e instanceof Element,j=e=>e instanceof HTMLElement,M=e=>e instanceof SVGElement,N=e=>e instanceof NodeList,P=e=>N(e)&&e.length===0,F=e=>e instanceof HTMLCollection;return e.isArray=f,e.isArrayEmpty=p,e.isBigInt=T,e.isBoolean=c,e.isBrowser=r,e.isDate=w,e.isElement=A,e.isError=O,e.isFalse=u,e.isFunction=g,e.isHtmlCollection=F,e.isHtmlCollectionEmpty=e=>F(e)&&e.length===0,e.isHtmlElement=j,e.isInfinity=E,e.isMap=y,e.isNaNValue=_,e.isNodeList=N,e.isNodeListEmpty=P,e.isNull=i,e.isNumber=d,e.isObject=m,e.isObjectEmpty=h,e.isPrimitive=k,e.isRegExp=v,e.isSet=x,e.isString=o,e.isStringEmpty=s,e.isSvgElement=M,e.isSymbol=C,e.isTrue=l,e.isURL=D,e.isUndefined=a,e.isWeakMap=b,e.isWeakSet=S,e.noop=t,e.toString=n,e})({});
|