@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.
Files changed (59) hide show
  1. package/dist/js/array/count.cjs +1 -8
  2. package/dist/js/array/count.js +1 -8
  3. package/dist/js/array/exists.cjs +1 -8
  4. package/dist/js/array/exists.js +1 -8
  5. package/dist/js/array/filter.cjs +1 -8
  6. package/dist/js/array/filter.js +1 -8
  7. package/dist/js/array/find.cjs +1 -8
  8. package/dist/js/array/find.js +1 -8
  9. package/dist/js/array/index-of.cjs +1 -8
  10. package/dist/js/array/index-of.js +1 -8
  11. package/dist/js/array/unique.cjs +1 -1
  12. package/dist/js/array/unique.js +1 -1
  13. package/dist/js/internal/array/find.cjs +12 -2
  14. package/dist/js/internal/array/find.js +12 -2
  15. package/package.json +11 -4
  16. package/src/js/array/count.ts +7 -20
  17. package/src/js/array/exists.ts +7 -22
  18. package/src/js/array/filter.ts +7 -20
  19. package/src/js/array/find.ts +7 -20
  20. package/src/js/array/group-by.ts +19 -21
  21. package/src/js/array/index-of.ts +7 -20
  22. package/src/js/array/models.ts +2 -16
  23. package/src/js/array/sort.ts +3 -7
  24. package/src/js/array/to-map.ts +19 -21
  25. package/src/js/array/to-record.ts +17 -19
  26. package/src/js/array/unique.ts +8 -8
  27. package/src/js/internal/array/callbacks.ts +4 -4
  28. package/src/js/internal/array/find.ts +29 -6
  29. package/types/array/count.d.cts +2 -5
  30. package/types/array/count.d.ts +3 -3
  31. package/types/array/exists.d.cts +2 -5
  32. package/types/array/exists.d.ts +3 -3
  33. package/types/array/filter.d.cts +2 -5
  34. package/types/array/filter.d.ts +3 -3
  35. package/types/array/find.d.cts +2 -5
  36. package/types/array/find.d.ts +3 -3
  37. package/types/array/group-by.d.cts +8 -11
  38. package/types/array/group-by.d.ts +10 -11
  39. package/types/array/index-of.d.cts +2 -5
  40. package/types/array/index-of.d.ts +3 -3
  41. package/types/array/index.d.cts +43 -48
  42. package/types/array/models.d.cts +2 -7
  43. package/types/array/models.d.ts +2 -7
  44. package/types/array/sort.d.cts +3 -4
  45. package/types/array/sort.d.ts +3 -3
  46. package/types/array/to-map.d.cts +8 -11
  47. package/types/array/to-map.d.ts +9 -10
  48. package/types/array/to-record.d.cts +8 -11
  49. package/types/array/to-record.d.ts +9 -10
  50. package/types/array/unique.d.cts +3 -5
  51. package/types/array/unique.d.ts +4 -4
  52. package/types/index.d.cts +321 -1019
  53. package/types/internal/array/find.d.cts +2 -2
  54. package/types/internal/array/find.d.ts +2 -2
  55. package/types/models.d.cts +210 -467
  56. package/types/value/get.d.cts +210 -469
  57. package/types/value/index.d.cts +223 -514
  58. package/types/value/set.d.cts +169 -356
  59. package/types/value/smush.d.cts +209 -463
@@ -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
  declare const emptyObjectSymbol: unique symbol;
17
10
  /**
18
11
  Represents a strictly empty plain object, the `{}` value.
@@ -69,11 +62,7 @@ type Includes<Value extends readonly any[], Item> =
69
62
  @category Type Guard
70
63
  @category Utilities
71
64
  */
72
- export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <
73
- G,
74
- >() => G extends B ? 1 : 2
75
- ? true
76
- : false;
65
+ export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends (<G>() => G extends B ? 1 : 2) ? true : false;
77
66
  /**
78
67
  Represents an object with `unknown` value. You probably want this instead of `{}`.
79
68
 
@@ -200,16 +189,14 @@ type B = StaticPartOfArray<A>;
200
189
  //=> [string, number, boolean]
201
190
  ```
202
191
  */
203
- export type StaticPartOfArray<
204
- T extends UnknownArray,
205
- Result extends UnknownArray = [],
206
- > = T extends unknown
207
- ? number extends T['length']
208
- ? T extends readonly [infer U, ...infer V]
209
- ? StaticPartOfArray<V, [...Result, U]>
210
- : Result
211
- : T
212
- : never; // Should never happen
192
+ export type StaticPartOfArray<T extends UnknownArray, Result extends UnknownArray = [
193
+ ]> = T extends unknown ? number extends T["length"] ? T extends readonly [
194
+ infer U,
195
+ ...infer V
196
+ ] ? StaticPartOfArray<V, [
197
+ ...Result,
198
+ U
199
+ ]> : Result : T : never; // Should never happen
213
200
  /**
214
201
  Returns the variable, non-fixed-length portion of the given array, excluding static-length parts.
215
202
 
@@ -220,22 +207,12 @@ type B = VariablePartOfArray<A>;
220
207
  //=> string[]
221
208
  ```
222
209
  */
