@vinicunca/perkakas 1.4.0 → 1.6.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 (151) hide show
  1. package/dist/array-required-prefix-BW08fIbb.d.cts +35 -0
  2. package/dist/array-required-prefix-a3sgCkd2.d.ts +35 -0
  3. package/dist/bounded-partial-CJjczH6j.d.ts +14 -0
  4. package/dist/bounded-partial-wqR8ceNQ.d.cts +14 -0
  5. package/dist/{chunk-AJQEGHF5.cjs → chunk-22AQJBPW.cjs} +1 -1
  6. package/dist/chunk-2HQM73IT.cjs +1 -0
  7. package/dist/chunk-2XGSSTCA.js +1 -0
  8. package/dist/{chunk-6ENW2VLC.cjs → chunk-3LC3CLYE.cjs} +1 -1
  9. package/dist/chunk-44LUF6RO.js +1 -0
  10. package/dist/{chunk-IXGOK22A.cjs → chunk-5NW4GR2Q.cjs} +1 -1
  11. package/dist/chunk-5PMGMODH.js +1 -0
  12. package/dist/{chunk-GVYLRJPB.cjs → chunk-66JP4PUG.cjs} +1 -1
  13. package/dist/{chunk-6XVLHSPK.js → chunk-673TXH2U.js} +1 -1
  14. package/dist/chunk-6M4IYQFZ.js +1 -0
  15. package/dist/chunk-B6SBIS6W.js +1 -0
  16. package/dist/{chunk-OL2TQDYM.cjs → chunk-BDBX4ZMW.cjs} +1 -1
  17. package/dist/chunk-BEMQAYI5.cjs +1 -0
  18. package/dist/chunk-CTGIT5TY.js +1 -0
  19. package/dist/chunk-FGMSPUSF.cjs +1 -0
  20. package/dist/{chunk-Z46FX2Y4.js → chunk-FP3LV577.js} +1 -1
  21. package/dist/{chunk-22IDCBFS.js → chunk-GFXNX2W7.js} +1 -1
  22. package/dist/chunk-GW4KDK3D.cjs +1 -0
  23. package/dist/chunk-GWXILWA5.cjs +1 -0
  24. package/dist/chunk-HSNPZS6R.cjs +1 -0
  25. package/dist/chunk-ITDJLXHO.js +1 -0
  26. package/dist/{chunk-QQMFHVPX.cjs → chunk-J3ZXNDMT.cjs} +1 -1
  27. package/dist/{chunk-FLQYTU5W.cjs → chunk-JHFSYEXB.cjs} +1 -1
  28. package/dist/{chunk-WCPENZWH.js → chunk-JI5FJX2E.js} +1 -1
  29. package/dist/chunk-K26HQR4Y.cjs +1 -0
  30. package/dist/chunk-KYMVIFAW.cjs +1 -0
  31. package/dist/{chunk-ZQXE6PIV.cjs → chunk-NVCXF5UR.cjs} +1 -1
  32. package/dist/chunk-O74TUGYF.js +1 -0
  33. package/dist/{chunk-MHEODCN3.cjs → chunk-OMHZCALN.cjs} +1 -1
  34. package/dist/chunk-QFJ3I53F.js +0 -0
  35. package/dist/chunk-R4O7XE2F.cjs +1 -0
  36. package/dist/chunk-TVMG2NYC.js +1 -0
  37. package/dist/chunk-UWMBE6BM.js +1 -0
  38. package/dist/{chunk-VBH6SKKO.js → chunk-VI2QG3FU.js} +1 -1
  39. package/dist/chunk-YCSQX2SY.js +1 -0
  40. package/dist/chunk-ZITGCTSW.js +1 -0
  41. package/dist/chunk.cjs +1 -1
  42. package/dist/chunk.d.cts +33 -22
  43. package/dist/chunk.d.ts +33 -22
  44. package/dist/chunk.js +1 -1
  45. package/dist/clamped-integer-subtract-DZ7rsJE4.d.cts +15 -0
  46. package/dist/clamped-integer-subtract-DZ7rsJE4.d.ts +15 -0
  47. package/dist/coerced-array-DRz3tqda.d.cts +14 -0
  48. package/dist/coerced-array-DRz3tqda.d.ts +14 -0
  49. package/dist/count-by.cjs +1 -1
  50. package/dist/count-by.d.cts +3 -3
  51. package/dist/count-by.d.ts +3 -3
  52. package/dist/count-by.js +1 -1
  53. package/dist/drop-first-by.cjs +1 -1
  54. package/dist/drop-first-by.js +1 -1
  55. package/dist/drop.cjs +1 -1
  56. package/dist/drop.d.cts +17 -30
  57. package/dist/drop.d.ts +17 -30
  58. package/dist/drop.js +1 -1
  59. package/dist/filter.cjs +1 -1
  60. package/dist/filter.d.cts +12 -4
  61. package/dist/filter.d.ts +12 -4
  62. package/dist/filter.js +1 -1
  63. package/dist/filtered-array-BNHX1Nwj.d.ts +18 -0
  64. package/dist/filtered-array-DX6NNaBq.d.cts +18 -0
  65. package/dist/first-by.cjs +1 -1
  66. package/dist/first-by.js +1 -1
  67. package/dist/from-keys.cjs +1 -1
  68. package/dist/from-keys.d.cts +2 -2
  69. package/dist/from-keys.d.ts +2 -2
  70. package/dist/from-keys.js +1 -1
  71. package/dist/funnel.reference-batch.test.cjs +1 -1
  72. package/dist/funnel.reference-batch.test.js +1 -1
  73. package/dist/group-by-prop.cjs +1 -0
  74. package/dist/group-by-prop.d.cts +91 -0
  75. package/dist/group-by-prop.d.ts +91 -0
  76. package/dist/group-by-prop.js +1 -0
  77. package/dist/group-by.cjs +1 -1
  78. package/dist/group-by.d.cts +13 -3
  79. package/dist/group-by.d.ts +13 -3
  80. package/dist/group-by.js +1 -1
  81. package/dist/has-at-least.cjs +1 -1
  82. package/dist/has-at-least.d.cts +6 -15
  83. package/dist/has-at-least.d.ts +6 -15
  84. package/dist/has-at-least.js +1 -1
  85. package/dist/index-by.cjs +1 -1
  86. package/dist/index-by.d.cts +3 -3
  87. package/dist/index-by.d.ts +3 -3
  88. package/dist/index-by.js +1 -1
  89. package/dist/index.cjs +1 -1
  90. package/dist/index.d.cts +9 -3
  91. package/dist/index.d.ts +9 -3
  92. package/dist/index.js +1 -1
  93. package/dist/map-keys.cjs +1 -1
  94. package/dist/map-keys.d.cts +4 -4
  95. package/dist/map-keys.d.ts +4 -4
  96. package/dist/map-keys.js +1 -1
  97. package/dist/merge-all.d.cts +1 -1
  98. package/dist/merge-all.d.ts +1 -1
  99. package/dist/omit.cjs +1 -1
  100. package/dist/omit.js +1 -1
  101. package/dist/partial-array-Vnf1fBtl.d.cts +10 -0
  102. package/dist/partial-array-Vnf1fBtl.d.ts +10 -0
  103. package/dist/pull-object.cjs +1 -1
  104. package/dist/pull-object.d.cts +3 -3
  105. package/dist/pull-object.d.ts +3 -3
  106. package/dist/pull-object.js +1 -1
  107. package/dist/sort-by.d.cts +1 -1
  108. package/dist/sort-by.d.ts +1 -1
  109. package/dist/take-first-by.cjs +1 -1
  110. package/dist/take-first-by.js +1 -1
  111. package/dist/take-last-while.cjs +1 -1
  112. package/dist/take-last-while.d.cts +2 -0
  113. package/dist/take-last-while.d.ts +2 -0
  114. package/dist/take-last-while.js +1 -1
  115. package/dist/take-while.d.cts +2 -0
  116. package/dist/take-while.d.ts +2 -0
  117. package/dist/tuple-parts-CrwnkDKX.d.ts +100 -0
  118. package/dist/tuple-parts-DAqFAJP8.d.cts +100 -0
  119. package/dist/type.helpers.cjs +1 -0
  120. package/dist/type.helpers.d.cts +10 -0
  121. package/dist/type.helpers.d.ts +10 -0
  122. package/dist/type.helpers.js +1 -0
  123. package/package.json +1 -1
  124. package/dist/chunk-2MU3SHCO.js +0 -1
  125. package/dist/chunk-3CFBQYOQ.js +0 -1
  126. package/dist/chunk-5VXKW6SI.cjs +0 -1
  127. package/dist/chunk-APUBIDDU.cjs +0 -1
  128. package/dist/chunk-B5QDOWVQ.cjs +0 -1
  129. package/dist/chunk-B7RHAPUE.js +0 -1
  130. package/dist/chunk-BOOMUHPG.js +0 -1
  131. package/dist/chunk-DLXKXNZT.js +0 -1
  132. package/dist/chunk-I7K3Z4BT.js +0 -1
  133. package/dist/chunk-IJ4I5A3K.js +0 -1
  134. package/dist/chunk-L4ITKDYB.cjs +0 -1
  135. package/dist/chunk-OEJ5J23C.js +0 -1
  136. package/dist/chunk-PIF5X7RQ.cjs +0 -1
  137. package/dist/chunk-PWHX2554.js +0 -1
  138. package/dist/chunk-THE6MSJO.cjs +0 -1
  139. package/dist/chunk-UUYCL4G2.js +0 -1
  140. package/dist/chunk-XLGD5ZUY.cjs +0 -1
  141. package/dist/chunk-YCM6N46T.js +0 -1
  142. package/dist/exact-record-Dhbe_K-E.d.ts +0 -5
  143. package/dist/exact-record-_isi2JMR.d.cts +0 -5
  144. package/dist/n-tuple-5jljrt4c.d.cts +0 -10
  145. package/dist/n-tuple-5jljrt4c.d.ts +0 -10
  146. package/dist/take-last-while.spec-d-.cjs +0 -1
  147. package/dist/take-last-while.spec-d-.d.cts +0 -2
  148. package/dist/take-last-while.spec-d-.d.ts +0 -2
  149. package/dist/take-last-while.spec-d-.js +0 -1
  150. package/dist/tuple-parts-CP0H7BrE.d.cts +0 -37
  151. package/dist/tuple-parts-CP0H7BrE.d.ts +0 -37
