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