223
- export type VariablePartOfArray<T extends UnknownArray> = T extends unknown
224
- ? T extends readonly [...StaticPartOfArray<T>, ...infer U]
225
- ? U
226
- : []
227
- : never; // Should never happen
228
- export type StringDigit =
229
- | '0'
230
- | '1'
231
- | '2'
232
- | '3'
233
- | '4'
234
- | '5'
235
- | '6'
236
- | '7'
237
- | '8'
238
- | '9';
210
+ export type VariablePartOfArray<T extends UnknownArray> = T extends unknown ? T extends readonly [
211
+ ...StaticPartOfArray<T>,
212
+ ...infer U
213
+ ] ? U : [
214
+ ] : never; // Should never happen
215
+ export type StringDigit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
239
216
  /**
240
217
  Returns a boolean for whether the given type is `any`.
241
218
 
@@ -278,7 +255,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
278
255
  */
279
256
  // See https://github.com/microsoft/TypeScript/issues/31752
280
257
  // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
281
- export type PositiveInfinity = 1e999;
258
+ export type PositiveInfinity = Infinity;
282
259
  /**
283
260
  Matches the hidden `-Infinity` type.
284
261
 
@@ -290,7 +267,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
290
267
  */
291
268
  // See https://github.com/microsoft/TypeScript/issues/31752
292
269
  // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
293
- export type NegativeInfinity = -1e999;
270
+ export type NegativeInfinity = -Infinity;
294
271
  /**
295
272
  A negative `number`/`bigint` (`-∞ < x < 0`)
296
273
 
@@ -301,11 +278,7 @@ Use-case: Validating and documenting parameters.
301
278
 
302
279
  @category Numeric
303
280
  */
304
- export type Negative<T extends Numeric> = T extends Zero
305
- ? never
306
- : `${T}` extends `-${string}`
307
- ? T
308
- : never;
281
+ export type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
309
282
  /**
310
283
  Returns a boolean for whether the given number is a negative number.
311
284
 
@@ -321,9 +294,7 @@ type ShouldBeTrue = IsNegative<-1>;
321
294
 
322
295
  @category Numeric
323
296
  */
324
- export type IsNegative<T extends Numeric> = T extends Negative<T>
325
- ? true
326
- : false;
297
+ export type IsNegative<T extends Numeric> = T extends Negative<T> ? true : false;
327
298
  /**
328
299
  Returns a boolean for whether two given types are both true.
329
300
 
@@ -344,12 +315,11 @@ And<true, false>;
344
315
  */
345
316
  export type And<A extends boolean, B extends boolean> = [
346
317
  A,
347
- B,
348
- ][number] extends true
349
- ? true
350
- : true extends [IsEqual<A, false>, IsEqual<B, false>][number]
351
- ? false
352
- : never;
318
+ B
319
+ ][number] extends true ? true : true extends [
320
+ IsEqual<A, false>,
321
+ IsEqual<B, false>
322
+ ][number] ? false : never;
353
323
  /**
354
324
  Returns a boolean for whether either of two given types are true.
355
325
 
@@ -370,12 +340,11 @@ Or<false, false>;
370
340
  */
371
341
  export type Or<A extends boolean, B extends boolean> = [
372
342
  A,
373
- B,
374
- ][number] extends false
375
- ? false
376
- : true extends [IsEqual<A, true>, IsEqual<B, true>][number]
377
- ? true
378
- : never;
343
+ B
344
+ ][number] extends false ? false : true extends [
345
+ IsEqual<A, true>,
346
+ IsEqual<B, true>
347
+ ][number] ? true : never;
379
348
  /**
380
349
  Returns a boolean for whether a given number is greater than another number.
381
350
 
@@ -393,44 +362,32 @@ GreaterThan<1, 5>;
393
362
  //=> false
394
363
  ```
395
364
  */
396
- export type GreaterThan<A extends number, B extends number> = number extends
397
- | A
398
- | B
399
- ? never
400
- : [
401
- IsEqual<A, PositiveInfinity>,
402
- IsEqual<A, NegativeInfinity>,
403
- IsEqual<B, PositiveInfinity>,
404
- IsEqual<B, NegativeInfinity>,
405
- ] extends infer R extends [boolean, boolean, boolean, boolean]
406
- ? Or<
407
- And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
408
- And<IsEqual<R[3], true>, IsEqual<R[1], false>>
409
- > extends true
410
- ? true
411
- : Or<
412
- And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
413
- And<IsEqual<R[2], true>, IsEqual<R[0], false>>
414
- > extends true
415
- ? false
416
- : true extends R[number]
417
- ? false
418
- : [IsNegative<A>, IsNegative<B>] extends infer R extends [
419
- boolean,
420
- boolean,
421
- ]
422
- ? [true, false] extends R
423
- ? false
424
- : [false, true] extends R
425
- ? true
426
- : [false, false] extends R
427
- ? PositiveNumericStringGt<`${A}`, `${B}`>
428
- : PositiveNumericStringGt<
429
- `${NumberAbsolute<B>}`,
430
- `${NumberAbsolute<A>}`
431
- >
432
- : never
433
- : never;
365
+ export type GreaterThan<A extends number, B extends number> = number extends A | B ? never : [
366
+ IsEqual<A, PositiveInfinity>,
367
+ IsEqual<A, NegativeInfinity>,
368
+ IsEqual<B, PositiveInfinity>,
369
+ IsEqual<B, NegativeInfinity>
370
+ ] extends infer R extends [
371
+ boolean,
372
+ boolean,
373
+ boolean,
374
+ boolean
375
+ ] ? 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 : [
376
+ IsNegative<A>,
377
+ IsNegative<B>
378
+ ] extends infer R extends [
379
+ boolean,
380
+ boolean
381
+ ] ? [
382
+ true,
383
+ false
384
+ ] extends R ? false : [
385
+ false,
386
+ true
387
+ ] extends R ? true : [
388
+ false,
389
+ false
390
+ ] extends R ? PositiveNumericStringGt<`${A}`, `${B}`> : PositiveNumericStringGt<`${NumberAbsolute<B>}`, `${NumberAbsolute<A>}`> : never : never;
434
391
  /**
435
392
  Returns a boolean for whether a given number is greater than or equal to another number.
436
393
 
@@ -448,10 +405,7 @@ GreaterThanOrEqual<1, 5>;
448
405
  //=> false
449
406
  ```
450
407
  */