@@ -1,7 +1,7 @@
1
+ import { O as OrderRule } from './curry-order-rules-BKXCPBNx.cjs';
1
2
  import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
2
3
  import { N as NonEmptyArray } from './non-empty-array-C9Od1wmF.cjs';
3
4
  import { R as ReorderedArray } from './reordered-array-DTkM8K3n.cjs';
4
- import { O as OrderRule } from './curry-order-rules-BKXCPBNx.cjs';
5
5
 
6
6
  /**
7
7
  * Sorts `data` using the provided ordering rules. The `sort` is done via the
package/dist/sort-by.d.ts CHANGED
@@ -1,7 +1,7 @@
1
+ import { O as OrderRule } from './curry-order-rules-BKXCPBNx.js';
1
2
  import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
2
3
  import { N as NonEmptyArray } from './non-empty-array-C9Od1wmF.js';
3
4
  import { R as ReorderedArray } from './reordered-array-DVguhAmZ.js';
4
- import { O as OrderRule } from './curry-order-rules-BKXCPBNx.js';
5
5
 
6
6
  /**
7
7
  * Sorts `data` using the provided ordering rules. The `sort` is done via the
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIXGOK22Acjs = require('./chunk-IXGOK22A.cjs');require('./chunk-FLQYTU5W.cjs');require('./chunk-Z6OOXW67.cjs');require('./chunk-EROXO3T4.cjs');require('./chunk-GVYLRJPB.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.takeFirstBy = _chunkIXGOK22Acjs.a;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk5NW4GR2Qcjs = require('./chunk-5NW4GR2Q.cjs');require('./chunk-JHFSYEXB.cjs');require('./chunk-Z6OOXW67.cjs');require('./chunk-EROXO3T4.cjs');require('./chunk-66JP4PUG.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.takeFirstBy = _chunk5NW4GR2Qcjs.a;
@@ -1 +1 @@
1
- import{a}from"./chunk-6XVLHSPK.js";import"./chunk-WCPENZWH.js";import"./chunk-YYEJOSR3.js";import"./chunk-7KBK2RWQ.js";import"./chunk-DLXKXNZT.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";export{a as takeFirstBy};
1
+ import{a}from"./chunk-673TXH2U.js";import"./chunk-JI5FJX2E.js";import"./chunk-YYEJOSR3.js";import"./chunk-7KBK2RWQ.js";import"./chunk-ITDJLXHO.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";export{a as takeFirstBy};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkZQXE6PIVcjs = require('./chunk-ZQXE6PIV.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.takeLastWhile = _chunkZQXE6PIVcjs.a;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkNVCXF5URcjs = require('./chunk-NVCXF5UR.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');exports.takeLastWhile = _chunkNVCXF5URcjs.a;
@@ -13,6 +13,7 @@ import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
13
13
  * @dataFirst
14
14
  * @category Array
15
15
  */
