@oscarpalmer/atoms 0.77.0 → 0.77.2
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/dist/js/array/chunk.cjs +1 -1
- package/dist/js/array/chunk.js +1 -1
- package/dist/js/value/equal.cjs +4 -1
- package/dist/js/value/equal.js +4 -1
- package/package.json +1 -1
- package/src/js/array/chunk.ts +1 -1
- package/src/js/array/count.ts +6 -6
- package/src/js/array/exists.ts +6 -6
- package/src/js/array/filter.ts +6 -6
- package/src/js/array/find.ts +6 -6
- package/src/js/array/group-by.ts +67 -55
- package/src/js/array/index-of.ts +6 -6
- package/src/js/array/sort.ts +20 -0
- package/src/js/array/to-map.ts +55 -47
- package/src/js/array/to-record.ts +61 -57
- package/src/js/array/unique.ts +6 -6
- package/src/js/internal/value/handle.ts +5 -5
- package/src/js/value/clone.ts +3 -1
- package/src/js/value/equal.ts +4 -1
- package/src/js/value/get.ts +9 -9
- package/src/js/value/set.ts +10 -11
- package/types/array/count.d.cts +34 -2
- package/types/array/count.d.ts +3 -3
- package/types/array/exists.d.cts +34 -2
- package/types/array/exists.d.ts +3 -3
- package/types/array/filter.d.cts +34 -2
- package/types/array/filter.d.ts +3 -3
- package/types/array/find.d.cts +34 -2
- package/types/array/find.d.ts +3 -3
- package/types/array/group-by.d.cts +44 -12
- package/types/array/group-by.d.ts +14 -14
- package/types/array/index-of.d.cts +34 -2
- package/types/array/index-of.d.ts +3 -3
- package/types/array/index.d.cts +88 -46
- package/types/array/sort.d.cts +42 -0
- package/types/array/sort.d.ts +11 -1
- package/types/array/to-map.d.cts +42 -10
- package/types/array/to-map.d.ts +13 -13
- package/types/array/to-record.d.cts +44 -12
- package/types/array/to-record.d.ts +13 -13
- package/types/array/unique.d.cts +34 -2
- package/types/array/unique.d.ts +3 -3
- package/types/index.d.cts +1034 -317
- package/types/internal/value/handle.d.cts +27 -2
- package/types/internal/value/handle.d.ts +2 -2
- package/types/models.d.cts +467 -210
- package/types/value/clone.d.cts +1 -1
- package/types/value/clone.d.ts +1 -1
- package/types/value/get.d.cts +470 -211
- package/types/value/get.d.ts +3 -3
- package/types/value/index.d.cts +515 -224
- package/types/value/set.d.cts +357 -170
- package/types/value/set.d.ts +3 -3
- package/types/value/smush.d.cts +463 -209
package/types/value/index.d.cts
CHANGED
|
@@ -5,7 +5,14 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
|
|
|
5
5
|
|
|
6
6
|
@category Type
|
|
7
7
|
*/
|
|
8
|
-
export type Primitive =
|
|
8
|
+
export type Primitive =
|
|
9
|
+
| null
|
|
10
|
+
| undefined
|
|
11
|
+
| string
|
|
12
|
+
| number
|
|
13
|
+
| boolean
|
|
14
|
+
| symbol
|
|
15
|
+
| bigint;
|
|
9
16
|
/**
|
|
10
17
|
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
11
18
|
|
|
@@ -43,7 +50,9 @@ type AllKeys = KeysOfUnion<Union>;
|
|
|
43
50
|
|
|
44
51
|
@category Object
|
|
45
52
|
*/
|
|
46
|
-
export type KeysOfUnion<ObjectType> = ObjectType extends unknown
|
|
53
|
+
export type KeysOfUnion<ObjectType> = ObjectType extends unknown
|
|
54
|
+
? keyof ObjectType
|
|
55
|
+
: never;
|
|
47
56
|
declare const emptyObjectSymbol: unique symbol;
|
|
48
57
|
/**
|
|
49
58
|
Represents a strictly empty plain object, the `{}` value.
|
|
@@ -100,7 +109,11 @@ type Includes<Value extends readonly any[], Item> =
|
|
|
100
109
|
@category Type Guard
|
|
101
110
|
@category Utilities
|
|
102
111
|
*/
|
|
103
|
-
export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends
|
|
112
|
+
export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <
|
|
113
|
+
G,
|
|
114
|
+
>() => G extends B ? 1 : 2
|
|
115
|
+
? true
|
|
116
|
+
: false;
|
|
104
117
|
/**
|
|
105
118
|
Represents an object with `unknown` value. You probably want this instead of `{}`.
|
|
106
119
|
|
|
@@ -227,14 +240,16 @@ type B = StaticPartOfArray<A>;
|
|
|
227
240
|
//=> [string, number, boolean]
|
|
228
241
|
```
|
|
229
242
|
*/
|
|
230
|
-
export type StaticPartOfArray<
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
243
|
+
export type StaticPartOfArray<
|
|
244
|
+
T extends UnknownArray,
|
|
245
|
+
Result extends UnknownArray = [],
|
|
246
|
+
> = T extends unknown
|
|
247
|
+
? number extends T['length']
|
|
248
|
+
? T extends readonly [infer U, ...infer V]
|
|
249
|
+
? StaticPartOfArray<V, [...Result, U]>
|
|
250
|
+
: Result
|
|
251
|
+
: T
|
|
252
|
+
: never; // Should never happen
|
|
238
253
|
/**
|
|
239
254
|
Returns the variable, non-fixed-length portion of the given array, excluding static-length parts.
|
|
240
255
|
|
|
@@ -245,12 +260,22 @@ type B = VariablePartOfArray<A>;
|
|
|
245
260
|
//=> string[]
|
|
246
261
|
```
|
|
247
262
|
*/
|
|
248
|
-
export type VariablePartOfArray<T extends UnknownArray> = T extends unknown
|
|
249
|
-
...StaticPartOfArray<T>,
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
export type StringDigit =
|
|
263
|
+
export type VariablePartOfArray<T extends UnknownArray> = T extends unknown
|
|
264
|
+
? T extends readonly [...StaticPartOfArray<T>, ...infer U]
|
|
265
|
+
? U
|
|
266
|
+
: []
|
|
267
|
+
: never; // Should never happen
|
|
268
|
+
export type StringDigit =
|
|
269
|
+
| '0'
|
|
270
|
+
| '1'
|
|
271
|
+
| '2'
|
|
272
|
+
| '3'
|
|
273
|
+
| '4'
|
|
274
|
+
| '5'
|
|
275
|
+
| '6'
|
|
276
|
+
| '7'
|
|
277
|
+
| '8'
|
|
278
|
+
| '9';
|
|
254
279
|
/**
|
|
255
280
|
Returns a boolean for whether the given type is `any`.
|
|
256
281
|
|
|
@@ -293,7 +318,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
|
|
|
293
318
|
*/
|
|
294
319
|
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
295
320
|
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
|
|
296
|
-
export type PositiveInfinity =
|
|
321
|
+
export type PositiveInfinity = 1e999;
|
|
297
322
|
/**
|
|
298
323
|
Matches the hidden `-Infinity` type.
|
|
299
324
|
|
|
@@ -305,7 +330,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
|
|
|
305
330
|
*/
|
|
306
331
|
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
307
332
|
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
|
|
308
|
-
export type NegativeInfinity = -
|
|
333
|
+
export type NegativeInfinity = -1e999;
|
|
309
334
|
/**
|
|
310
335
|
A negative `number`/`bigint` (`-∞ < x < 0`)
|
|
311
336
|
|
|
@@ -316,7 +341,11 @@ Use-case: Validating and documenting parameters.
|
|
|
316
341
|
|
|
317
342
|
@category Numeric
|
|
318
343
|
*/
|
|
319
|
-
export type Negative<T extends Numeric> = T extends Zero
|
|
344
|
+
export type Negative<T extends Numeric> = T extends Zero
|
|
345
|
+
? never
|
|
346
|
+
: `${T}` extends `-${string}`
|
|
347
|
+
? T
|
|
348
|
+
: never;
|
|
320
349
|
/**
|
|
321
350
|
Returns a boolean for whether the given number is a negative number.
|
|
322
351
|
|
|
@@ -332,7 +361,9 @@ type ShouldBeTrue = IsNegative<-1>;
|
|
|
332
361
|
|
|
333
362
|
@category Numeric
|
|
334
363
|
*/
|
|
335
|
-
export type IsNegative<T extends Numeric> = T extends Negative<T>
|
|
364
|
+
export type IsNegative<T extends Numeric> = T extends Negative<T>
|
|
365
|
+
? true
|
|
366
|
+
: false;
|
|
336
367
|
/**
|
|
337
368
|
Returns a boolean for whether two given types are both true.
|
|
338
369
|
|
|
@@ -353,11 +384,12 @@ And<true, false>;
|
|
|
353
384
|
*/
|
|
354
385
|
export type And<A extends boolean, B extends boolean> = [
|
|
355
386
|
A,
|
|
356
|
-
B
|
|
357
|
-
][number] extends true
|
|
358
|
-
|
|
359
|
-
IsEqual<B, false>
|
|
360
|
-
|
|
387
|
+
B,
|
|
388
|
+
][number] extends true
|
|
389
|
+
? true
|
|
390
|
+
: true extends [IsEqual<A, false>, IsEqual<B, false>][number]
|
|
391
|
+
? false
|
|
392
|
+
: never;
|
|
361
393
|
/**
|
|
362
394
|
Returns a boolean for whether either of two given types are true.
|
|
363
395
|
|
|
@@ -378,11 +410,12 @@ Or<false, false>;
|
|
|
378
410
|
*/
|
|
379
411
|
export type Or<A extends boolean, B extends boolean> = [
|
|
380
412
|
A,
|
|
381
|
-
B
|
|
382
|
-
][number] extends false
|
|
383
|
-
|
|
384
|
-
IsEqual<B, true>
|
|
385
|
-
|
|
413
|
+
B,
|
|
414
|
+
][number] extends false
|
|
415
|
+
? false
|
|
416
|
+
: true extends [IsEqual<A, true>, IsEqual<B, true>][number]
|
|
417
|
+
? true
|
|
418
|
+
: never;
|
|
386
419
|
/**
|
|
387
420
|
Returns a boolean for whether a given number is greater than another number.
|
|
388
421
|
|
|
@@ -400,32 +433,44 @@ GreaterThan<1, 5>;
|
|
|
400
433
|
//=> false
|
|
401
434
|
```
|
|
402
435
|
*/
|
|
403
|
-
export type GreaterThan<A extends number, B extends number> = number extends
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
]
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
] extends R
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
]
|
|
436
|
+
export type GreaterThan<A extends number, B extends number> = number extends
|
|
437
|
+
| A
|
|
438
|
+
| B
|
|
439
|
+
? never
|
|
440
|
+
: [
|
|
441
|
+
IsEqual<A, PositiveInfinity>,
|
|
442
|
+
IsEqual<A, NegativeInfinity>,
|
|
443
|
+
IsEqual<B, PositiveInfinity>,
|
|
444
|
+
IsEqual<B, NegativeInfinity>,
|
|
445
|
+
] extends infer R extends [boolean, boolean, boolean, boolean]
|
|
446
|
+
? Or<
|
|
447
|
+
And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
|
|
448
|
+
And<IsEqual<R[3], true>, IsEqual<R[1], false>>
|
|
449
|
+
> extends true
|
|
450
|
+
? true
|
|
451
|
+
: Or<
|
|
452
|
+
And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
|
|
453
|
+
And<IsEqual<R[2], true>, IsEqual<R[0], false>>
|
|
454
|
+
> extends true
|
|
455
|
+
? false
|
|
456
|
+
: true extends R[number]
|
|
457
|
+
? false
|
|
458
|
+
: [IsNegative<A>, IsNegative<B>] extends infer R extends [
|
|
459
|
+
boolean,
|
|
460
|
+
boolean,
|
|
461
|
+
]
|
|
462
|
+
? [true, false] extends R
|
|
463
|
+
? false
|
|
464
|
+
: [false, true] extends R
|
|
465
|
+
? true
|
|
466
|
+
: [false, false] extends R
|
|
467
|
+
? PositiveNumericStringGt<`${A}`, `${B}`>
|
|
468
|
+
: PositiveNumericStringGt<
|
|
469
|
+
`${NumberAbsolute<B>}`,
|
|
470
|
+
`${NumberAbsolute<A>}`
|
|
471
|
+
>
|
|
472
|
+
: never
|
|
473
|
+
: never;
|
|
429
474
|
/**
|
|
430
475
|
Returns a boolean for whether a given number is greater than or equal to another number.
|
|
431
476
|
|
|
@@ -443,7 +488,10 @@ GreaterThanOrEqual<1, 5>;
|
|
|
443
488
|
//=> false
|
|
444
489
|
```
|
|
445
490
|
*/
|
|
446
|
-
export type GreaterThanOrEqual<
|
|
491
|
+
export type GreaterThanOrEqual<
|
|
492
|
+
A extends number,
|
|
493
|
+
B extends number,
|
|
494
|
+
> = number extends A | B ? never : A extends B ? true : GreaterThan<A, B>;
|
|
447
495
|
/**
|
|
448
496
|
Returns a boolean for whether a given number is less than another number.
|
|
449
497
|
|
|
@@ -461,7 +509,11 @@ LessThan<1, 5>;
|
|
|
461
509
|
//=> true
|
|
462
510
|
```
|
|
463
511
|
*/
|
|
464
|
-
export type LessThan<A extends number, B extends number> = number extends A | B
|
|
512
|
+
export type LessThan<A extends number, B extends number> = number extends A | B
|
|
513
|
+
? never
|
|
514
|
+
: GreaterThanOrEqual<A, B> extends true
|
|
515
|
+
? false
|
|
516
|
+
: true;
|
|
465
517
|
/**
|
|
466
518
|
Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.
|
|
467
519
|
|
|
@@ -469,11 +521,11 @@ If `<Fill>` is not provided, it will default to `unknown`.
|
|
|
469
521
|
|
|
470
522
|
@link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
|
|
471
523
|
*/
|
|
472
|
-
export type BuildTuple<
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
]>;
|
|
524
|
+
export type BuildTuple<
|
|
525
|
+
L extends number,
|
|
526
|
+
Fill = unknown,
|
|
527
|
+
T extends readonly unknown[] = [],
|
|
528
|
+
> = T['length'] extends L ? T : BuildTuple<L, Fill, [...T, Fill]>;
|
|
477
529
|
/**
|
|
478
530
|
Returns the maximum value from a tuple of integers.
|
|
479
531
|
|
|
@@ -489,10 +541,16 @@ ArrayMax<[1, 2, 5, 3, 99, -1]>;
|
|
|
489
541
|
//=> 99
|
|
490
542
|
```
|
|
491
543
|
*/
|
|
492
|
-
export type TupleMax<
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
544
|
+
export type TupleMax<
|
|
545
|
+
A extends number[],
|
|
546
|
+
Result extends number = NegativeInfinity,
|
|
547
|
+
> = number extends A[number]
|
|
548
|
+
? never
|
|
549
|
+
: A extends [infer F extends number, ...infer R extends number[]]
|
|
550
|
+
? GreaterThan<F, Result> extends true
|
|
551
|
+
? TupleMax<R, F>
|
|
552
|
+
: TupleMax<R, Result>
|
|
553
|
+
: Result;
|
|
496
554
|
/**
|
|
497
555
|
Returns the minimum value from a tuple of integers.
|
|
498
556
|
|
|
@@ -508,10 +566,16 @@ ArrayMin<[1, 2, 5, 3, -5]>;
|
|
|
508
566
|
//=> -5
|
|
509
567
|
```
|
|
510
568
|
*/
|
|
511
|
-
export type TupleMin<
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
569
|
+
export type TupleMin<
|
|
570
|
+
A extends number[],
|
|
571
|
+
Result extends number = PositiveInfinity,
|
|
572
|
+
> = number extends A[number]
|
|
573
|
+
? never
|
|
574
|
+
: A extends [infer F extends number, ...infer R extends number[]]
|
|
575
|
+
? LessThan<F, Result> extends true
|
|
576
|
+
? TupleMin<R, F>
|
|
577
|
+
: TupleMin<R, Result>
|
|
578
|
+
: Result;
|
|
515
579
|
/**
|
|
516
580
|
Return a string representation of the given string or number.
|
|
517
581
|
|
|
@@ -546,7 +610,14 @@ type NegativeInfinity = StringToNumber<'-Infinity'>;
|
|
|
546
610
|
@category Numeric
|
|
547
611
|
@category Template literal
|
|
548
612
|
*/
|
|
549
|
-
export type StringToNumber<S extends string> =
|
|
613
|
+
export type StringToNumber<S extends string> =
|
|
614
|
+
S extends `${infer N extends number}`
|
|
615
|
+
? N
|
|
616
|
+
: S extends 'Infinity'
|
|
617
|
+
? PositiveInfinity
|
|
618
|
+
: S extends '-Infinity'
|
|
619
|
+
? NegativeInfinity
|
|
620
|
+
: never;
|
|
550
621
|
/**
|
|
551
622
|
Returns an array of the characters of the string.
|
|
552
623
|
|
|
@@ -561,11 +632,14 @@ StringToArray<string>;
|
|
|
561
632
|
|
|
562
633
|
@category String
|
|
563
634
|
*/
|
|
564
|
-
export type StringToArray<
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
635
|
+
export type StringToArray<
|
|
636
|
+
S extends string,
|
|
637
|
+
Result extends string[] = [],
|
|
638
|
+
> = string extends S
|
|
639
|
+
? never
|
|
640
|
+
: S extends `${infer F}${infer R}`
|
|
641
|
+
? StringToArray<R, [...Result, F]>
|
|
642
|
+
: Result;
|
|
569
643
|
/**
|
|
570
644
|
Returns the length of the given string.
|
|
571
645
|
|
|
@@ -581,7 +655,9 @@ StringLength<string>;
|
|
|
581
655
|
@category String
|
|
582
656
|
@category Template literal
|
|
583
657
|
*/
|
|
584
|
-
export type StringLength<S extends string> = string extends S
|
|
658
|
+
export type StringLength<S extends string> = string extends S
|
|
659
|
+
? never
|
|
660
|
+
: StringToArray<S>['length'];
|
|
585
661
|
/**
|
|
586
662
|
Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both numeric strings and have the same length.
|
|
587
663
|
|
|
@@ -594,8 +670,17 @@ SameLengthPositiveNumericStringGt<'10', '10'>;
|
|
|
594
670
|
//=> false
|
|
595
671
|
```
|
|
596
672
|
*/
|
|
597
|
-
export type SameLengthPositiveNumericStringGt<
|
|
598
|
-
|
|
673
|
+
export type SameLengthPositiveNumericStringGt<
|
|
674
|
+
A extends string,
|
|
675
|
+
B extends string,
|
|
676
|
+
> = A extends `${infer FirstA}${infer RestA}`
|
|
677
|
+
? B extends `${infer FirstB}${infer RestB}`
|
|
678
|
+
? FirstA extends FirstB
|
|
679
|
+
? SameLengthPositiveNumericStringGt<RestA, RestB>
|
|
680
|
+
: PositiveNumericCharacterGt<FirstA, FirstB>
|
|
681
|
+
: never
|
|
682
|
+
: false;
|
|
683
|
+
export type NumericString = '0123456789';
|
|
599
684
|
/**
|
|
600
685
|
Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
|
|
601
686
|
|
|
@@ -611,16 +696,21 @@ PositiveNumericStringGt<'1', '500'>;
|
|
|
611
696
|
//=> false
|
|
612
697
|
```
|
|
613
698
|
*/
|
|
614
|
-
export type PositiveNumericStringGt<
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
699
|
+
export type PositiveNumericStringGt<
|
|
700
|
+
A extends string,
|
|
701
|
+
B extends string,
|
|
702
|
+
> = A extends B
|
|
703
|
+
? false
|
|
704
|
+
: [
|
|
705
|
+
BuildTuple<StringLength<A>, 0>,
|
|
706
|
+
BuildTuple<StringLength<B>, 0>,
|
|
707
|
+
] extends infer R extends [readonly unknown[], readonly unknown[]]
|
|
708
|
+
? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]]
|
|
709
|
+
? 0 extends Remain['length']
|
|
710
|
+
? SameLengthPositiveNumericStringGt<A, B>
|
|
711
|
+
: true
|
|
712
|
+
: false
|
|
713
|
+
: never;
|
|
624
714
|
/**
|
|
625
715
|
Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
|
|
626
716
|
|
|
@@ -633,7 +723,16 @@ PositiveNumericCharacterGt<'1', '1'>;
|
|
|
633
723
|
//=> false
|
|
634
724
|
```
|
|
635
725
|
*/
|
|
636
|
-
export type PositiveNumericCharacterGt<
|
|
726
|
+
export type PositiveNumericCharacterGt<
|
|
727
|
+
A extends string,
|
|
728
|
+
B extends string,
|
|
729
|
+
> = NumericString extends `${infer HeadA}${A}${infer TailA}`
|
|
730
|
+
? NumericString extends `${infer HeadB}${B}${infer TailB}`
|
|
731
|
+
? HeadA extends `${HeadB}${infer _}${infer __}`
|
|
732
|
+
? true
|
|
733
|
+
: false
|
|
734
|
+
: never
|
|
735
|
+
: never;
|
|
637
736
|
/**
|
|
638
737
|
Returns the absolute value of a given value.
|
|
639
738
|
|
|
@@ -649,7 +748,10 @@ NumberAbsolute<NegativeInfinity>
|
|
|
649
748
|
//=> PositiveInfinity
|
|
650
749
|
```
|
|
651
750
|
*/
|
|
652
|
-
export type NumberAbsolute<N extends number> =
|
|
751
|
+
export type NumberAbsolute<N extends number> =
|
|
752
|
+
`${N}` extends `-${infer StringPositiveN}`
|
|
753
|
+
? StringToNumber<StringPositiveN>
|
|
754
|
+
: N;
|
|
653
755
|
/**
|
|
654
756
|
Check whether the given type is a number or a number string.
|
|
655
757
|
|
|
@@ -669,7 +771,13 @@ type C = IsNumberLike<1>;
|
|
|
669
771
|
type D = IsNumberLike<'a'>;
|
|
670
772
|
//=> false
|
|
671
773
|
*/
|
|
672
|
-
export type IsNumberLike<N> = N extends number
|
|
774
|
+
export type IsNumberLike<N> = N extends number
|
|
775
|
+
? true
|
|
776
|
+
: N extends `${number}`
|
|
777
|
+
? true
|
|
778
|
+
: N extends `${number}.${number}`
|
|
779
|
+
? true
|
|
780
|
+
: false;
|
|
673
781
|
/**
|
|
674
782
|
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
675
783
|
*/
|
|
@@ -677,7 +785,12 @@ export type BuiltIns = Primitive | void | Date | RegExp;
|
|
|
677
785
|
/**
|
|
678
786
|
Matches non-recursive types.
|
|
679
787
|
*/
|
|
680
|
-
export type NonRecursiveType =
|
|
788
|
+
export type NonRecursiveType =
|
|
789
|
+
| BuiltIns
|
|
790
|
+
| Function
|
|
791
|
+
| (new (
|
|
792
|
+
...arguments_: any[]
|
|
793
|
+
) => unknown);
|
|
681
794
|
/**
|
|
682
795
|
Returns the sum of two numbers.
|
|
683
796
|
|
|
@@ -709,35 +822,45 @@ Sum<PositiveInfinity, NegativeInfinity>;
|
|
|
709
822
|
@category Numeric
|
|
710
823
|
*/
|
|
711
824
|
// TODO: Support big integer and negative number.
|
|
712
|
-
export type Sum<A extends number, B extends number> = number extends A | B
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
825
|
+
export type Sum<A extends number, B extends number> = number extends A | B
|
|
826
|
+
? number
|
|
827
|
+
: [
|
|
828
|
+
IsEqual<A, PositiveInfinity>,
|
|
829
|
+
IsEqual<A, NegativeInfinity>,
|
|
830
|
+
IsEqual<B, PositiveInfinity>,
|
|
831
|
+
IsEqual<B, NegativeInfinity>,
|
|
832
|
+
] extends infer R extends [boolean, boolean, boolean, boolean]
|
|
833
|
+
? Or<
|
|
834
|
+
And<IsEqual<R[0], true>, IsEqual<R[3], false>>,
|
|
835
|
+
And<IsEqual<R[2], true>, IsEqual<R[1], false>>
|
|
836
|
+
> extends true
|
|
837
|
+
? PositiveInfinity
|
|
838
|
+
: Or<
|
|
839
|
+
And<IsEqual<R[1], true>, IsEqual<R[2], false>>,
|
|
840
|
+
And<IsEqual<R[3], true>, IsEqual<R[0], false>>
|
|
841
|
+
> extends true
|
|
842
|
+
? NegativeInfinity
|
|
843
|
+
: true extends R[number]
|
|
844
|
+
? number
|
|
845
|
+
: ([IsNegative<A>, IsNegative<B>] extends infer R
|
|
846
|
+
? [false, false] extends R
|
|
847
|
+
? [...BuildTuple<A>, ...BuildTuple<B>]['length']
|
|
848
|
+
: [true, true] extends R
|
|
849
|
+
? number
|
|
850
|
+
: TupleMax<
|
|
851
|
+
[NumberAbsolute<A>, NumberAbsolute<B>]
|
|
852
|
+
> extends infer Max_
|
|
853
|
+
? TupleMin<
|
|
854
|
+
[NumberAbsolute<A>, NumberAbsolute<B>]
|
|
855
|
+
> extends infer Min_ extends number
|
|
856
|
+
? Max_ extends A | B
|
|
857
|
+
? Subtract<Max_, Min_>
|
|
858
|
+
: number
|
|
859
|
+
: never
|
|
860
|
+
: never
|
|
861
|
+
: never) &
|
|
862
|
+
number
|
|
863
|
+
: never;
|
|
741
864
|
/**
|
|
742
865
|
Returns the difference between two numbers.
|
|
743
866
|
|
|
@@ -768,29 +891,40 @@ Subtract<PositiveInfinity, PositiveInfinity>;
|
|
|
768
891
|
@category Numeric
|
|
769
892
|
*/
|
|
770
893
|
// TODO: Support big integer and negative number.
|
|
771
|
-
export type Subtract<A extends number, B extends number> = number extends A | B
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
894
|
+
export type Subtract<A extends number, B extends number> = number extends A | B
|
|
895
|
+
? number
|
|
896
|
+
: [
|
|
897
|
+
IsEqual<A, PositiveInfinity>,
|
|
898
|
+
IsEqual<A, NegativeInfinity>,
|
|
899
|
+
IsEqual<B, PositiveInfinity>,
|
|
900
|
+
IsEqual<B, NegativeInfinity>,
|
|
901
|
+
] extends infer R extends [boolean, boolean, boolean, boolean]
|
|
902
|
+
? Or<
|
|
903
|
+
And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
|
|
904
|
+
And<IsEqual<R[3], true>, IsEqual<R[1], false>>
|
|
905
|
+
> extends true
|
|
906
|
+
? PositiveInfinity
|
|
907
|
+
: Or<
|
|
908
|
+
And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
|
|
909
|
+
And<IsEqual<R[2], true>, IsEqual<R[0], false>>
|
|
910
|
+
> extends true
|
|
911
|
+
? NegativeInfinity
|
|
912
|
+
: true extends R[number]
|
|
913
|
+
? number
|
|
914
|
+
: [IsNegative<A>, IsNegative<B>] extends infer R
|
|
915
|
+
? [false, false] extends R
|
|
916
|
+
? BuildTuple<A> extends infer R
|
|
917
|
+
? R extends [...BuildTuple<B>, ...infer R]
|
|
918
|
+
? R['length']
|
|
919
|
+
: number
|
|
920
|
+
: never
|
|
921
|
+
: LessThan<A, B> extends true
|
|
922
|
+
? number
|
|
923
|
+
: [false, true] extends R
|
|
924
|
+
? Sum<A, NumberAbsolute<B>>
|
|
925
|
+
: Subtract<NumberAbsolute<B>, NumberAbsolute<A>>
|
|
926
|
+
: never
|
|
927
|
+
: never;
|
|
794
928
|
/**
|
|
795
929
|
Paths options.
|
|
796
930
|
|
|
@@ -881,28 +1015,85 @@ open('listB.1'); // TypeError. Because listB only has one element.
|
|
|
881
1015
|
@category Object
|
|
882
1016
|
@category Array
|
|
883
1017
|
*/
|
|
884
|
-
export type Paths<T, Options extends PathsOptions = {}> = _Paths<
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
]
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
1018
|
+
export type Paths<T, Options extends PathsOptions = {}> = _Paths<
|
|
1019
|
+
T,
|
|
1020
|
+
{
|
|
1021
|
+
// Set default maxRecursionDepth to 10
|
|
1022
|
+
maxRecursionDepth: Options['maxRecursionDepth'] extends number
|
|
1023
|
+
? Options['maxRecursionDepth']
|
|
1024
|
+
: DefaultPathsOptions['maxRecursionDepth'];
|
|
1025
|
+
// Set default bracketNotation to false
|
|
1026
|
+
bracketNotation: Options['bracketNotation'] extends boolean
|
|
1027
|
+
? Options['bracketNotation']
|
|
1028
|
+
: DefaultPathsOptions['bracketNotation'];
|
|
1029
|
+
}
|
|
1030
|
+
>;
|
|
1031
|
+
export type _Paths<T, Options extends Required<PathsOptions>> = T extends
|
|
1032
|
+
| NonRecursiveType
|
|
1033
|
+
| ReadonlyMap<unknown, unknown>
|
|
1034
|
+
| ReadonlySet<unknown>
|
|
1035
|
+
? never
|
|
1036
|
+
: IsAny<T> extends true
|
|
1037
|
+
? never
|
|
1038
|
+
: T extends UnknownArray
|
|
1039
|
+
? number extends T['length']
|
|
1040
|
+
?
|
|
1041
|
+
| InternalPaths<StaticPartOfArray<T>, Options>
|
|
1042
|
+
| InternalPaths<Array<VariablePartOfArray<T>[number]>, Options>
|
|
1043
|
+
: InternalPaths<T, Options>
|
|
1044
|
+
: T extends object
|
|
1045
|
+
? InternalPaths<T, Options>
|
|
1046
|
+
: never;
|
|
1047
|
+
export type InternalPaths<
|
|
1048
|
+
T,
|
|
1049
|
+
Options extends Required<PathsOptions>,
|
|
1050
|
+
> = Options['maxRecursionDepth'] extends infer MaxDepth extends number
|
|
1051
|
+
? Required<T> extends infer T
|
|
1052
|
+
? T extends EmptyObject | readonly []
|
|
1053
|
+
? never
|
|
1054
|
+
: {
|
|
1055
|
+
[Key in keyof T]: Key extends string | number // Limit `Key` to string or number.
|
|
1056
|
+
? (
|
|
1057
|
+
Options['bracketNotation'] extends true
|
|
1058
|
+
? IsNumberLike<Key> extends true
|
|
1059
|
+
? `[${Key}]`
|
|
1060
|
+
: Key | ToString<Key>
|
|
1061
|
+
: never | Options['bracketNotation'] extends false
|
|
1062
|
+
? Key | ToString<Key>
|
|
1063
|
+
: never
|
|
1064
|
+
) extends infer TranformedKey extends string | number
|
|
1065
|
+
? // 1. If style is 'a[0].b' and 'Key' is a numberlike value like 3 or '3', transform 'Key' to `[${Key}]`, else to `${Key}` | Key
|
|
1066
|
+
// 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
|
|
1067
|
+
| TranformedKey
|
|
1068
|
+
// Recursively generate paths for the current key
|
|
1069
|
+
| (GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
|
|
1070
|
+
? _Paths<
|
|
1071
|
+
T[Key],
|
|
1072
|
+
{
|
|
1073
|
+
bracketNotation: Options['bracketNotation'];
|
|
1074
|
+
maxRecursionDepth: Subtract<MaxDepth, 1>;
|
|
1075
|
+
}
|
|
1076
|
+
> extends infer SubPath
|
|
1077
|
+
? SubPath extends string | number
|
|
1078
|
+
?
|
|
1079
|
+
| (Options['bracketNotation'] extends true
|
|
1080
|
+
? SubPath extends
|
|
1081
|
+
| `[${any}]`
|
|
1082
|
+
| `[${any}]${string}`
|
|
1083
|
+
? `${TranformedKey}${SubPath}` // If next node is number key like `[3]`, no need to add `.` before it.
|
|
1084
|
+
: `${TranformedKey}.${SubPath}`
|
|
1085
|
+
: never)
|
|
1086
|
+
| (Options['bracketNotation'] extends false
|
|
1087
|
+
? `${TranformedKey}.${SubPath}`
|
|
1088
|
+
: never)
|
|
1089
|
+
: never
|
|
1090
|
+
: never
|
|
1091
|
+
: never)
|
|
1092
|
+
: never
|
|
1093
|
+
: never;
|
|
1094
|
+
}[keyof T & (T extends UnknownArray ? number : unknown)]
|
|
1095
|
+
: never
|
|
1096
|
+
: never;
|
|
906
1097
|
export type LiteralStringUnion<T> = LiteralUnion<T, string>;
|
|
907
1098
|
/**
|
|
908
1099
|
Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
@@ -933,7 +1124,9 @@ const pet: Pet2 = '';
|
|
|
933
1124
|
|
|
934
1125
|
@category Type
|
|
935
1126
|
*/
|
|
936
|
-
export type LiteralUnion<LiteralType, BaseType extends Primitive> =
|
|
1127
|
+
export type LiteralUnion<LiteralType, BaseType extends Primitive> =
|
|
1128
|
+
| LiteralType
|
|
1129
|
+
| (BaseType & Record<never, never>);
|
|
937
1130
|
/**
|
|
938
1131
|
Get keys of the given type as strings.
|
|
939
1132
|
|
|
@@ -958,7 +1151,8 @@ type StringKeysOfFoo = StringKeyOf<Foo>;
|
|
|
958
1151
|
|
|
959
1152
|
@category Object
|
|
960
1153
|
*/
|
|
961
|
-
export type StringKeyOf<BaseType> =
|
|
1154
|
+
export type StringKeyOf<BaseType> =
|
|
1155
|
+
`${Extract<keyof BaseType, string | number>}`;
|
|
962
1156
|
/**
|
|
963
1157
|
Represents an array of strings split using a given character or character set.
|
|
964
1158
|
|
|
@@ -980,13 +1174,14 @@ array = split(items, ',');
|
|
|
980
1174
|
@category String
|
|
981
1175
|
@category Template literal
|
|
982
1176
|
*/
|
|
983
|
-
export type Split<
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
S
|
|
989
|
-
]
|
|
1177
|
+
export type Split<
|
|
1178
|
+
S extends string,
|
|
1179
|
+
Delimiter extends string,
|
|
1180
|
+
> = S extends `${infer Head}${Delimiter}${infer Tail}`
|
|
1181
|
+
? [Head, ...Split<Tail, Delimiter>]
|
|
1182
|
+
: S extends Delimiter
|
|
1183
|
+
? []
|
|
1184
|
+
: [S];
|
|
990
1185
|
export type GetOptions = {
|
|
991
1186
|
/**
|
|
992
1187
|
Include `undefined` in the return type when accessing properties.
|
|
@@ -1000,24 +1195,41 @@ export type GetOptions = {
|
|
|
1000
1195
|
/**
|
|
1001
1196
|
Like the `Get` type but receives an array of strings as a path parameter.
|
|
1002
1197
|
*/
|
|
1003
|
-
export type GetWithPath<
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1198
|
+
export type GetWithPath<
|
|
1199
|
+
BaseType,
|
|
1200
|
+
Keys,
|
|
1201
|
+
Options extends GetOptions = {},
|
|
1202
|
+
> = Keys extends readonly []
|
|
1203
|
+
? BaseType
|
|
1204
|
+
: Keys extends readonly [infer Head, ...infer Tail]
|
|
1205
|
+
? GetWithPath<
|
|
1206
|
+
PropertyOf<BaseType, Extract<Head, string>, Options>,
|
|
1207
|
+
Extract<Tail, string[]>,
|
|
1208
|
+
Options
|
|
1209
|
+
>
|
|
1210
|
+
: never;
|
|
1008
1211
|
/**
|
|
1009
1212
|
Adds `undefined` to `Type` if `strict` is enabled.
|
|
1010
1213
|
*/
|
|
1011
|
-
export type Strictify<
|
|
1214
|
+
export type Strictify<
|
|
1215
|
+
Type,
|
|
1216
|
+
Options extends GetOptions,
|
|
1217
|
+
> = Options['strict'] extends false ? Type : Type | undefined;
|
|
1012
1218
|
/**
|
|
1013
1219
|
If `Options['strict']` is `true`, includes `undefined` in the returned type when accessing properties on `Record<string, any>`.
|
|
1014
1220
|
|
|
1015
1221
|
Known limitations:
|
|
1016
1222
|
- Does not include `undefined` in the type on object types with an index signature (for example, `{a: string; [key: string]: string}`).
|
|
1017
1223
|
*/
|
|
1018
|
-
export type StrictPropertyOf<
|
|
1019
|
-
|
|
1020
|
-
|
|
1224
|
+
export type StrictPropertyOf<
|
|
1225
|
+
BaseType,
|
|
1226
|
+
Key extends keyof BaseType,
|
|
1227
|
+
Options extends GetOptions,
|
|
1228
|
+
> = Record<string, any> extends BaseType
|
|
1229
|
+
? string extends keyof BaseType
|
|
1230
|
+
? Strictify<BaseType[Key], Options> // Record<string, any>
|
|
1231
|
+
: BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
|
|
1232
|
+
: BaseType[Key];
|
|
1021
1233
|
/**
|
|
1022
1234
|
Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
|
|
1023
1235
|
|
|
@@ -1030,11 +1242,18 @@ ToPath<'foo[0].bar.baz'>
|
|
|
1030
1242
|
//=> ['foo', '0', 'bar', 'baz']
|
|
1031
1243
|
```
|
|
1032
1244
|
*/
|
|
1033
|
-
export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>,
|
|
1245
|
+
export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.'>;
|
|
1034
1246
|
/**
|
|
1035
1247
|
Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
|
|
1036
1248
|
*/
|
|
1037
|
-
export type FixPathSquareBrackets<Path extends string> =
|
|
1249
|
+
export type FixPathSquareBrackets<Path extends string> =
|
|
1250
|
+
Path extends `[${infer Head}]${infer Tail}`
|
|
1251
|
+
? Tail extends `[${string}`
|
|
1252
|
+
? `${Head}.${FixPathSquareBrackets<Tail>}`
|
|
1253
|
+
: `${Head}${FixPathSquareBrackets<Tail>}`
|
|
1254
|
+
: Path extends `${infer Head}[${infer Middle}]${infer Tail}`
|
|
1255
|
+
? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}`
|
|
1256
|
+
: Path;
|
|
1038
1257
|
/**
|
|
1039
1258
|
Returns true if `LongString` is made up out of `Substring` repeated 0 or more times.
|
|
1040
1259
|
|
|
@@ -1046,7 +1265,14 @@ ConsistsOnlyOf<'aBa', 'a'> //=> false
|
|
|
1046
1265
|
ConsistsOnlyOf<'', 'a'> //=> true
|
|
1047
1266
|
```
|
|
1048
1267
|
*/
|
|
1049
|
-
export type ConsistsOnlyOf<
|
|
1268
|
+
export type ConsistsOnlyOf<
|
|
1269
|
+
LongString extends string,
|
|
1270
|
+
Substring extends string,
|
|
1271
|
+
> = LongString extends ''
|
|
1272
|
+
? true
|
|
1273
|
+
: LongString extends `${Substring}${infer Tail}`
|
|
1274
|
+
? ConsistsOnlyOf<Tail, Substring>
|
|
1275
|
+
: false;
|
|
1050
1276
|
/**
|
|
1051
1277
|
Convert a type which may have number keys to one with string keys, making it possible to index using strings retrieved from template types.
|
|
1052
1278
|
|
|
@@ -1067,11 +1293,11 @@ export type WithStringKeys<BaseType> = {
|
|
|
1067
1293
|
/**
|
|
1068
1294
|
Perform a `T[U]` operation if `T` supports indexing.
|
|
1069
1295
|
*/
|
|
1070
|
-
export type UncheckedIndex<T, U extends string | number> = [
|
|
1071
|
-
|
|
1072
|
-
]
|
|
1073
|
-
|
|
1074
|
-
|
|
1296
|
+
export type UncheckedIndex<T, U extends string | number> = [T] extends [
|
|
1297
|
+
Record<string | number, any>,
|
|
1298
|
+
]
|
|
1299
|
+
? T[U]
|
|
1300
|
+
: never;
|
|
1075
1301
|
/**
|
|
1076
1302
|
Get a property of an object or array. Works when indexing arrays using number-literal-strings, for example, `PropertyOf<number[], '0'> = number`, and when indexing objects with number keys.
|
|
1077
1303
|
|
|
@@ -1079,15 +1305,26 @@ Note:
|
|
|
1079
1305
|
- Returns `unknown` if `Key` is not a property of `BaseType`, since TypeScript uses structural typing, and it cannot be guaranteed that extra properties unknown to the type system will exist at runtime.
|
|
1080
1306
|
- Returns `undefined` from nullish values, to match the behaviour of most deep-key libraries like `lodash`, `dot-prop`, etc.
|
|
1081
1307
|
*/
|
|
1082
|
-
export type PropertyOf<
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1308
|
+
export type PropertyOf<
|
|
1309
|
+
BaseType,
|
|
1310
|
+
Key extends string,
|
|
1311
|
+
Options extends GetOptions = {},
|
|
1312
|
+
> = BaseType extends null | undefined
|
|
1313
|
+
? undefined
|
|
1314
|
+
: Key extends keyof BaseType
|
|
1315
|
+
? StrictPropertyOf<BaseType, Key, Options>
|
|
1316
|
+
: BaseType extends readonly [] | readonly [unknown, ...unknown[]]
|
|
1317
|
+
? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
|
|
1318
|
+
: BaseType extends {
|
|
1319
|
+
[n: number]: infer Item;
|
|
1320
|
+
length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
|
|
1321
|
+
}
|
|
1322
|
+
? ConsistsOnlyOf<Key, StringDigit> extends true
|
|
1323
|
+
? Strictify<Item, Options>
|
|
1324
|
+
: unknown
|
|
1325
|
+
: Key extends keyof WithStringKeys<BaseType>
|
|
1326
|
+
? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options>
|
|
1327
|
+
: unknown;
|
|
1091
1328
|
// This works by first splitting the path based on `.` and `[...]` characters into a tuple of string keys. Then it recursively uses the head key to get the next property of the current object, until there are no keys left. Number keys extract the item type from arrays, or are converted to strings to extract types from tuples and dictionaries with number keys.
|
|
1092
1329
|
/**
|
|
1093
1330
|
Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
|
|
@@ -1135,22 +1372,39 @@ Get<Record<string, string>, 'foo', {strict: true}> // => string
|
|
|
1135
1372
|
@category Array
|
|
1136
1373
|
@category Template literal
|
|
1137
1374
|
*/
|
|
1138
|
-
export type Get<
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1375
|
+
export type Get<
|
|
1376
|
+
BaseType,
|
|
1377
|
+
Path extends
|
|
1378
|
+
| readonly string[]
|
|
1379
|
+
| LiteralStringUnion<
|
|
1380
|
+
ToString<
|
|
1381
|
+
| Paths<
|
|
1382
|
+
BaseType,
|
|
1383
|
+
{
|
|
1384
|
+
bracketNotation: false;
|
|
1385
|
+
}
|
|
1386
|
+
>
|
|
1387
|
+
| Paths<
|
|
1388
|
+
BaseType,
|
|
1389
|
+
{
|
|
1390
|
+
bracketNotation: true;
|
|
1391
|
+
}
|
|
1392
|
+
>
|
|
1393
|
+
>
|
|
1394
|
+
>,
|
|
1395
|
+
Options extends GetOptions = {},
|
|
1396
|
+
> = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, Options>;
|
|
1143
1397
|
export type ArrayOrPlainObject = UnknownArray | UnknownRecord;
|
|
1144
1398
|
export type PlainObject = UnknownRecord;
|
|
1145
1399
|
/**
|
|
1146
1400
|
* Clone any kind of value _(deeply, if needed)_
|
|
1147
1401
|
*/
|
|
1148
|
-
export declare function clone(value:
|
|
1402
|
+
export declare function clone<Value>(value: Value): Value;
|
|
1149
1403
|
/**
|
|
1150
1404
|
* Compare two values _(for sorting purposes)_
|
|
1151
1405
|
*/
|
|
1152
1406
|
export declare function compare(first: unknown, second: unknown): number;
|
|
1153
|
-
export type DiffType =
|
|
1407
|
+
export type DiffType = 'full' | 'none' | 'partial';
|
|
1154
1408
|
export type DiffResult<First, Second = First> = {
|
|
1155
1409
|
original: DiffValue<First, Second>;
|
|
1156
1410
|
type: DiffType;
|
|
@@ -1170,11 +1424,18 @@ export type DiffValue<First = unknown, Second = First> = {
|
|
|
1170
1424
|
* - `partial` if the values are partially different
|
|
1171
1425
|
* - `values` holds the differences with dot notation keys
|
|
1172
1426
|
*/
|
|
1173
|
-
export declare function diff<First, Second = First>(
|
|
1427
|
+
export declare function diff<First, Second = First>(
|
|
1428
|
+
first: First,
|
|
1429
|
+
second: Second,
|
|
1430
|
+
): DiffResult<First, Second>;
|
|
1174
1431
|
/**
|
|
1175
1432
|
* Are two strings equal? _(Case-sensitive by default)_
|
|
1176
1433
|
*/
|
|
1177
|
-
export declare function equal(
|
|
1434
|
+
export declare function equal(
|
|
1435
|
+
first: string,
|
|
1436
|
+
second: string,
|
|
1437
|
+
ignoreCase?: boolean,
|
|
1438
|
+
): boolean;
|
|
1178
1439
|
/**
|
|
1179
1440
|
* Are two values equal? _(Does a deep comparison, if needed)_
|
|
1180
1441
|
*/
|
|
@@ -1184,14 +1445,21 @@ export declare function equal(first: unknown, second: unknown): boolean;
|
|
|
1184
1445
|
* - You can retrieve a nested value by using dot notation, e.g., `foo.bar.baz`
|
|
1185
1446
|
* - Returns `undefined` if the value is not found
|
|
1186
1447
|
*/
|
|
1187
|
-
export declare function getValue<
|
|
1448
|
+
export declare function getValue<
|
|
1449
|
+
Data extends ArrayOrPlainObject,
|
|
1450
|
+
Path extends Paths<Data>,
|
|
1451
|
+
>(data: Data, path: Path): Get<Data, ToString<Path>>;
|
|
1188
1452
|
/**
|
|
1189
1453
|
* - Get the value from an object using an unknown path
|
|
1190
1454
|
* - You can retrieve a nested value by using dot notation, e.g., `foo.bar.baz`
|
|
1191
1455
|
* - If `ignoreCase` is `true`, path matching will be case-insensitive
|
|
1192
1456
|
* - Returns `undefined` if the value is not found
|
|
1193
1457
|
*/
|
|
1194
|
-
export declare function getValue<Data extends
|
|
1458
|
+
export declare function getValue<Data extends ArrayOrPlainObject>(
|
|
1459
|
+
data: Data,
|
|
1460
|
+
path: string,
|
|
1461
|
+
ignoreCase?: boolean,
|
|
1462
|
+
): unknown;
|
|
1195
1463
|
export type MergeOptions = {
|
|
1196
1464
|
/**
|
|
1197
1465
|
* - Skip nullable values when merging arrays?
|
|
@@ -1202,14 +1470,20 @@ export type MergeOptions = {
|
|
|
1202
1470
|
/**
|
|
1203
1471
|
* Merge multiple arrays or objects into a single one
|
|
1204
1472
|
*/
|
|
1205
|
-
export declare function merge<Model extends ArrayOrPlainObject>(
|
|
1473
|
+
export declare function merge<Model extends ArrayOrPlainObject>(
|
|
1474
|
+
values: Model[],
|
|
1475
|
+
options?: Partial<MergeOptions>,
|
|
1476
|
+
): Model;
|
|
1206
1477
|
/**
|
|
1207
1478
|
* - Set the value in an object using a known path
|
|
1208
1479
|
* - You can set a nested value by using dot notation, e.g., `foo.bar.baz`
|
|
1209
1480
|
* - If a part of the path does not exist, it will be created, either as an array or a generic object, depending on the path
|
|
1210
1481
|
* - Returns the original object
|
|
1211
1482
|
*/
|
|
1212
|
-
export declare function setValue<
|
|
1483
|
+
export declare function setValue<
|
|
1484
|
+
Data extends ArrayOrPlainObject,
|
|
1485
|
+
Path extends Paths<Data>,
|
|
1486
|
+
>(data: Data, path: Path, value: unknown): Data;
|
|
1213
1487
|
/**
|
|
1214
1488
|
* - Set the value in an object using an unknown path
|
|
1215
1489
|
* - You can set a nested value by using dot notation, e.g., `foo.bar.baz`
|
|
@@ -1217,24 +1491,41 @@ export declare function setValue<Data extends PlainObject, Path extends Paths<Da
|
|
|
1217
1491
|
* - If `ignoreCase` is `true`, path matching will be case-insensitive
|
|
1218
1492
|
* - Returns the original object
|
|
1219
1493
|
*/
|
|
1220
|
-
export declare function setValue<Data extends
|
|
1494
|
+
export declare function setValue<Data extends ArrayOrPlainObject>(
|
|
1495
|
+
data: Data,
|
|
1496
|
+
path: string,
|
|
1497
|
+
value: unknown,
|
|
1498
|
+
ignoreCase?: boolean,
|
|
1499
|
+
): Data;
|
|
1221
1500
|
export type Smushed<Value> = Simplify<{
|
|
1222
1501
|
[Key in Paths<Value>]: Get<Value, ToString<Key>>;
|
|
1223
1502
|
}>;
|
|
1224
1503
|
/**
|
|
1225
1504
|
* Smush an object into a flat object that uses dot notation keys
|
|
1226
1505
|
*/
|
|
1227
|
-
export declare function smush<Value extends PlainObject>(
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1506
|
+
export declare function smush<Value extends PlainObject>(
|
|
1507
|
+
value: Value,
|
|
1508
|
+
): Smushed<Value>;
|
|
1509
|
+
export type Unsmushed<Value extends PlainObject> = Simplify<
|
|
1510
|
+
Omit<
|
|
1511
|
+
{
|
|
1512
|
+
[Key in KeysOfUnion<Value>]: Value[Key];
|
|
1513
|
+
},
|
|
1514
|
+
`${string}.${string}`
|
|
1515
|
+
>
|
|
1516
|
+
>;
|
|
1231
1517
|
/**
|
|
1232
1518
|
* Unsmush a smushed object _(turning dot notation keys into nested keys)_
|
|
1233
1519
|
*/
|
|
1234
|
-
export declare function unsmush<Value extends PlainObject>(
|
|
1520
|
+
export declare function unsmush<Value extends PlainObject>(
|
|
1521
|
+
value: Value,
|
|
1522
|
+
): Unsmushed<Value>;
|
|
1235
1523
|
/**
|
|
1236
1524
|
* Create a new object with only the specified keys
|
|
1237
1525
|
*/
|
|
1238
|
-
export declare function partial<
|
|
1526
|
+
export declare function partial<
|
|
1527
|
+
Value extends PlainObject,
|
|
1528
|
+
Key extends keyof Value,
|
|
1529
|
+
>(value: Value, keys: Key[]): Pick<Value, Key>;
|
|
1239
1530
|
|
|
1240
1531
|
export {};
|