451
- export type GreaterThanOrEqual<
452
- A extends number,
453
- B extends number,
454
- > = number extends A | B ? never : A extends B ? true : GreaterThan<A, B>;
408
+ export type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B ? never : A extends B ? true : GreaterThan<A, B>;
455
409
  /**
456
410
  Returns a boolean for whether a given number is less than another number.
457
411
 
@@ -469,11 +423,7 @@ LessThan<1, 5>;
469
423
  //=> true
470
424
  ```
471
425
  */
472
- export type LessThan<A extends number, B extends number> = number extends A | B
473
- ? never
474
- : GreaterThanOrEqual<A, B> extends true
475
- ? false
476
- : true;
426
+ export type LessThan<A extends number, B extends number> = number extends A | B ? never : GreaterThanOrEqual<A, B> extends true ? false : true;
477
427
  /**
478
428
  Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.
479
429
 
@@ -481,11 +431,11 @@ If `<Fill>` is not provided, it will default to `unknown`.
481
431
 
482
432
  @link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
483
433
  */
484
- export type BuildTuple<
485
- L extends number,
486
- Fill = unknown,
487
- T extends readonly unknown[] = [],
488
- > = T['length'] extends L ? T : BuildTuple<L, Fill, [...T, Fill]>;
434
+ export type BuildTuple<L extends number, Fill = unknown, T extends readonly unknown[] = [
435
+ ]> = T["length"] extends L ? T : BuildTuple<L, Fill, [
436
+ ...T,
437
+ Fill
438
+ ]>;
489
439
  /**
490
440
  Returns the maximum value from a tuple of integers.
491
441
 
@@ -501,16 +451,10 @@ ArrayMax<[1, 2, 5, 3, 99, -1]>;
501
451
  //=> 99
502
452
  ```
503
453
  */
504
- export type TupleMax<
505
- A extends number[],
506
- Result extends number = NegativeInfinity,
507
- > = number extends A[number]
508
- ? never
509
- : A extends [infer F extends number, ...infer R extends number[]]
510
- ? GreaterThan<F, Result> extends true
511
- ? TupleMax<R, F>
512
- : TupleMax<R, Result>
513
- : Result;
454
+ export type TupleMax<A extends number[], Result extends number = NegativeInfinity> = number extends A[number] ? never : A extends [
455
+ infer F extends number,
456
+ ...infer R extends number[]
457
+ ] ? GreaterThan<F, Result> extends true ? TupleMax<R, F> : TupleMax<R, Result> : Result;
514
458
  /**
515
459
  Returns the minimum value from a tuple of integers.
516
460
 
@@ -526,16 +470,10 @@ ArrayMin<[1, 2, 5, 3, -5]>;
526
470
  //=> -5
527
471
  ```
528
472
  */
529
- export type TupleMin<
530
- A extends number[],
531
- Result extends number = PositiveInfinity,
532
- > = number extends A[number]
533
- ? never
534
- : A extends [infer F extends number, ...infer R extends number[]]
535
- ? LessThan<F, Result> extends true
536
- ? TupleMin<R, F>
537
- : TupleMin<R, Result>
538
- : Result;
473
+ export type TupleMin<A extends number[], Result extends number = PositiveInfinity> = number extends A[number] ? never : A extends [
474
+ infer F extends number,
475
+ ...infer R extends number[]
476
+ ] ? LessThan<F, Result> extends true ? TupleMin<R, F> : TupleMin<R, Result> : Result;
539
477
  /**
540
478
  Return a string representation of the given string or number.
541
479
 
@@ -570,14 +508,7 @@ type NegativeInfinity = StringToNumber<'-Infinity'>;
570
508
  @category Numeric
571
509
  @category Template literal
572
510
  */
573
- export type StringToNumber<S extends string> =
574
- S extends `${infer N extends number}`
575
- ? N
576
- : S extends 'Infinity'
577
- ? PositiveInfinity
578
- : S extends '-Infinity'
579
- ? NegativeInfinity
580
- : never;
511
+ export type StringToNumber<S extends string> = S extends `${infer N extends number}` ? N : S extends "Infinity" ? PositiveInfinity : S extends "-Infinity" ? NegativeInfinity : never;
581
512
  /**
582
513
  Returns an array of the characters of the string.
583
514
 
@@ -592,14 +523,11 @@ StringToArray<string>;
592
523
 
593
524
  @category String
594
525
  */