16
+ declare function takeLastWhile<T extends IterableContainer, S extends T[number]>(data: T, predicate: (item: T[number], index: number, data: T) => item is S): Array<S>;
16
17
  declare function takeLastWhile<T extends IterableContainer>(data: T, predicate: (item: T[number], index: number, data: T) => boolean): Array<T[number]>;
17
18
  /**
18
19
  * Returns elements from the end of the array until the predicate returns false.
@@ -26,6 +27,7 @@ declare function takeLastWhile<T extends IterableContainer>(data: T, predicate:
26
27
  * @dataLast
27
28
  * @category Array
28
29
  */
30
+ declare function takeLastWhile<T extends IterableContainer, S extends T[number]>(predicate: (item: T[number], index: number, data: T) => item is S): (array: T) => Array<S>;
29
31
  declare function takeLastWhile<T extends IterableContainer>(predicate: (item: T[number], index: number, data: T) => boolean): (data: T) => Array<T[number]>;
30
32
 
31
33
  export { takeLastWhile };
@@ -13,6 +13,7 @@ import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
13
13
  * @dataFirst
14
14
  * @category Array
15
15
  */
16
+ declare function takeLastWhile<T extends IterableContainer, S extends T[number]>(data: T, predicate: (item: T[number], index: number, data: T) => item is S): Array<S>;
16
17
  declare function takeLastWhile<T extends IterableContainer>(data: T, predicate: (item: T[number], index: number, data: T) => boolean): Array<T[number]>;
17
18
  /**
18
19
  * Returns elements from the end of the array until the predicate returns false.
@@ -26,6 +27,7 @@ declare function takeLastWhile<T extends IterableContainer>(data: T, predicate:
26
27
  * @dataLast
27
28
  * @category Array
28
29
  */
30
+ declare function takeLastWhile<T extends IterableContainer, S extends T[number]>(predicate: (item: T[number], index: number, data: T) => item is S): (array: T) => Array<S>;
29
31
  declare function takeLastWhile<T extends IterableContainer>(predicate: (item: T[number], index: number, data: T) => boolean): (data: T) => Array<T[number]>;
30
32
 
31
33
  export { takeLastWhile };
@@ -1 +1 @@
1
- import{a}from"./chunk-3CFBQYOQ.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";export{a as takeLastWhile};
1
+ import{a}from"./chunk-O74TUGYF.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";export{a as takeLastWhile};
@@ -12,6 +12,7 @@ import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
12
12
  * @dataFirst
13
13
  * @category Array
14
14
  */
15
+ declare function takeWhile<T extends IterableContainer, S extends T[number]>(data: T, predicate: (item: T[number], index: number, data: T) => item is S): Array<S>;
15
16
  declare function takeWhile<T extends IterableContainer>(data: T, predicate: (item: T[number], index: number, data: T) => boolean): Array<T[number]>;
16
17
  /**
17
18
  * Returns elements from the array until predicate returns false.
@@ -24,6 +25,7 @@ declare function takeWhile<T extends IterableContainer>(data: T, predicate: (ite
24
25
  * @dataLast
25
26
  * @category Array
26
27
  */
28
+ declare function takeWhile<T extends IterableContainer, S extends T[number]>(predicate: (item: T[number], index: number, data: T) => item is S): (array: T) => Array<S>;
27
29
  declare function takeWhile<T extends IterableContainer>(predicate: (item: T[number], index: number, data: T) => boolean): (array: T) => Array<T[number]>;
28
30
 
29
31
  export { takeWhile };
@@ -12,6 +12,7 @@ import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
12
12
  * @dataFirst
13
13
  * @category Array
14
14
  */
15
+ declare function takeWhile<T extends IterableContainer, S extends T[number]>(data: T, predicate: (item: T[number], index: number, data: T) => item is S): Array<S>;
15
16
  declare function takeWhile<T extends IterableContainer>(data: T, predicate: (item: T[number], index: number, data: T) => boolean): Array<T[number]>;
16
17
  /**
17
18
  * Returns elements from the array until predicate returns false.
@@ -24,6 +25,7 @@ declare function takeWhile<T extends IterableContainer>(data: T, predicate: (ite
24
25
  * @dataLast
25
26
  * @category Array
26
27
  */
28
+ declare function takeWhile<T extends IterableContainer, S extends T[number]>(predicate: (item: T[number], index: number, data: T) => item is S): (array: T) => Array<S>;
27
29
  declare function takeWhile<T extends IterableContainer>(predicate: (item: T[number], index: number, data: T) => boolean): (array: T) => Array<T[number]>;
28
30
 
29
31
  export { takeWhile };