595
- export type StringToArray<
596
- S extends string,
597
- Result extends string[] = [],
598
- > = string extends S
599
- ? never
600
- : S extends `${infer F}${infer R}`
601
- ? StringToArray<R, [...Result, F]>
602
- : Result;
526
+ export type StringToArray<S extends string, Result extends string[] = [
527
+ ]> = string extends S ? never : S extends `${infer F}${infer R}` ? StringToArray<R, [
528
+ ...Result,
529
+ F
530
+ ]> : Result;
603
531
  /**
604
532
  Returns the length of the given string.
605
533
 
@@ -615,9 +543,7 @@ StringLength<string>;
615
543
  @category String
616
544
  @category Template literal
617
545
  */
618
- export type StringLength<S extends string> = string extends S
619
- ? never
620
- : StringToArray<S>['length'];
546
+ export type StringLength<S extends string> = string extends S ? never : StringToArray<S>["length"];
621
547
  /**
622
548
  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.
623
549
 
@@ -630,17 +556,8 @@ SameLengthPositiveNumericStringGt<'10', '10'>;
630
556
  //=> false
631
557
  ```
632
558
  */
633
- export type SameLengthPositiveNumericStringGt<
634
- A extends string,
635
- B extends string,
636
- > = A extends `${infer FirstA}${infer RestA}`
637
- ? B extends `${infer FirstB}${infer RestB}`
638
- ? FirstA extends FirstB
639
- ? SameLengthPositiveNumericStringGt<RestA, RestB>
640
- : PositiveNumericCharacterGt<FirstA, FirstB>
641
- : never
642
- : false;
643
- export type NumericString = '0123456789';
559
+ 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;
560
+ export type NumericString = "0123456789";
644
561
  /**
645
562
  Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
646
563
 
@@ -656,21 +573,16 @@ PositiveNumericStringGt<'1', '500'>;
656
573
  //=> false
657
574
  ```
658
575
  */
659
- export type PositiveNumericStringGt<
660
- A extends string,
661
- B extends string,
662
- > = A extends B
663
- ? false
664
- : [
665
- BuildTuple<StringLength<A>, 0>,
666
- BuildTuple<StringLength<B>, 0>,
667
- ] extends infer R extends [readonly unknown[], readonly unknown[]]
668
- ? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]]
669
- ? 0 extends Remain['length']
670
- ? SameLengthPositiveNumericStringGt<A, B>
671
- : true
672
- : false
673
- : never;
576
+ export type PositiveNumericStringGt<A extends string, B extends string> = A extends B ? false : [
577
+ BuildTuple<StringLength<A>, 0>,
578
+ BuildTuple<StringLength<B>, 0>
579
+ ] extends infer R extends [
580
+ readonly unknown[],
581
+ readonly unknown[]
582
+ ] ? R[0] extends [
583
+ ...R[1],
584
+ ...infer Remain extends readonly unknown[]
585
+ ] ? 0 extends Remain["length"] ? SameLengthPositiveNumericStringGt<A, B> : true : false : never;
674
586
  /**
675
587
  Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
676
588
 
@@ -683,16 +595,7 @@ PositiveNumericCharacterGt<'1', '1'>;
683
595
  //=> false
684
596
  ```
685
597
  */
686
- export type PositiveNumericCharacterGt<
687
- A extends string,
688
- B extends string,
689
- > = NumericString extends `${infer HeadA}${A}${infer TailA}`
690
- ? NumericString extends `${infer HeadB}${B}${infer TailB}`
691
- ? HeadA extends `${HeadB}${infer _}${infer __}`
692
- ? true
693
- : false
694
- : never
695
- : never;
598
+ 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;
696
599
  /**
697
600
  Returns the absolute value of a given value.
698
601
 
@@ -708,10 +611,7 @@ NumberAbsolute<NegativeInfinity>
708
611
  //=> PositiveInfinity
709
612
  ```
710
613
  */
711
- export type NumberAbsolute<N extends number> =
712
- `${N}` extends `-${infer StringPositiveN}`
713
- ? StringToNumber<StringPositiveN>
714
- : N;
614
+ export type NumberAbsolute<N extends number> = `${N}` extends `-${infer StringPositiveN}` ? StringToNumber<StringPositiveN> : N;
715
615
  /**
716
616
  Check whether the given type is a number or a number string.
717
617
 
@@ -731,13 +631,7 @@ type C = IsNumberLike<1>;
731
631
  type D = IsNumberLike<'a'>;
732
632
  //=> false
733
633
  */
734
- export type IsNumberLike<N> = N extends number
735
- ? true
736
- : N extends `${number}`
737
- ? true
738
- : N extends `${number}.${number}`
739
- ? true
740
- : false;
634
+ export type IsNumberLike<N> = N extends number ? true : N extends `${number}` ? true : N extends `${number}.${number}` ? true : false;
741
635
  /**
742
636
  Matches any primitive, `void`, `Date`, or `RegExp` value.
743
637
  */
@@ -745,12 +639,7 @@ export type BuiltIns = Primitive | void | Date | RegExp;
745
639
  /**
746
640
  Matches non-recursive types.
747
641
  */
748
- export type NonRecursiveType =
749
- | BuiltIns
750
- | Function
751
- | (new (
752
- ...arguments_: any[]
753
- ) => unknown);
642
+ export type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown);
754
643
  /**
755
644
  Returns the sum of two numbers.
756
645
 
@@ -782,45 +671,35 @@ Sum<PositiveInfinity, NegativeInfinity>;
782
671
  @category Numeric
783
672
  */
784
673
  // TODO: Support big integer and negative number.
785
- export type Sum<A extends number, B extends number> = number extends A | B
786
- ? number
787
- : [
788
- IsEqual<A, PositiveInfinity>,
789
- IsEqual<A, NegativeInfinity>,
790
- IsEqual<B, PositiveInfinity>,
791
- IsEqual<B, NegativeInfinity>,
792
- ] extends infer R extends [boolean, boolean, boolean, boolean]
793
- ? Or<
794
- And<IsEqual<R[0], true>, IsEqual<R[3], false>>,
795
- And<IsEqual<R[2], true>, IsEqual<R[1], false>>
796
- > extends true
797
- ? PositiveInfinity
798
- : Or<
799
- And<IsEqual<R[1], true>, IsEqual<R[2], false>>,
800
- And<IsEqual<R[3], true>, IsEqual<R[0], false>>
801
- > extends true
802
- ? NegativeInfinity
803
- : true extends R[number]
804
- ? number
805
- : ([IsNegative<A>, IsNegative<B>] extends infer R
806
- ? [false, false] extends R
807
- ? [...BuildTuple<A>, ...BuildTuple<B>]['length']
808
- : [true, true] extends R
809
- ? number
810
- : TupleMax<
811
- [NumberAbsolute<A>, NumberAbsolute<B>]
812
- > extends infer Max_
813
- ? TupleMin<
814
- [NumberAbsolute<A>, NumberAbsolute<B>]
815
- > extends infer Min_ extends number
816
- ? Max_ extends A | B
817
- ? Subtract<Max_, Min_>
818
- : number
819
- : never
820
- : never
821
- : never) &
822
- number
823
- : never;
674
+ export type Sum<A extends number, B extends number> = number extends A | B ? number : [
675
+ IsEqual<A, PositiveInfinity>,
676
+ IsEqual<A, NegativeInfinity>,
677
+ IsEqual<B, PositiveInfinity>,
678
+ IsEqual<B, NegativeInfinity>
679
+ ] extends infer R extends [
680
+ boolean,
681
+ boolean,
682
+ boolean,
683
+ boolean
684
+ ] ? 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 : ([
685
+ IsNegative<A>,
686
+ IsNegative<B>
687
+ ] extends infer R ? [
688
+ false,
689
+ false
690
+ ] extends R ? [
691
+ ...BuildTuple<A>,
692
+ ...BuildTuple<B>
693
+ ]["length"] : [
694
+ true,
695
+ true
696
+ ] extends R ? number : TupleMax<[
697
+ NumberAbsolute<A>,
698
+ NumberAbsolute<B>
699
+ ]> extends infer Max_ ? TupleMin<[
700
+ NumberAbsolute<A>,
701
+ NumberAbsolute<B>
702
+ ]> extends infer Min_ extends number ? Max_ extends A | B ? Subtract<Max_, Min_> : number : never : never : never) & number : never;
824
703
  /**
825
704
  Returns the difference between two numbers.
826
705
 
@@ -851,40 +730,29 @@ Subtract<PositiveInfinity, PositiveInfinity>;
851
730
  @category Numeric
852
731
  */
853
732
  // TODO: Support big integer and negative number.
854
- export type Subtract<A extends number, B extends number> = number extends A | B
855
- ? number
856
- : [
857
- IsEqual<A, PositiveInfinity>,
858
- IsEqual<A, NegativeInfinity>,
859
- IsEqual<B, PositiveInfinity>,
860
- IsEqual<B, NegativeInfinity>,
861
- ] extends infer R extends [boolean, boolean, boolean, boolean]
862
- ? Or<
863
- And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
864
- And<IsEqual<R[3], true>, IsEqual<R[1], false>>
865
- > extends true
866
- ? PositiveInfinity
867
- : Or<
868
- And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
869
- And<IsEqual<R[2], true>, IsEqual<R[0], false>>
870
- > extends true
871
- ? NegativeInfinity
872
- : true extends R[number]
873
- ? number
874
- : [IsNegative<A>, IsNegative<B>] extends infer R
875
- ? [false, false] extends R
876
- ? BuildTuple<A> extends infer R
877
- ? R extends [...BuildTuple<B>, ...infer R]
878
- ? R['length']
879
- : number
880
- : never
881
- : LessThan<A, B> extends true
882
- ? number
883
- : [false, true] extends R
884
- ? Sum<A, NumberAbsolute<B>>
885
- : Subtract<NumberAbsolute<B>, NumberAbsolute<A>>
886
- : never
887
- : never;
733
+ export type Subtract<A extends number, B extends number> = number extends A | B ? number : [
734
+ IsEqual<A, PositiveInfinity>,
735
+ IsEqual<A, NegativeInfinity>,
736
+ IsEqual<B, PositiveInfinity>,
737
+ IsEqual<B, NegativeInfinity>
738
+ ] extends infer R extends [
739
+ boolean,
740
+ boolean,
741
+ boolean,
742
+ boolean
743
+ ] ? 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 : [
744
+ IsNegative<A>,
745
+ IsNegative<B>
746
+ ] extends infer R ? [
747
+ false,
748
+ false
749
+ ] extends R ? BuildTuple<A> extends infer R ? R extends [
750
+ ...BuildTuple<B>,
751
+ ...infer R
752
+ ] ? R["length"] : number : never : LessThan<A, B> extends true ? number : [
753
+ false,
754
+ true
755
+ ] extends R ? Sum<A, NumberAbsolute<B>> : Subtract<NumberAbsolute<B>, NumberAbsolute<A>> : never : never;
888
756
  /**
889
757
  Paths options.
890
758
 
@@ -975,85 +843,28 @@ open('listB.1'); // TypeError. Because listB only has one element.
975
843
  @category Object
976
844
  @category Array
977
845
  */