@@ -0,0 +1,100 @@
1
+ import { Tagged, Simplify, Or } from 'type-fest';
2
+ import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
3
+
4
+ declare const PerkakasErrorSymbol: unique symbol;
5
+ interface PerkakasTypeErrorOptions {
6
+ type?: unknown;
7
+ metadata?: unknown;
8
+ }
9
+ /**
10
+ * Used for reporting type errors in a more useful way than `never`.
11
+ */
12
+ type PerkakasTypeError<FunctionName extends string, Message extends number | string, Options extends PerkakasTypeErrorOptions = {}> = Tagged<Options extends {
13
+ type: infer T;
14
+ } ? T : typeof PerkakasErrorSymbol, `PerkakasTypeError(${FunctionName}): ${Message}.`, Options extends {
15
+ metadata: infer Metadata;
16
+ } ? Metadata : never>;
17
+
18
+ /**
19
+ * Takes a tuple and returns the types that make up its parts. These parts
20
+ * follow TypeScript's only supported format for arrays/tuples:
21
+ * [<required>, <optional>, ...<rest>[], <suffix>].
22
+ *
23
+ * There are some limitations to what shapes TypeScript supports:
24
+ * tuples can only have a suffix if they also have a non-never rest element,
25
+ * **and** tuples cannot have both an optional part and a suffix; this means
26
+ * there are only 10 possible shapes for tuples:
27
+ * 1. Empty Tuples: `[]`.
28
+ * 2. Fixed Tuples: `[string, number]`.
29
+ * 3. Optional Tuples: `[string?, number?]`.
30
+ * 4. Mixed Tuples: `[string, number?]`.
31
+ * 5. Arrays: `Array<string>`.
32
+ * 6. Fixed-Prefix Arrays: `[string, ...Array<string>]`.
33
+ * 7. Optional-Prefix Arrays: `[number?, ...Array<boolean>]`.
34
+ * 8. Mixed-Prefix Arrays: `[string, number?, ...Array<boolean>]`.
35
+ * 9. Fixed-Suffix Arrays: `[...Array<string>, string]`.
36
+ * 10. Fixed-Elements Arrays: `[string, ...Array<string>, string]`.
37
+ *
38
+ * @example [
39
+ * ...TupleParts<T>["required"],
40
+ * ...Partial<TupleParts<T>["optional"]>,
41
+ * ...CoercedArray<TupleParts<T>["item"]>,
42
+ * ...TupleParts<T>["suffix"],
43
+ * ].
44
+ */
45
+ type TupleParts<T extends IterableContainer, Prefix extends Array<unknown> = []> = T extends readonly [infer Head, ...infer Tail] ? TupleParts<Tail, [...Prefix, Head]> : Simplify<{
46
+ /**
47
+ * A fixed tuple that defines the part of the tuple where all its
48
+ * elements are required. This will always be the first part of the
49
+ * tuple and will never contain any optional or rest elements. When the
50
+ * array doesn't have a required part this will be an empty tuple
51
+ * (`[]`).
52
+ */
53
+ required: Prefix;
54
+ } & TuplePartsWithoutRequired<T>>;
55
+ type TuplePartsWithoutRequired<T extends IterableContainer, Suffix extends Array<unknown> = []> = T extends readonly [...infer Head, infer Tail] ? TuplePartsWithoutRequired<Head, [Tail, ...Suffix]> : (Suffix extends readonly [] ? TuplePartsWithoutFixed<T> : // When the suffix is not empty we can skip the optional part and go
56
+ {
57
+ optional: [];
58
+ } & TuplePartsRest<T>) & {
59
+ /**
60
+ * A *fixed* tuple that defines the part of a tuple **after** a non-never
61
+ * rest parameter. These could never be optional elements, and could
62
+ * never contain another rest element. When the array doesn't have a
63
+ * required part this will be an empty tuple (`[]`).
64
+ */
65
+ suffix: Suffix;
66
+ };
67
+ type TuplePartsWithoutFixed<T extends IterableContainer, Optional extends Array<unknown> = []> = T extends readonly [(infer Head)?, ...infer Tail] ? Or<T extends readonly [] ? true : false, Array<T[number]> extends Tail ? true : false> extends true ? {
68
+ /**
69
+ * A *fixed* tuple that defines the part of a tuple where all its
70
+ * elements are suffixed with the optional operator (`?`); but with
71
+ * the optional operator removed (e.g. `[string?]` would be
72
+ * represented as `[string]`). These elements can only follow the
73
+ * `required` part (which could be empty).
74
+ * To add optional operator back wrap the result with the built-in
75
+ * `Partial` type.
76
+ * When the array doesn't have a required part this will be an empty
77
+ * tuple (`[]`).
78
+ *
79
+ * @example Partial<TupleParts<T>["optional"]>
80
+ */
81
+ optional: Optional;
82
+ } & TuplePartsRest<T> : TuplePartsWithoutFixed<Tail, [...Optional, Head | undefined]> : PerkakasTypeError<'TupleParts', 'Unexpected tuple shape', {
83
+ type: never;
84
+ metadata: T;
85
+ }>;
86
+ interface TuplePartsRest<T extends IterableContainer> {
87
+ /**
88
+ * The type for the rest parameter of the tuple, if any. Unlike the
89
+ * other parts of the tuple, this is a single type and not
90
+ * represented as an array/tuple. When a tuple doesn't have a rest
91
+ * element, this will be `never`. To convert this to a matching array
92
+ * type that could be spread into a new type use the `CoercedArray`
93
+ * type which handles the `never` case correctly.
94
+ *
95
+ * @example CoercedArray<TupleParts<T>["item"]>
96
+ */
97
+ item: T extends readonly [] ? never : T[number];
98
+ }
99
+
100
+ export type { PerkakasTypeError as P, TupleParts as T };
@@ -0,0 +1,100 @@
1
+ import { Tagged, Simplify, Or } from 'type-fest';
2
+ import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
3
+
4
+ declare const PerkakasErrorSymbol: unique symbol;
5
+ interface PerkakasTypeErrorOptions {
6
+ type?: unknown;
7
+ metadata?: unknown;
8
+ }
9
+ /**
10
+ * Used for reporting type errors in a more useful way than `never`.
11
+ */
12
+ type PerkakasTypeError<FunctionName extends string, Message extends number | string, Options extends PerkakasTypeErrorOptions = {}> = Tagged<Options extends {
13
+ type: infer T;
14
+ } ? T : typeof PerkakasErrorSymbol, `PerkakasTypeError(${FunctionName}): ${Message}.`, Options extends {
15
+ metadata: infer Metadata;
16
+ } ? Metadata : never>;
17
+
18
+ /**
19
+ * Takes a tuple and returns the types that make up its parts. These parts
20
+ * follow TypeScript's only supported format for arrays/tuples:
21
+ * [<required>, <optional>, ...<rest>[], <suffix>].
22
+ *
23
+ * There are some limitations to what shapes TypeScript supports:
24
+ * tuples can only have a suffix if they also have a non-never rest element,
25
+ * **and** tuples cannot have both an optional part and a suffix; this means
26
+ * there are only 10 possible shapes for tuples:
27
+ * 1. Empty Tuples: `[]`.
28
+ * 2. Fixed Tuples: `[string, number]`.
29
+ * 3. Optional Tuples: `[string?, number?]`.
30
+ * 4. Mixed Tuples: `[string, number?]`.
31
+ * 5. Arrays: `Array<string>`.
32
+ * 6. Fixed-Prefix Arrays: `[string, ...Array<string>]`.
33
+ * 7. Optional-Prefix Arrays: `[number?, ...Array<boolean>]`.
34
+ * 8. Mixed-Prefix Arrays: `[string, number?, ...Array<boolean>]`.
35
+ * 9. Fixed-Suffix Arrays: `[...Array<string>, string]`.
36
+ * 10. Fixed-Elements Arrays: `[string, ...Array<string>, string]`.
37
+ *
38
+ * @example [
39
+ * ...TupleParts<T>["required"],
40
+ * ...Partial<TupleParts<T>["optional"]>,
41
+ * ...CoercedArray<TupleParts<T>["item"]>,
42
+ * ...TupleParts<T>["suffix"],
43
+ * ].
44
+ */
45
+ type TupleParts<T extends IterableContainer, Prefix extends Array<unknown> = []> = T extends readonly [infer Head, ...infer Tail] ? TupleParts<Tail, [...Prefix, Head]> : Simplify<{
46
+ /**
47
+ * A fixed tuple that defines the part of the tuple where all its
48
+ * elements are required. This will always be the first part of the
49
+ * tuple and will never contain any optional or rest elements. When the
50
+ * array doesn't have a required part this will be an empty tuple
51
+ * (`[]`).
52
+ */
53
+ required: Prefix;
54
+ } & TuplePartsWithoutRequired<T>>;
55
+ type TuplePartsWithoutRequired<T extends IterableContainer, Suffix extends Array<unknown> = []> = T extends readonly [...infer Head, infer Tail] ? TuplePartsWithoutRequired<Head, [Tail, ...Suffix]> : (Suffix extends readonly [] ? TuplePartsWithoutFixed<T> : // When the suffix is not empty we can skip the optional part and go
56
+ {
57
+ optional: [];
58
+ } & TuplePartsRest<T>) & {
59
+ /**
60
+ * A *fixed* tuple that defines the part of a tuple **after** a non-never
61
+ * rest parameter. These could never be optional elements, and could
62
+ * never contain another rest element. When the array doesn't have a
63
+ * required part this will be an empty tuple (`[]`).
64
+ */
65
+ suffix: Suffix;
66
+ };
67
+ type TuplePartsWithoutFixed<T extends IterableContainer, Optional extends Array<unknown> = []> = T extends readonly [(infer Head)?, ...infer Tail] ? Or<T extends readonly [] ? true : false, Array<T[number]> extends Tail ? true : false> extends true ? {
68
+ /**
69
+ * A *fixed* tuple that defines the part of a tuple where all its
70
+ * elements are suffixed with the optional operator (`?`); but with
71
+ * the optional operator removed (e.g. `[string?]` would be
72
+ * represented as `[string]`). These elements can only follow the
73
+ * `required` part (which could be empty).
74
+ * To add optional operator back wrap the result with the built-in
75
+ * `Partial` type.
76
+ * When the array doesn't have a required part this will be an empty
77
+ * tuple (`[]`).
78
+ *
79
+ * @example Partial<TupleParts<T>["optional"]>
80
+ */
81
+ optional: Optional;
82
+ } & TuplePartsRest<T> : TuplePartsWithoutFixed<Tail, [...Optional, Head | undefined]> : PerkakasTypeError<'TupleParts', 'Unexpected tuple shape', {
83
+ type: never;
84
+ metadata: T;
85
+ }>;
86
+ interface TuplePartsRest<T extends IterableContainer> {
87
+ /**
88
+ * The type for the rest parameter of the tuple, if any. Unlike the
89
+ * other parts of the tuple, this is a single type and not
90
+ * represented as an array/tuple. When a tuple doesn't have a rest
91
+ * element, this will be `never`. To convert this to a matching array
92
+ * type that could be spread into a new type use the `CoercedArray`
93
+ * type which handles the `never` case correctly.
94
+ *
95
+ * @example CoercedArray<TupleParts<T>["item"]>
96
+ */
97
+ item: T extends readonly [] ? never : T[number];
98
+ }
99
+
100
+ export type { PerkakasTypeError as P, TupleParts as T };
@@ -0,0 +1 @@
1
+ "use strict";require('./chunk-GWXILWA5.cjs');
@@ -0,0 +1,10 @@
1
+ interface TightMap<O = any> {
2
+ [key: string]: TightMap | O;
3
+ }
4
+ type DeepPartial<T, O = any> = {
5
+ [P in keyof T]?: T[P] extends Array<string> ? string : T[P] extends object ? DeepPartial<T[P], O> : T[P];
6
+ } & {
7
+ [key: string]: O | TightMap<O>;
8
+ };
9
+
10
+ export type { DeepPartial };
@@ -0,0 +1,10 @@
1
+ interface TightMap<O = any> {
2
+ [key: string]: TightMap | O;
3
+ }
4
+ type DeepPartial<T, O = any> = {
5
+ [P in keyof T]?: T[P] extends Array<string> ? string : T[P] extends object ? DeepPartial<T[P], O> : T[P];
6
+ } & {
7
+ [key: string]: O | TightMap<O>;
8
+ };
9
+
10
+ export type { DeepPartial };
@@ -0,0 +1 @@
1
+ import"./chunk-QFJ3I53F.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vinicunca/perkakas",
3
3
  "type": "module",