978
- export type Paths<T, Options extends PathsOptions = {}> = _Paths<
979
- T,
980
- {
981
- // Set default maxRecursionDepth to 10
982
- maxRecursionDepth: Options['maxRecursionDepth'] extends number
983
- ? Options['maxRecursionDepth']
984
- : DefaultPathsOptions['maxRecursionDepth'];
985
- // Set default bracketNotation to false
986
- bracketNotation: Options['bracketNotation'] extends boolean
987
- ? Options['bracketNotation']
988
- : DefaultPathsOptions['bracketNotation'];
989
- }
990
- >;
991
- export type _Paths<T, Options extends Required<PathsOptions>> = T extends
992
- | NonRecursiveType
993
- | ReadonlyMap<unknown, unknown>
994
- | ReadonlySet<unknown>
995
- ? never
996
- : IsAny<T> extends true
997
- ? never
998
- : T extends UnknownArray
999
- ? number extends T['length']
1000
- ?
1001
- | InternalPaths<StaticPartOfArray<T>, Options>
1002
- | InternalPaths<Array<VariablePartOfArray<T>[number]>, Options>
1003
- : InternalPaths<T, Options>
1004
- : T extends object
1005
- ? InternalPaths<T, Options>
1006
- : never;
1007
- export type InternalPaths<
1008
- T,
1009
- Options extends Required<PathsOptions>,
1010
- > = Options['maxRecursionDepth'] extends infer MaxDepth extends number
1011
- ? Required<T> extends infer T
1012
- ? T extends EmptyObject | readonly []
1013
- ? never
1014
- : {
1015
- [Key in keyof T]: Key extends string | number // Limit `Key` to string or number.
1016
- ? (
1017
- Options['bracketNotation'] extends true
1018
- ? IsNumberLike<Key> extends true
1019
- ? `[${Key}]`
1020
- : Key | ToString<Key>
1021
- : never | Options['bracketNotation'] extends false
1022
- ? Key | ToString<Key>
1023
- : never
1024
- ) extends infer TranformedKey extends string | number
1025
- ? // 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
1026
- // 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
1027
- | TranformedKey
1028
- // Recursively generate paths for the current key
1029
- | (GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
1030
- ? _Paths<
1031
- T[Key],
1032
- {
1033
- bracketNotation: Options['bracketNotation'];
1034
- maxRecursionDepth: Subtract<MaxDepth, 1>;
1035
- }
1036
- > extends infer SubPath
1037
- ? SubPath extends string | number
1038
- ?
1039
- | (Options['bracketNotation'] extends true
1040
- ? SubPath extends
1041
- | `[${any}]`
1042
- | `[${any}]${string}`
1043
- ? `${TranformedKey}${SubPath}` // If next node is number key like `[3]`, no need to add `.` before it.
1044
- : `${TranformedKey}.${SubPath}`
1045
- : never)
1046
- | (Options['bracketNotation'] extends false
1047
- ? `${TranformedKey}.${SubPath}`
1048
- : never)
1049
- : never
1050
- : never
1051
- : never)
1052
- : never
1053
- : never;
1054
- }[keyof T & (T extends UnknownArray ? number : unknown)]
1055
- : never
1056
- : never;
846
+ export type Paths<T, Options extends PathsOptions = {}> = _Paths<T, {
847
+ // Set default maxRecursionDepth to 10
848
+ maxRecursionDepth: Options["maxRecursionDepth"] extends number ? Options["maxRecursionDepth"] : DefaultPathsOptions["maxRecursionDepth"];
849
+ // Set default bracketNotation to false
850
+ bracketNotation: Options["bracketNotation"] extends boolean ? Options["bracketNotation"] : DefaultPathsOptions["bracketNotation"];
851
+ }>;
852
+ 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;
853
+ export type InternalPaths<T, Options extends Required<PathsOptions>> = Options["maxRecursionDepth"] extends infer MaxDepth extends number ? Required<T> extends infer T ? T extends EmptyObject | readonly [
854
+ ] ? never : {
855
+ [Key in keyof T]: Key extends string | number // Limit `Key` to string or number.
856
+ ? (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 ?
857
+ // 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
858
+ // 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
859
+ TranformedKey | (
860
+ // Recursively generate paths for the current key
861
+ GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
862
+ ? _Paths<T[Key], {
863
+ bracketNotation: Options["bracketNotation"];
864
+ maxRecursionDepth: Subtract<MaxDepth, 1>;
865
+ }> 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.
866
+ : `${TranformedKey}.${SubPath}` : never) | (Options["bracketNotation"] extends false ? `${TranformedKey}.${SubPath}` : never) : never : never : never) : never : never;
867
+ }[keyof T & (T extends UnknownArray ? number : unknown)] : never : never;
1057
868
  export type LiteralStringUnion<T> = LiteralUnion<T, string>;
1058
869
  /**
1059
870
  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.
@@ -1084,9 +895,7 @@ const pet: Pet2 = '';
1084
895
 
1085
896
  @category Type
1086
897
  */
1087
- export type LiteralUnion<LiteralType, BaseType extends Primitive> =
1088
- | LiteralType
1089
- | (BaseType & Record<never, never>);
898
+ export type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1090
899
  /**
1091
900
  Get keys of the given type as strings.
1092
901
 
@@ -1111,8 +920,7 @@ type StringKeysOfFoo = StringKeyOf<Foo>;
1111
920
 
1112
921
  @category Object
1113
922
  */
1114
- export type StringKeyOf<BaseType> =
1115
- `${Extract<keyof BaseType, string | number>}`;
923
+ export type StringKeyOf<BaseType> = `${Extract<keyof BaseType, string | number>}`;
1116
924
  /**
1117
925
  Represents an array of strings split using a given character or character set.
1118
926
 
@@ -1134,14 +942,13 @@ array = split(items, ',');
1134
942
  @category String
1135
943
  @category Template literal
1136
944
  */
1137
- export type Split<
1138
- S extends string,
1139
- Delimiter extends string,
1140
- > = S extends `${infer Head}${Delimiter}${infer Tail}`
1141
- ? [Head, ...Split<Tail, Delimiter>]
1142
- : S extends Delimiter
1143
- ? []
1144
- : [S];
945
+ export type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [
946
+ Head,
947
+ ...Split<Tail, Delimiter>
948
+ ] : S extends Delimiter ? [
949
+ ] : [
950
+ S
951
+ ];
1145
952
  export type GetOptions = {
1146
953
  /**
1147
954
  Include `undefined` in the return type when accessing properties.
@@ -1155,41 +962,24 @@ export type GetOptions = {
1155
962
  /**
1156
963
  Like the `Get` type but receives an array of strings as a path parameter.
1157
964
  */
1158
- export type GetWithPath<
1159
- BaseType,
1160
- Keys,
1161
- Options extends GetOptions = {},
1162
- > = Keys extends readonly []
1163
- ? BaseType
1164
- : Keys extends readonly [infer Head, ...infer Tail]
1165
- ? GetWithPath<
1166
- PropertyOf<BaseType, Extract<Head, string>, Options>,
1167
- Extract<Tail, string[]>,
1168
- Options
1169
- >
1170
- : never;
965
+ export type GetWithPath<BaseType, Keys, Options extends GetOptions = {}> = Keys extends readonly [
966
+ ] ? BaseType : Keys extends readonly [
967
+ infer Head,
968
+ ...infer Tail
969
+ ] ? GetWithPath<PropertyOf<BaseType, Extract<Head, string>, Options>, Extract<Tail, string[]>, Options> : never;
1171
970
  /**
1172
971
  Adds `undefined` to `Type` if `strict` is enabled.
1173
972
  */
1174
- export type Strictify<
1175
- Type,
1176
- Options extends GetOptions,
1177
- > = Options['strict'] extends false ? Type : Type | undefined;
973
+ export type Strictify<Type, Options extends GetOptions> = Options["strict"] extends false ? Type : (Type | undefined);
1178
974
  /**
1179
975
  If `Options['strict']` is `true`, includes `undefined` in the returned type when accessing properties on `Record<string, any>`.
1180
976
 
1181
977
  Known limitations:
1182
978
  - Does not include `undefined` in the type on object types with an index signature (for example, `{a: string; [key: string]: string}`).
1183
979
  */
1184
- export type StrictPropertyOf<
1185
- BaseType,
1186
- Key extends keyof BaseType,
1187
- Options extends GetOptions,
1188
- > = Record<string, any> extends BaseType
1189
- ? string extends keyof BaseType
1190
- ? Strictify<BaseType[Key], Options> // Record<string, any>
1191
- : BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
1192
- : BaseType[Key];
980
+ 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>
981
+ : BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
982
+ : BaseType[Key];
1193
983
  /**
1194
984
  Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
1195
985
 
@@ -1202,18 +992,11 @@ ToPath<'foo[0].bar.baz'>
1202
992
  //=> ['foo', '0', 'bar', 'baz']
1203
993
  ```
1204
994
  */
1205
- export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.'>;
995
+ export type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, ".">;
1206
996
  /**
1207
997
  Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
1208
998
  */
1209
- export type FixPathSquareBrackets<Path extends string> =
1210
- Path extends `[${infer Head}]${infer Tail}`
1211
- ? Tail extends `[${string}`
1212
- ? `${Head}.${FixPathSquareBrackets<Tail>}`
1213
- : `${Head}${FixPathSquareBrackets<Tail>}`
1214
- : Path extends `${infer Head}[${infer Middle}]${infer Tail}`
1215
- ? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}`
1216
- : Path;
999
+ 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;
1217
1000
  /**
1218
1001
  Returns true if `LongString` is made up out of `Substring` repeated 0 or more times.
1219
1002
 
@@ -1225,14 +1008,7 @@ ConsistsOnlyOf<'aBa', 'a'> //=> false
1225
1008
  ConsistsOnlyOf<'', 'a'> //=> true
1226
1009
  ```