4
- "version": "1.4.0",
4
+ "version": "1.6.0",
5
5
  "description": "Utility for JavaScript and Typescript.",
6
6
  "author": "praburangki<https://github.com/praburangki>",
7
7
  "license": "MIT",
@@ -1 +0,0 @@
1
- import{a as o}from"./chunk-J6WPJH72.js";function i(...e){return o(p,e)}function p(e,a){let n=new Map;for(let[d,t]of e.entries()){let y=a(t,d,e);if(y!==void 0){let r=n.get(y);r===void 0&&(r=[],n.set(y,r)),r.push(t)}}return Object.fromEntries(n)}export{i as a};
@@ -1 +0,0 @@
1
- import{a as r}from"./chunk-J6WPJH72.js";function o(...e){return r(a,e)}function a(e,t){for(let n=e.length-1;n>=0;n--)if(!t(e[n],n,e))return e.slice(n+1);return[...e]}export{o as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkXR72I63Wcjs = require('./chunk-XR72I63W.cjs');function p(...e){return _chunkXR72I63Wcjs.a.call(void 0, u,e)}function u(e,a){let n={};for(let[o,r]of Object.entries(e)){let y=a(o,r,e);n[y]=r}return n}exports.a = p;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkXR72I63Wcjs = require('./chunk-XR72I63W.cjs');function i(...e){return _chunkXR72I63Wcjs.a.call(void 0, p,e)}function p(e,a){let n=new Map;for(let[d,t]of e.entries()){let y=a(t,d,e);if(y!==void 0){let r=n.get(y);r===void 0&&(r=[],n.set(y,r)),r.push(t)}}return Object.fromEntries(n)}exports.a = i;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkN5JE6642cjs = require('./chunk-N5JE6642.cjs');var _chunkXR72I63Wcjs = require('./chunk-XR72I63W.cjs');function l(...e){return _chunkXR72I63Wcjs.a.call(void 0, p,e,u)}function p(e,r){return r<0?[...e]:e.slice(r)}function u(e){if(e<=0)return _chunkN5JE6642cjs.c;let r=e;return o=>r>0?(r-=1,_chunkN5JE6642cjs.a):{done:!1,hasNext:!0,next:o}}exports.a = l;
@@ -1 +0,0 @@
1
- import{a as t}from"./chunk-J6WPJH72.js";function c(...e){return t(y,e)}function y(e,o){let r={};for(let[a,n]of e.entries()){let d=o(n,a,e);r[d]=n}return r}export{c as a};
@@ -1 +0,0 @@
1
- import{a as o}from"./chunk-J6WPJH72.js";function i(...e){return o(u,e)}function u(e,a){let n=new Map;for(let[d,y]of e.entries()){let r=a(y,d,e);if(r!==void 0){let t=n.get(r);t===void 0?n.set(r,1):n.set(r,t+1)}}return Object.fromEntries(n)}export{i as a};
@@ -1 +0,0 @@
1
- import{a as n}from"./chunk-J6WPJH72.js";function i(...e){return n(r,e)}function r(e,t){return e.length>=t}export{i as a};
@@ -1 +0,0 @@
1
- import{a}from"./chunk-J6WPJH72.js";function l(...e){return a(s,e)}function s(e,n){if(n<1)throw new RangeError(`chunk: A chunk size of '${n}' would result in an infinite array`);if(e.length===0)return[];if(n>=e.length)return[[...e]];let i=Math.ceil(e.length/n),u=new Array(i);if(n===1)for(let[r,t]of e.entries())u[r]=[t];else for(let r=0;r<i;r+=1){let t=r*n;u[r]=e.slice(t,t+n)}return u}export{l as a};
@@ -1 +0,0 @@
1
- import{a as n}from"./chunk-J6WPJH72.js";function i(...e){return n(a,e)}function a(e,o){let r={};for(let[y,t]of e.entries())r[t]=o(t,y,e);return r}export{i as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkXR72I63Wcjs = require('./chunk-XR72I63W.cjs');function l(...e){return _chunkXR72I63Wcjs.a.call(void 0, s,e)}function s(e,n){if(n<1)throw new RangeError(`chunk: A chunk size of '${n}' would result in an infinite array`);if(e.length===0)return[];if(n>=e.length)return[[...e]];let i=Math.ceil(e.length/n),u=new Array(i);if(n===1)for(let[r,t]of e.entries())u[r]=[t];else for(let r=0;r<i;r+=1){let t=r*n;u[r]=e.slice(t,t+n)}return u}exports.a = l;
@@ -1 +0,0 @@
1
- import{a as n,c as a}from"./chunk-EPU4K3DD.js";import{a as t}from"./chunk-J6WPJH72.js";function l(...e){return t(p,e,u)}function p(e,r){return r<0?[...e]:e.slice(r)}function u(e){if(e<=0)return a;let r=e;return o=>r>0?(r-=1,n):{done:!1,hasNext:!0,next:o}}export{l as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkXR72I63Wcjs = require('./chunk-XR72I63W.cjs');function i(...e){return _chunkXR72I63Wcjs.a.call(void 0, u,e)}function u(e,a){let n=new Map;for(let[d,y]of e.entries()){let r=a(y,d,e);if(r!==void 0){let t=n.get(r);t===void 0?n.set(r,1):n.set(r,t+1)}}return Object.fromEntries(n)}exports.a = i;
@@ -1 +0,0 @@
1
- import{a as n}from"./chunk-EPU4K3DD.js";import{a as e}from"./chunk-J6WPJH72.js";function u(...a){return e(l,a,y)}function l(a,r){return a.filter(r)}function y(a){return(r,t,o)=>a(r,t,o)?{done:!1,hasNext:!0,next:r}:n}export{u as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkXR72I63Wcjs = require('./chunk-XR72I63W.cjs');function i(...e){return _chunkXR72I63Wcjs.a.call(void 0, a,e)}function a(e,o){let r={};for(let[y,t]of e.entries())r[t]=o(t,y,e);return r}exports.a = i;
@@ -1 +0,0 @@
1
- import{a}from"./chunk-J6WPJH72.js";function x(...e){return a(m,e)}function m(e,o,i){let t={};for(let[r,n]of e.entries()){let u=o(n,r,e),c=i(n,r,e);t[u]=c}return t}export{x as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkXR72I63Wcjs = require('./chunk-XR72I63W.cjs');function x(...e){return _chunkXR72I63Wcjs.a.call(void 0, m,e)}function m(e,o,i){let t={};for(let[r,n]of e.entries()){let u=o(n,r,e),c=i(n,r,e);t[u]=c}return t}exports.a = x;
@@ -1 +0,0 @@
1
- import{a as t}from"./chunk-J6WPJH72.js";function p(...e){return t(u,e)}function u(e,a){let n={};for(let[o,r]of Object.entries(e)){let y=a(o,r,e);n[y]=r}return n}export{p as a};
@@ -1,5 +0,0 @@
1
- import { I as IfBoundedRecord } from './if-bounded-record-Drd4UbBU.js';
2
-
3
- type ExactRecord<Key extends PropertyKey, Value> = IfBoundedRecord<Record<Key, Value>, Partial<Record<Key, Value>>, Record<Key, Value>>;
4
-
5
- export type { ExactRecord as E };
@@ -1,5 +0,0 @@
1
- import { I as IfBoundedRecord } from './if-bounded-record-Drd4UbBU.cjs';
2
-
3
- type ExactRecord<Key extends PropertyKey, Value> = IfBoundedRecord<Record<Key, Value>, Partial<Record<Key, Value>>, Record<Key, Value>>;
4
-
5
- export type { ExactRecord as E };
@@ -1,10 +0,0 @@
1
- /**
2
- * An array with *exactly* N elements in it.
3
- *
4
- * Only literal N values are supported. For very large N the type might result
5
- * in a recurse depth error. For negative N the type would result in an infinite
6
- * recursion. None of these have protections because this is an internal type!
7
- */
8
- type NTuple<T, N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : NTuple<T, N, [...Result, T]>;
9
-
10
- export type { NTuple as N };
@@ -1,10 +0,0 @@
1
- /**
2
- * An array with *exactly* N elements in it.
3
- *
4
- * Only literal N values are supported. For very large N the type might result
5
- * in a recurse depth error. For negative N the type would result in an infinite
6
- * recursion. None of these have protections because this is an internal type!
7
- */
8
- type NTuple<T, N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : NTuple<T, N, [...Result, T]>;
9
-
10
- export type { NTuple as N };
@@ -1 +0,0 @@
1
- "use strict";var _chunkZQXE6PIVcjs = require('./chunk-ZQXE6PIV.cjs');var _chunkWLNQOMKLcjs = require('./chunk-WLNQOMKL.cjs');var _chunkBO34ARLYcjs = require('./chunk-BO34ARLY.cjs');require('./chunk-N5JE6642.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');describe("data-first",()=>{test("empty array",()=>{let e=_chunkZQXE6PIVcjs.a.call(void 0, [],_chunkWLNQOMKLcjs.a.call(void 0, !0));expectTypeOf(e).toEqualTypeOf()}),test("regular array",()=>{let e=_chunkZQXE6PIVcjs.a.call(void 0, [],_chunkWLNQOMKLcjs.a.call(void 0, !0));expectTypeOf(e).toEqualTypeOf()}),test("regular array with union type",()=>{let e=_chunkZQXE6PIVcjs.a.call(void 0, [],_chunkWLNQOMKLcjs.a.call(void 0, !0));expectTypeOf(e).toEqualTypeOf()}),test("prefix array",()=>{let e=_chunkZQXE6PIVcjs.a.call(void 0, [1],_chunkWLNQOMKLcjs.a.call(void 0, !0));expectTypeOf(e).toEqualTypeOf()}),test("suffix array",()=>{let e=_chunkZQXE6PIVcjs.a.call(void 0, [1],_chunkWLNQOMKLcjs.a.call(void 0, !0));expectTypeOf(e).toEqualTypeOf()}),test("array with suffix and prefix",()=>{let e=_chunkZQXE6PIVcjs.a.call(void 0, [1,"a"],_chunkWLNQOMKLcjs.a.call(void 0, !0));expectTypeOf(e).toEqualTypeOf()}),test("tuple",()=>{let e=_chunkZQXE6PIVcjs.a.call(void 0, [1,"a",!0],_chunkWLNQOMKLcjs.a.call(void 0, !0));expectTypeOf(e).toEqualTypeOf()}),test("union of arrays",()=>{let e=_chunkZQXE6PIVcjs.a.call(void 0, [],_chunkWLNQOMKLcjs.a.call(void 0, !0));expectTypeOf(e).toEqualTypeOf()})});describe("data-last",()=>{test("empty array",()=>{let e=_chunkBO34ARLYcjs.a.call(void 0, [],_chunkZQXE6PIVcjs.a.call(void 0, _chunkWLNQOMKLcjs.a.call(void 0, !0)));expectTypeOf(e).toEqualTypeOf()}),test("regular array",()=>{let e=_chunkBO34ARLYcjs.a.call(void 0, [],_chunkZQXE6PIVcjs.a.call(void 0, _chunkWLNQOMKLcjs.a.call(void 0, !0)));expectTypeOf(e).toEqualTypeOf()}),test("regular array with union type",()=>{let e=_chunkBO34ARLYcjs.a.call(void 0, [],_chunkZQXE6PIVcjs.a.call(void 0, _chunkWLNQOMKLcjs.a.call(void 0, !0)));expectTypeOf(e).toEqualTypeOf()}),test("prefix array",()=>{let e=_chunkBO34ARLYcjs.a.call(void 0, [1],_chunkZQXE6PIVcjs.a.call(void 0, _chunkWLNQOMKLcjs.a.call(void 0, !0)));expectTypeOf(e).toEqualTypeOf()}),test("suffix array",()=>{let e=_chunkBO34ARLYcjs.a.call(void 0, [1],_chunkZQXE6PIVcjs.a.call(void 0, _chunkWLNQOMKLcjs.a.call(void 0, !0)));expectTypeOf(e).toEqualTypeOf()}),test("array with suffix and prefix",()=>{let e=_chunkBO34ARLYcjs.a.call(void 0, [1,"a"],_chunkZQXE6PIVcjs.a.call(void 0, _chunkWLNQOMKLcjs.a.call(void 0, !0)));expectTypeOf(e).toEqualTypeOf()}),test("tuple",()=>{let e=_chunkBO34ARLYcjs.a.call(void 0, [1,"a",!0],_chunkZQXE6PIVcjs.a.call(void 0, _chunkWLNQOMKLcjs.a.call(void 0, !0)));expectTypeOf(e).toEqualTypeOf()}),test("union of arrays",()=>{let e=_chunkBO34ARLYcjs.a.call(void 0, [],_chunkZQXE6PIVcjs.a.call(void 0, _chunkWLNQOMKLcjs.a.call(void 0, !0)));expectTypeOf(e).toEqualTypeOf()}),describe("predicate is typed correctly",()=>{test("empty array",()=>{_chunkBO34ARLYcjs.a.call(void 0, [],_chunkZQXE6PIVcjs.a.call(void 0, (e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("regular array",()=>{_chunkBO34ARLYcjs.a.call(void 0, [],_chunkZQXE6PIVcjs.a.call(void 0, (e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("regular array with union type",()=>{_chunkBO34ARLYcjs.a.call(void 0, [],_chunkZQXE6PIVcjs.a.call(void 0, (e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("prefix array",()=>{_chunkBO34ARLYcjs.a.call(void 0, [1],_chunkZQXE6PIVcjs.a.call(void 0, (e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("suffix array",()=>{_chunkBO34ARLYcjs.a.call(void 0, [1],_chunkZQXE6PIVcjs.a.call(void 0, (e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("array with suffix and prefix",()=>{_chunkBO34ARLYcjs.a.call(void 0, [1,"a"],_chunkZQXE6PIVcjs.a.call(void 0, (e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("tuple",()=>{_chunkBO34ARLYcjs.a.call(void 0, [1,"a",!0],_chunkZQXE6PIVcjs.a.call(void 0, (e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("union of arrays",()=>{_chunkBO34ARLYcjs.a.call(void 0, [],_chunkZQXE6PIVcjs.a.call(void 0, (e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))})})});
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1 +0,0 @@
1
- import{a as r}from"./chunk-3CFBQYOQ.js";import{a as t}from"./chunk-T5XG33UI.js";import{a}from"./chunk-QHBVEZSR.js";import"./chunk-EPU4K3DD.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";describe("data-first",()=>{test("empty array",()=>{let e=r([],t(!0));expectTypeOf(e).toEqualTypeOf()}),test("regular array",()=>{let e=r([],t(!0));expectTypeOf(e).toEqualTypeOf()}),test("regular array with union type",()=>{let e=r([],t(!0));expectTypeOf(e).toEqualTypeOf()}),test("prefix array",()=>{let e=r([1],t(!0));expectTypeOf(e).toEqualTypeOf()}),test("suffix array",()=>{let e=r([1],t(!0));expectTypeOf(e).toEqualTypeOf()}),test("array with suffix and prefix",()=>{let e=r([1,"a"],t(!0));expectTypeOf(e).toEqualTypeOf()}),test("tuple",()=>{let e=r([1,"a",!0],t(!0));expectTypeOf(e).toEqualTypeOf()}),test("union of arrays",()=>{let e=r([],t(!0));expectTypeOf(e).toEqualTypeOf()})});describe("data-last",()=>{test("empty array",()=>{let e=a([],r(t(!0)));expectTypeOf(e).toEqualTypeOf()}),test("regular array",()=>{let e=a([],r(t(!0)));expectTypeOf(e).toEqualTypeOf()}),test("regular array with union type",()=>{let e=a([],r(t(!0)));expectTypeOf(e).toEqualTypeOf()}),test("prefix array",()=>{let e=a([1],r(t(!0)));expectTypeOf(e).toEqualTypeOf()}),test("suffix array",()=>{let e=a([1],r(t(!0)));expectTypeOf(e).toEqualTypeOf()}),test("array with suffix and prefix",()=>{let e=a([1,"a"],r(t(!0)));expectTypeOf(e).toEqualTypeOf()}),test("tuple",()=>{let e=a([1,"a",!0],r(t(!0)));expectTypeOf(e).toEqualTypeOf()}),test("union of arrays",()=>{let e=a([],r(t(!0)));expectTypeOf(e).toEqualTypeOf()}),describe("predicate is typed correctly",()=>{test("empty array",()=>{a([],r((e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("regular array",()=>{a([],r((e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("regular array with union type",()=>{a([],r((e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("prefix array",()=>{a([1],r((e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("suffix array",()=>{a([1],r((e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("array with suffix and prefix",()=>{a([1,"a"],r((e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("tuple",()=>{a([1,"a",!0],r((e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))}),test("union of arrays",()=>{a([],r((e,u,y)=>(expectTypeOf(e).toEqualTypeOf(),expectTypeOf(u).toEqualTypeOf(),expectTypeOf(y).toEqualTypeOf(),!0)))})})});
@@ -1,37 +0,0 @@
1
- import { IsEqual } from 'type-fest';
2
-
3
- /**
4
- * Takes an array and returns the types that make up its parts. The prefix is
5
- * anything before the rest parameter (if any), split between it's required
6
- * part, and it's optional part. The suffix is anything after the rest
7
- * parameter (if any), and the item is the type of the rest parameter.
8
- *
9
- * NOTE: The prefix is split into 2 tuples where all items are non-optional so
10
- * that types that rely on the presence of a specific element can be built more
11
- * accurately.
12
- *
13
- * TODO: Some existing types use the `prefix` accessor which doesn't handle the optional part correctly. We need to fix each of those types before we can remove it.
14
- *
15
- * The output could be used to reconstruct the input: `[
16
- * ...TupleParts<T>["required"],
17
- * ...Partial<TupleParts<T>["optional"]>,
18
- * ...CoercedArray<TupleParts<T>["item"]>,
19
- * ...TupleParts<T>["suffix"],
20
- * ]`.
21
- */
22
- type TupleParts<T, PrefixRequired extends Array<unknown> = [], PrefixOptionals extends Array<unknown> = [], Suffix extends Array<unknown> = []> = T extends readonly [infer Head, ...infer Tail] ? TupleParts<Tail, [...PrefixRequired, Head], PrefixOptionals, Suffix> : T extends readonly [...infer Head, infer Tail] ? TupleParts<Head, PrefixRequired, PrefixOptionals, [Tail, ...Suffix]> : IsTupleRestOnly<T> extends true ? T extends ReadonlyArray<infer Item> ? {
23
- prefix: [...PrefixRequired, ...Partial<PrefixOptionals>];
24
- required: PrefixRequired;
25
- optional: PrefixOptionals;
26
- item: Item;
27
- suffix: Suffix;
28
- } : never : T extends readonly [(infer OptionalHead)?, ...infer Tail] ? TupleParts<Tail, PrefixRequired, [
29
- ...PrefixOptionals,
30
- OptionalHead
31
- ], Suffix> : never;
32
- /**
33
- * Helper type for `TupleParts`. Checks if T = ReadonlyArray<U> for some U.
34
- */
35
- type IsTupleRestOnly<T> = T extends readonly [] ? true : T extends readonly [unknown?, ...infer Tail] ? IsEqual<Readonly<T>, Readonly<Tail>> : false;
36
-
37
- export type { TupleParts as T };
@@ -1,37 +0,0 @@
1
- import { IsEqual } from 'type-fest';
2
-
3
- /**
4
- * Takes an array and returns the types that make up its parts. The prefix is
5
- * anything before the rest parameter (if any), split between it's required
6
- * part, and it's optional part. The suffix is anything after the rest
7
- * parameter (if any), and the item is the type of the rest parameter.
8
- *
9
- * NOTE: The prefix is split into 2 tuples where all items are non-optional so
10
- * that types that rely on the presence of a specific element can be built more
11
- * accurately.
12
- *
13
- * TODO: Some existing types use the `prefix` accessor which doesn't handle the optional part correctly. We need to fix each of those types before we can remove it.
14
- *
15
- * The output could be used to reconstruct the input: `[
16
- * ...TupleParts<T>["required"],
17
- * ...Partial<TupleParts<T>["optional"]>,
18
- * ...CoercedArray<TupleParts<T>["item"]>,
19
- * ...TupleParts<T>["suffix"],
20
- * ]`.
21
- */
22
- type TupleParts<T, PrefixRequired extends Array<unknown> = [], PrefixOptionals extends Array<unknown> = [], Suffix extends Array<unknown> = []> = T extends readonly [infer Head, ...infer Tail] ? TupleParts<Tail, [...PrefixRequired, Head], PrefixOptionals, Suffix> : T extends readonly [...infer Head, infer Tail] ? TupleParts<Head, PrefixRequired, PrefixOptionals, [Tail, ...Suffix]> : IsTupleRestOnly<T> extends true ? T extends ReadonlyArray<infer Item> ? {
23
- prefix: [...PrefixRequired, ...Partial<PrefixOptionals>];
24
- required: PrefixRequired;
25
- optional: PrefixOptionals;
26
- item: Item;
27
- suffix: Suffix;
28
- } : never : T extends readonly [(infer OptionalHead)?, ...infer Tail] ? TupleParts<Tail, PrefixRequired, [
29
- ...PrefixOptionals,
30
- OptionalHead
31
- ], Suffix> : never;
32
- /**
33
- * Helper type for `TupleParts`. Checks if T = ReadonlyArray<U> for some U.
34
- */
35
- type IsTupleRestOnly<T> = T extends readonly [] ? true : T extends readonly [unknown?, ...infer Tail] ? IsEqual<Readonly<T>, Readonly<Tail>> : false;
36
-
37
- export type { TupleParts as T };