1227
1010
  */
1228
- export type ConsistsOnlyOf<
1229
- LongString extends string,
1230
- Substring extends string,
1231
- > = LongString extends ''
1232
- ? true
1233
- : LongString extends `${Substring}${infer Tail}`
1234
- ? ConsistsOnlyOf<Tail, Substring>
1235
- : false;
1011
+ export type ConsistsOnlyOf<LongString extends string, Substring extends string> = LongString extends "" ? true : LongString extends `${Substring}${infer Tail}` ? ConsistsOnlyOf<Tail, Substring> : false;
1236
1012
  /**
1237
1013
  Convert a type which may have number keys to one with string keys, making it possible to index using strings retrieved from template types.
1238
1014
 
@@ -1253,11 +1029,11 @@ export type WithStringKeys<BaseType> = {
1253
1029
  /**
1254
1030
  Perform a `T[U]` operation if `T` supports indexing.
1255
1031
  */
1256
- export type UncheckedIndex<T, U extends string | number> = [T] extends [
1257
- Record<string | number, any>,
1258
- ]
1259
- ? T[U]
1260
- : never;
1032
+ export type UncheckedIndex<T, U extends string | number> = [
1033
+ T
1034
+ ] extends [
1035
+ Record<string | number, any>
1036
+ ] ? T[U] : never;
1261
1037
  /**
1262
1038
  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.
1263
1039
 
@@ -1265,26 +1041,15 @@ Note:
1265
1041
  - 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.
1266
1042
  - Returns `undefined` from nullish values, to match the behaviour of most deep-key libraries like `lodash`, `dot-prop`, etc.
1267
1043
  */
1268
- export type PropertyOf<
1269
- BaseType,
1270
- Key extends string,
1271
- Options extends GetOptions = {},
1272
- > = BaseType extends null | undefined
1273
- ? undefined
1274
- : Key extends keyof BaseType
1275
- ? StrictPropertyOf<BaseType, Key, Options>
1276
- : BaseType extends readonly [] | readonly [unknown, ...unknown[]]
1277
- ? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
1278
- : BaseType extends {
1279
- [n: number]: infer Item;
1280
- length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
1281
- }
1282
- ? ConsistsOnlyOf<Key, StringDigit> extends true
1283
- ? Strictify<Item, Options>
1284
- : unknown
1285
- : Key extends keyof WithStringKeys<BaseType>
1286
- ? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options>
1287
- : unknown;
1044
+ 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 [
1045
+ ] | readonly [
1046
+ unknown,
1047
+ ...unknown[]
1048
+ ] ? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
1049
+ : BaseType extends {
1050
+ [n: number]: infer Item;
1051
+ length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
1052
+ } ? (ConsistsOnlyOf<Key, StringDigit> extends true ? Strictify<Item, Options> : unknown) : Key extends keyof WithStringKeys<BaseType> ? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options> : unknown;
1288
1053
  // 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.
1289
1054
  /**
1290
1055
  Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
@@ -1332,28 +1097,11 @@ Get<Record<string, string>, 'foo', {strict: true}> // => string
1332
1097
  @category Array
1333
1098
  @category Template literal
1334
1099
  */
1335
- export type Get<
1336
- BaseType,
1337
- Path extends
1338
- | readonly string[]
1339
- | LiteralStringUnion<
1340
- ToString<
1341
- | Paths<
1342
- BaseType,
1343
- {
1344
- bracketNotation: false;
1345
- }
1346
- >
1347
- | Paths<
1348
- BaseType,
1349
- {
1350
- bracketNotation: true;
1351
- }
1352
- >
1353
- >
1354
- >,
1355
- Options extends GetOptions = {},
1356
- > = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, Options>;
1100
+ export type Get<BaseType, Path extends readonly string[] | LiteralStringUnion<ToString<Paths<BaseType, {
1101
+ bracketNotation: false;
1102
+ }> | Paths<BaseType, {
1103
+ bracketNotation: true;
1104
+ }>>>, Options extends GetOptions = {}> = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, Options>;
1357
1105
  export type PlainObject = UnknownRecord;
1358
1106
  export type Smushed<Value> = Simplify<{
1359
1107
  [Key in Paths<Value>]: Get<Value, ToString<Key>>;
@@ -1361,8 +1109,6 @@ export type Smushed<Value> = Simplify<{
1361
1109
  /**
1362
1110
  * Smush an object into a flat object that uses dot notation keys
1363
1111
  */
1364
- export declare function smush<Value extends PlainObject>(
1365
- value: Value,
1366
- ): Smushed<Value>;
1112
+ export declare function smush<Value extends PlainObject>(value: Value): Smushed<Value>;
1367
1113
 
1368
1114
  export {};