type-plus 7.4.0 → 7.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 (202) hide show
  1. package/README.md +81 -92
  2. package/cjs/array/array.entries.d.ts +4 -3
  3. package/cjs/array/array.entries.d.ts.map +1 -1
  4. package/cjs/array/array_index.d.ts +4 -1
  5. package/cjs/array/array_index.d.ts.map +1 -1
  6. package/cjs/array/array_plus.common_prop_keys.d.ts +27 -0
  7. package/cjs/array/array_plus.common_prop_keys.d.ts.map +1 -0
  8. package/cjs/array/array_plus.common_prop_keys.js +3 -0
  9. package/cjs/array/array_plus.common_prop_keys.js.map +1 -0
  10. package/cjs/array/array_plus.d.ts +6 -3
  11. package/cjs/array/array_plus.d.ts.map +1 -1
  12. package/cjs/array/array_plus.drop_match.d.ts +4 -0
  13. package/cjs/array/array_plus.drop_match.d.ts.map +1 -0
  14. package/cjs/array/array_plus.drop_match.js +3 -0
  15. package/cjs/array/array_plus.drop_match.js.map +1 -0
  16. package/cjs/array/array_plus.element_match.d.ts +44 -0
  17. package/cjs/array/array_plus.element_match.d.ts.map +1 -0
  18. package/cjs/array/array_plus.element_match.js +3 -0
  19. package/cjs/array/array_plus.element_match.js.map +1 -0
  20. package/cjs/array/array_plus.find.d.ts +57 -0
  21. package/cjs/array/array_plus.find.d.ts.map +1 -0
  22. package/cjs/array/array_plus.find.js +3 -0
  23. package/cjs/array/array_plus.find.js.map +1 -0
  24. package/cjs/array/array_plus.split_at.d.ts +20 -15
  25. package/cjs/array/array_plus.split_at.d.ts.map +1 -1
  26. package/cjs/array/find_first.d.ts +62 -0
  27. package/cjs/array/find_first.d.ts.map +1 -0
  28. package/cjs/array/{array.find.js → find_first.js} +1 -1
  29. package/cjs/array/find_first.js.map +1 -0
  30. package/cjs/array/head.d.ts +18 -6
  31. package/cjs/array/head.d.ts.map +1 -1
  32. package/cjs/array/last.d.ts +17 -6
  33. package/cjs/array/last.d.ts.map +1 -1
  34. package/cjs/assertion/assert_type.d.ts +4 -1
  35. package/cjs/assertion/assert_type.d.ts.map +1 -1
  36. package/cjs/assertion/assert_type.js.map +1 -1
  37. package/cjs/index.d.ts +5 -2
  38. package/cjs/index.d.ts.map +1 -1
  39. package/cjs/index.js.map +1 -1
  40. package/cjs/never/never_type.d.ts +11 -0
  41. package/cjs/never/never_type.d.ts.map +1 -1
  42. package/cjs/object/index.d.ts +0 -1
  43. package/cjs/object/index.d.ts.map +1 -1
  44. package/cjs/object/index.js.map +1 -1
  45. package/cjs/testing/test_type.d.ts +277 -276
  46. package/cjs/testing/test_type.d.ts.map +1 -1
  47. package/cjs/testing/test_type.js.map +1 -1
  48. package/cjs/tuple/common_prop_keys.d.ts +15 -10
  49. package/cjs/tuple/common_prop_keys.d.ts.map +1 -1
  50. package/cjs/tuple/drop.d.ts +45 -26
  51. package/cjs/tuple/drop.d.ts.map +1 -1
  52. package/cjs/tuple/drop.js.map +1 -1
  53. package/cjs/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
  54. package/cjs/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
  55. package/cjs/tuple/tuple_plus.common_prop_keys.js +3 -0
  56. package/cjs/tuple/tuple_plus.common_prop_keys.js.map +1 -0
  57. package/cjs/tuple/tuple_plus.d.ts +3 -0
  58. package/cjs/tuple/tuple_plus.d.ts.map +1 -1
  59. package/cjs/tuple/tuple_plus.drop_match.d.ts +6 -0
  60. package/cjs/tuple/tuple_plus.drop_match.d.ts.map +1 -0
  61. package/cjs/tuple/tuple_plus.drop_match.js +3 -0
  62. package/cjs/tuple/tuple_plus.drop_match.js.map +1 -0
  63. package/cjs/tuple/tuple_plus.filter.d.ts +2 -2
  64. package/cjs/tuple/tuple_plus.find.d.ts +64 -0
  65. package/cjs/tuple/tuple_plus.find.d.ts.map +1 -0
  66. package/cjs/tuple/tuple_plus.find.js +3 -0
  67. package/cjs/tuple/tuple_plus.find.js.map +1 -0
  68. package/cjs/tuple/tuple_plus.pad_start.d.ts +7 -6
  69. package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -1
  70. package/cjs/tuple/tuple_type.d.ts +41 -23
  71. package/cjs/tuple/tuple_type.d.ts.map +1 -1
  72. package/cjs/union/union.d.ts +33 -0
  73. package/cjs/union/union.d.ts.map +1 -0
  74. package/cjs/union/union.js +3 -0
  75. package/cjs/union/union.js.map +1 -0
  76. package/cjs/unknown/unknown_type.d.ts +12 -0
  77. package/cjs/unknown/unknown_type.d.ts.map +1 -1
  78. package/cjs/utils/options.d.ts +10 -0
  79. package/cjs/utils/options.d.ts.map +1 -0
  80. package/cjs/utils/options.js +3 -0
  81. package/cjs/utils/options.js.map +1 -0
  82. package/esm/array/array.entries.d.ts +4 -3
  83. package/esm/array/array.entries.d.ts.map +1 -1
  84. package/esm/array/array_index.d.ts +4 -1
  85. package/esm/array/array_index.d.ts.map +1 -1
  86. package/esm/array/array_plus.common_prop_keys.d.ts +27 -0
  87. package/esm/array/array_plus.common_prop_keys.d.ts.map +1 -0
  88. package/esm/array/array_plus.common_prop_keys.js +2 -0
  89. package/esm/array/array_plus.common_prop_keys.js.map +1 -0
  90. package/esm/array/array_plus.d.ts +6 -3
  91. package/esm/array/array_plus.d.ts.map +1 -1
  92. package/esm/array/array_plus.drop_match.d.ts +4 -0
  93. package/esm/array/array_plus.drop_match.d.ts.map +1 -0
  94. package/esm/array/array_plus.drop_match.js +2 -0
  95. package/esm/array/array_plus.drop_match.js.map +1 -0
  96. package/esm/array/array_plus.element_match.d.ts +44 -0
  97. package/esm/array/array_plus.element_match.d.ts.map +1 -0
  98. package/esm/array/array_plus.element_match.js +2 -0
  99. package/esm/array/array_plus.element_match.js.map +1 -0
  100. package/esm/array/array_plus.find.d.ts +57 -0
  101. package/esm/array/array_plus.find.d.ts.map +1 -0
  102. package/esm/array/array_plus.find.js +2 -0
  103. package/esm/array/array_plus.find.js.map +1 -0
  104. package/esm/array/array_plus.split_at.d.ts +20 -15
  105. package/esm/array/array_plus.split_at.d.ts.map +1 -1
  106. package/esm/array/find_first.d.ts +62 -0
  107. package/esm/array/find_first.d.ts.map +1 -0
  108. package/esm/array/find_first.js +2 -0
  109. package/esm/array/find_first.js.map +1 -0
  110. package/esm/array/head.d.ts +18 -6
  111. package/esm/array/head.d.ts.map +1 -1
  112. package/esm/array/last.d.ts +17 -6
  113. package/esm/array/last.d.ts.map +1 -1
  114. package/esm/assertion/assert_type.d.ts +4 -1
  115. package/esm/assertion/assert_type.d.ts.map +1 -1
  116. package/esm/assertion/assert_type.js.map +1 -1
  117. package/esm/index.d.ts +5 -2
  118. package/esm/index.d.ts.map +1 -1
  119. package/esm/index.js.map +1 -1
  120. package/esm/never/never_type.d.ts +11 -0
  121. package/esm/never/never_type.d.ts.map +1 -1
  122. package/esm/object/index.d.ts +0 -1
  123. package/esm/object/index.d.ts.map +1 -1
  124. package/esm/object/index.js.map +1 -1
  125. package/esm/testing/test_type.d.ts +277 -276
  126. package/esm/testing/test_type.d.ts.map +1 -1
  127. package/esm/testing/test_type.js.map +1 -1
  128. package/esm/tuple/common_prop_keys.d.ts +15 -10
  129. package/esm/tuple/common_prop_keys.d.ts.map +1 -1
  130. package/esm/tuple/drop.d.ts +45 -26
  131. package/esm/tuple/drop.d.ts.map +1 -1
  132. package/esm/tuple/drop.js.map +1 -1
  133. package/esm/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
  134. package/esm/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
  135. package/esm/tuple/tuple_plus.common_prop_keys.js +2 -0
  136. package/esm/tuple/tuple_plus.common_prop_keys.js.map +1 -0
  137. package/esm/tuple/tuple_plus.d.ts +3 -0
  138. package/esm/tuple/tuple_plus.d.ts.map +1 -1
  139. package/esm/tuple/tuple_plus.drop_match.d.ts +6 -0
  140. package/esm/tuple/tuple_plus.drop_match.d.ts.map +1 -0
  141. package/esm/tuple/tuple_plus.drop_match.js +2 -0
  142. package/esm/tuple/tuple_plus.drop_match.js.map +1 -0
  143. package/esm/tuple/tuple_plus.filter.d.ts +2 -2
  144. package/esm/tuple/tuple_plus.find.d.ts +64 -0
  145. package/esm/tuple/tuple_plus.find.d.ts.map +1 -0
  146. package/esm/tuple/tuple_plus.find.js +2 -0
  147. package/esm/tuple/tuple_plus.find.js.map +1 -0
  148. package/esm/tuple/tuple_plus.pad_start.d.ts +7 -6
  149. package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -1
  150. package/esm/tuple/tuple_type.d.ts +41 -23
  151. package/esm/tuple/tuple_type.d.ts.map +1 -1
  152. package/esm/union/union.d.ts +33 -0
  153. package/esm/union/union.d.ts.map +1 -0
  154. package/esm/union/union.js +2 -0
  155. package/esm/union/union.js.map +1 -0
  156. package/esm/unknown/unknown_type.d.ts +12 -0
  157. package/esm/unknown/unknown_type.d.ts.map +1 -1
  158. package/esm/utils/options.d.ts +10 -0
  159. package/esm/utils/options.d.ts.map +1 -0
  160. package/esm/utils/options.js +2 -0
  161. package/esm/utils/options.js.map +1 -0
  162. package/package.json +12 -1
  163. package/ts/array/array.entries.ts +4 -2
  164. package/ts/array/array_index.ts +33 -23
  165. package/ts/array/array_plus.common_prop_keys.ts +35 -0
  166. package/ts/array/array_plus.drop_match.ts +16 -0
  167. package/ts/array/array_plus.element_match.ts +61 -0
  168. package/ts/array/array_plus.find.ts +71 -0
  169. package/ts/array/array_plus.split_at.ts +52 -23
  170. package/ts/array/array_plus.ts +6 -3
  171. package/ts/array/find_first.ts +71 -0
  172. package/ts/array/head.ts +28 -6
  173. package/ts/array/last.ts +26 -6
  174. package/ts/array/readme.md +152 -32
  175. package/ts/assertion/assert_type.ts +4 -1
  176. package/ts/assertion/readme.md +3 -2
  177. package/ts/index.ts +5 -5
  178. package/ts/never/never_type.ts +13 -0
  179. package/ts/object/index.ts +0 -1
  180. package/ts/testing/test_type.ts +279 -277
  181. package/ts/tuple/common_prop_keys.ts +18 -32
  182. package/ts/tuple/drop.ts +61 -60
  183. package/ts/tuple/readme.md +178 -39
  184. package/ts/tuple/tuple_plus.common_prop_keys.ts +47 -0
  185. package/ts/tuple/tuple_plus.drop_match.ts +20 -0
  186. package/ts/tuple/tuple_plus.filter.ts +2 -2
  187. package/ts/tuple/tuple_plus.find.ts +88 -0
  188. package/ts/tuple/tuple_plus.pad_start.ts +28 -25
  189. package/ts/tuple/tuple_plus.ts +3 -0
  190. package/ts/tuple/tuple_type.ts +67 -25
  191. package/ts/union/readme.md +81 -0
  192. package/ts/union/union.ts +37 -0
  193. package/ts/unknown/unknown_type.ts +13 -0
  194. package/ts/utils/options.ts +10 -0
  195. package/cjs/array/array.find.d.ts +0 -23
  196. package/cjs/array/array.find.d.ts.map +0 -1
  197. package/cjs/array/array.find.js.map +0 -1
  198. package/esm/array/array.find.d.ts +0 -23
  199. package/esm/array/array.find.d.ts.map +0 -1
  200. package/esm/array/array.find.js +0 -2
  201. package/esm/array/array.find.js.map +0 -1
  202. package/ts/array/array.find.ts +0 -34
@@ -12,7 +12,7 @@ and each element has the same type `T`.
12
12
  The `ArrayType<T>` and friends are used to check if a type is exactly `Array<T>` or not.
13
13
 
14
14
  They are strict type checks, meaning they match only the type `Array<T>`,
15
- and not [tuple], union, or intersection types.
15
+ and not [tuple], [union], or intersection types.
16
16
 
17
17
  ### [ArrayType](./array_type.ts#18)
18
18
 
@@ -83,7 +83,7 @@ type R = IsNotArrayType<number> // true
83
83
  type R = IsNotArrayType<[1]> // true
84
84
  ```
85
85
 
86
- ## [At](./array.at.ts)
86
+ ## [At](./array.at.ts#l20)
87
87
 
88
88
  `At<A, N, Fail = never>`
89
89
 
@@ -97,7 +97,7 @@ as there is no way to guarantee the array has value at `N`.
97
97
  ```ts
98
98
  type A = Array<string | number>
99
99
 
100
- ArrayPlus.At<A, 0> // string | number | undefined
100
+ type R = ArrayPlus.At<A, 0> // string | number | undefined
101
101
  ```
102
102
 
103
103
  For tuple, it will return the type of the tuple value at index `N`.
@@ -105,8 +105,8 @@ For tuple, it will return the type of the tuple value at index `N`.
105
105
  ```ts
106
106
  type T = [number, string, 1, 2, 3]
107
107
 
108
- ArrayPlus.At<T, 0> // number
109
- ArrayPlus.At<T, -1> // 3
108
+ type R = ArrayPlus.At<T, 0> // number
109
+ type R = ArrayPlus.At<T, -1> // 3
110
110
  ```
111
111
 
112
112
  If the `N` is out of bound,
@@ -127,9 +127,41 @@ It is added for completeness.
127
127
 
128
128
  You are encouraged to use `[...A, ...B]` directly.
129
129
 
130
- ## [`FindFirst`](./array.find.ts)
130
+ ## [`FindFirst`](./find_first.ts#l52)
131
131
 
132
- ## [`FineLast`](./array.find_last.ts)
132
+ `FindFirst<A, Criteria, Options = { widen, caseEmptyTuple, caseNever, caseNoMatch, caseWiden, caseUnionMiss }>`
133
+
134
+ 🦴 *utilities*
135
+ 🔢 *customizable*
136
+
137
+ Find the first type in the array or tuple `A` that matches `Criteria`.
138
+
139
+ ```ts
140
+ import type { FindFirst } from 'type-plus'
141
+
142
+ type R = FindFirst<[true, 1, 'x', 3], string> // 'x'
143
+ type R = FindFirst<[true, 1, 'x', 3], number> // 1
144
+ type R = FindFirst<[string, number, 1], 1> // widen: 1 | undefined
145
+ type R = FindFirst<[true, number | string], string> // unionNotMatch: string
146
+ type R = FindFirst<Array<string>, string> // string
147
+ type R = FindFirst<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
148
+ type R = FindFirst<Array<string | number>, number | string> // string | number
149
+ type R = FindFirst<Array<number>, 1> // widen: 1 | undefined
150
+ type R = FindFirst<Array<string | number>, number> // unionNotMatch: number
151
+
152
+ type R = FindFirst<[true, 1, 'x'], 2> // never
153
+ type R = FindFirst<string[], number> // never
154
+
155
+ // customization
156
+ type R = FindFirst<[number], 1, { widen: false }> // never
157
+ type R = FindFirst<[number], 1, { caseWiden: never }> // never
158
+ type R = FindFirst<[], 1, { caseEmptyTuple: 2 }> // 2
159
+ type R = FindFirst<never, 1, { caseNever: 2 }> // 2
160
+ type R = FindFirst<[string], number, { caseNotMatch: 2 }> // 2
161
+ type R = FindFirst<[string | number], number, { caseUnionNotMatch: undefined }> // number | undefined
162
+ ```
163
+
164
+ ## [`FindLast`](./array.find_last.ts)
133
165
 
134
166
  ## [`Some`](./array.some.ts)
135
167
 
@@ -164,42 +196,52 @@ type R = KeepMatch<[1, 2, '3'], number> // [1, 2]
164
196
  type R = KeepMatch<Array<string | undefined>, string> // string[]
165
197
  ```
166
198
 
167
- ## [`Head`](./head.ts#l14)
199
+ ## [`Head`](./head.ts#l23)
168
200
 
169
- `Head<T, Cases = { empty_tuple }>`
201
+ `Head<T, Options = { caseNever, caseEmptyTuple }>`
170
202
 
171
203
  🦴 *utilities*
204
+ 🔢 *customizable*
172
205
 
173
- Gets the first entry in the tuple or the type of array.
206
+ Gets the first entry in the tuple or the type of array `T`.
174
207
 
175
208
  ```ts
176
209
  import type { Head } from 'type-plus'
177
210
 
178
211
  type R = Head<[1, 2, 3]> // 1
179
212
  type R = Head<string[]> // string
213
+ type R = Head<never> // caseNever: never
214
+ type R = Head<[]> // caseEmptyTuple: never
180
215
 
181
- type R = Head<[]> // never
216
+ // customization
217
+ type R = Head<never, { caseNever: 1 }> // 1
218
+ type R = Head<[], { caseEmptyTuple: undefined }> // undefined
182
219
  ```
183
220
 
184
221
  ## [`IntersectOfProps`](./intersect_of_props.ts)
185
222
 
186
223
  ## [`MapToProp`](./intersect_of_props.ts)
187
224
 
188
- ## [`Last`](./last.ts)
225
+ ## [`Last`](./last.ts#l23)
189
226
 
190
- `Last<T, Cases = { empty_tuple }>`
227
+ `Last<T, Options = { caseNever, caseEmptyTuple }>`
191
228
 
192
229
  🦴 *utilities*
230
+ 🔢 *customizable*
193
231
 
194
- Gets the last entry in the tuple or the type of array.
232
+ Gets the last entry in the tuple or the type of array `T`.
195
233
 
196
234
  ```ts
197
235
  import type { Last } from 'type-plus'
198
236
 
199
237
  type R = Last<[1, 2, 3]> // 3
200
238
  type R = Last<string[]> // string
239
+ type R = Last<never> // caseNever: never
240
+ type R = Last<[]> // caseEmptyTuple: never
201
241
 
202
- type R = Last<[]> // never
242
+ // customization
243
+ type R = Last<never, { caseNever: 1 }> // 1
244
+ type R = Last<[], { caseEmptyTuple: undefined }> // undefined
203
245
  ```
204
246
 
205
247
  ## [`literalArray`](./literal_array.ts)
@@ -231,12 +273,56 @@ please check [`TuplePlus`](../tuple/readme.md#TuplePlus).
231
273
 
232
274
  Alias of [At](#at).
233
275
 
234
- ### [`ArrayPlus.Concat`](./array.concat.ts#L12)
276
+ ## [ArrayPlus.CommonPropKeys](./array_plus.common_prop_keys.ts#l21)
277
+
278
+ `ArrayPlus.CommonPropKeys<T extends Record[], Options = { caseNever }>`
279
+
280
+ ⚗️ *transform*
281
+ 🔢 *customizable*
282
+
283
+ Gets the common property keys of the elements in array `A`.
284
+
285
+ ```ts
286
+ import { type ArrayPlus } from 'type-plus'
287
+
288
+ type R = ArrayPlus.CommonPropKeys<Array<{ a: 1 }>> // 'a'
289
+ type R = ArrayPlus.CommonPropKeys<Array<{ a: 1, b: 1 } | { a: 1, c: 1 }>> // 'a'
290
+
291
+ // customization
292
+ type R = ArrayPlus.CommonPropKeys<never, { caseNever: 1 }> // 1
293
+ ```
294
+
295
+ ### [`ArrayPlus.Concat`](./array.concat.ts#l12)
235
296
 
236
297
  `ArrayPlus.Concat<A, B>`
237
298
 
238
299
  Alias of [Concat](#concat).
239
300
 
301
+ ### [`ArrayPlus.ElementMatch`](./array_plus.element_match.ts#l30)
302
+
303
+ `ArrayPlus.ElementMatch<T, Criteria, Options = { widen, caseNotMatch, caseWiden, caseUnionNotMatch }>`
304
+
305
+ 🌪️ *filter*
306
+ 🔢 *customizable*
307
+
308
+ Filter the element `T` in an array or tuple to match `Criteria`.
309
+
310
+ ```ts
311
+ import type { ArrayPlus } from 'type-plus'
312
+
313
+ type R = ArrayPlus.ElementMatch<number, number> // number
314
+ type R = ArrayPlus.ElementMatch<1, number> // 1
315
+ type R = ArrayPlus.ElementMatch<number, string> // notMatch: never
316
+ type R = ArrayPlus.ElementMatch<number, 1> // widen: 1
317
+ type R = ArrayPlus.ElementMatch<number | string, number> // unionNotMatch: number
318
+
319
+ // customization
320
+ type R = ArrayPlus.ElementMatch<number, string, { caseNotMatch: 1 }> // 1
321
+ type R = ArrayPlus.ElementMatch<number, 1, { widen: false }> // never
322
+ type R = ArrayPlus.ElementMatch<number, 1, { caseWiden: never }> // never
323
+ type R = ArrayPlus.ElementMatch<number | string, number, { caseUnionNotMatch: undefined }> // number | undefined
324
+ ```
325
+
240
326
  ### [`ArrayPlus.Entries`](./array.entries.ts#L14)
241
327
 
242
328
  > `ArrayPlus.Entries<A>`
@@ -247,24 +333,37 @@ Note that this is not the same as `Array.entries(A)`,
247
333
  which returns an iterable interator.
248
334
 
249
335
  ```ts
250
- ArrayPlus.Entries<Array<string | number>> // Array<[number, string | number]>
251
- ArrayPlus.Entries<[1, 2, 3]> // [[0, 1], [1, 2], [2, 3]]
336
+ type R = ArrayPlus.Entries<Array<string | number>> // Array<[number, string | number]>
337
+ type R = ArrayPlus.Entries<[1, 2, 3]> // [[0, 1], [1, 2], [2, 3]]
252
338
  ```
253
339
 
254
- ### [`ArrayPlus.Find`](./array.find.ts#L17)
255
-
256
- > `ArrayPlus.Find<A, Criteria>
340
+ ### [`ArrayPlus.Find`](./array_plus.find.ts#l49)
257
341
 
258
- Returns the first type in the array or tuple that matches the `Criteria`.
342
+ `ArrayPlus.Find<A, Criteria, Options { widen, caseNever, caseNotMatch, caseTuple, caseWiden, caseUnionNotMatch }>`
259
343
 
260
- If the `Criteria` is not met, it will return `never'.
344
+ 🦴 *utilities*
345
+ 🔢 *customizable*
261
346
 
262
- For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
347
+ Finds the type in array `A` that matches `Criteria`.
263
348
 
264
349
  ```ts
265
- ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
266
-
267
- ArrayPlus.Find<[true, 1, 'x', 3], string> // 'x'
350
+ import type { ArrayPlus } from 'type-plus'
351
+
352
+ type R = ArrayPlus.Find<Array<string>, string> // string
353
+ type R = ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
354
+ type R = ArrayPlus.Find<Array<string | number>, number | string> // string | number
355
+ type R = ArrayPlus.Find<number[], 1> // widen: 1 | undefined
356
+ type R = ArrayPlus.Find<Array<string | number>, number> // unionNotMatch: number
357
+
358
+ type R = ArrayPlus.Find<string[], number> // never
359
+
360
+ // customization
361
+ type R = ArrayPlus.Find<number[], 1, { widen: false }> // never
362
+ type R = ArrayPlus.Find<number[], 1, { caseWiden: never }> // never
363
+ type R = ArrayPlus.Find<never, 1, { caseNever: 2 }> // 2
364
+ type R = ArrayPlus.Find<string[], number, { caseNotMatch: 2 }> // 2
365
+ type R = ArrayPlus.Find<[], 1, { caseTuple: 2 }> // 2
366
+ type R = ArrayPlus.Find<Array<string | number>, number, { caseUnionNotMatch: undefined }> // number | undefined
268
367
  ```
269
368
 
270
369
  ### [`ArrayPlus.FindLast`](./array.find_last.ts#L17)
@@ -295,12 +394,28 @@ ArrayPlus.Reverse<[1, 2, 3]> // [3, 2, 1]
295
394
 
296
395
  ### [`ArrayPlus.SplitAt`](./array_plus.split_at.ts#L22)
297
396
 
298
- > `ArrayPlus.SplitAt<A, Index>`
397
+ `ArrayPlus.SplitAt<A, Index>`
398
+
399
+ ⚗️ *transform*
400
+
401
+ Splits array or tuple `A` into two at the specified `Index`.
402
+
403
+ If the `Index` is out of bounds,
404
+ it will set to the boundary value.
299
405
 
300
- Splits the array or tuple at `Index`.
406
+ It is the type level `splice()`.
301
407
 
302
408
  ```ts
303
- ArrayPlus.SplitAt<[1, 2, 3], 1> // [[1, 2], [3]]
409
+ SplitAt<[1, 2, 3, 4, 5], 2> // [[1, 2], [3, 4, 5]]
410
+ SplitAt<[1, 2, 3, 4, 5], -3> // [[1, 2], [3, 4, 5]]
411
+
412
+ SplitAt<[1, 2, 3, 4, 5], 2, 2> // [[1, 2, 5], [3, 4]]
413
+
414
+ SplitAt<[1, 2, 3, 4, 5], 2, 2, ['a', 'b']> // [[1, 2, 'a', 'b', 5], [3, 4]]
415
+
416
+ // out of bound resets to boundary
417
+ SplitAt<[1, 2, 3, 4, 5], 6> // [[1, 2, 3, 4, 5], []]
418
+ SplitAt<[1, 2, 3, 4, 5], -6> // [[], [1, 2, 3, 4, 5]]
304
419
  ```
305
420
 
306
421
  ### [`ArrayPlus.Some`](./array.some.ts#L23)
@@ -339,7 +454,11 @@ or with reduced capability.
339
454
  They are exposed under the `ArrayPlus` namespace,
340
455
  while some common ones are exposed at top-level.
341
456
 
342
- Here are the list of array methods and their corresponding type-level functions, if availableL
457
+ Here are the list of array methods and their corresponding type-level functions, if available.
458
+
459
+ ✅ means it is implemented.
460
+ ✴️ means it is implemented with reduced functionality
461
+ 🧬 means there is a built-in mechanism or type for it.
343
462
 
344
463
  - ✅ `at`: [`ArrayPlus.At`](#arrayplusat)
345
464
  - ✅ `concat`: [`Concat` | `ArrayPlus.Concat`](#arrayplusconcat) (`[...A, ...B]`)
@@ -365,7 +484,7 @@ Here are the list of array methods and their corresponding type-level functions,
365
484
  - 🚧 `slice`:
366
485
  - ✴️ `some`: [`Some` | `ArrayPlus.Some`](#arrayplussome)
367
486
  - 🚧 `sort`:
368
- - 🚧 `splice`:
487
+ - ✴️ `splice`: [`ArrayPlus.SplitAt`](#arrayplussplitat)
369
488
  - 🧬 `unshift`: `[T, ...A]`
370
489
  - 🧬 `values`: `keyof A`
371
490
 
@@ -375,3 +494,4 @@ Here are the list of array methods and their corresponding type-level functions,
375
494
 
376
495
  [handbook]: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#arrays
377
496
  [tuple]: ../tuple/readme.md
497
+ [union]: ../union/readme.md
@@ -3,7 +3,10 @@ import { isConstructor, type AnyConstructor } from '../class/index.js'
3
3
  import { type AnyFunction } from '../function/any_function.js'
4
4
 
5
5
  /**
6
- * assert the subject satisfies the specified type T
6
+ * 💥 *immediate*
7
+ * 🚦 *assertion*
8
+ *
9
+ * Assert the subject satisfies the specified type T
7
10
  * @type T the type to check against.
8
11
  */
9
12
  export function assertType<T>(subject: T): asserts subject is T
@@ -9,11 +9,12 @@ They throw an error if the condition is not met, and return nothing otherwise.
9
9
  These assertion functions are typically used in runtime,
10
10
  so that that type of the value can be narrowed down.
11
11
 
12
- ## [assertType](./assert_type.ts)
12
+ ## [assertType](./assert_type.ts#l10)
13
13
 
14
14
  `assertType<T>(subject)`
15
15
 
16
- 💥 `immediate`
16
+ 💥 *immediate*
17
+ 🚦 *assertion*
17
18
 
18
19
  It ensures `subject` satisfies `T`.
19
20
  It is similar to `const x: T = subject` without introducing an unused variable.
package/ts/index.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export type { AnyType, IsAny, IsNotAny, NotAnyType } from './any/any_type.js'
2
2
  export type { At } from './array/array.at.js'
3
- export type { FindFirst } from './array/array.find.js'
4
3
  export type { FindLast } from './array/array.find_last.js'
5
4
  export type { Some } from './array/array.some.js'
6
5
  export type { Concat } from './array/array_plus.concat.js'
7
6
  export * as ArrayPlus from './array/array_plus.js'
8
7
  export type { ArrayType, IsArray, IsNotArray, NotArrayType } from './array/array_type.js'
9
8
  export type { Filter, KeepMatch } from './array/filter.js'
9
+ export type { FindFirst } from './array/find_first.js'
10
10
  export type { Head } from './array/head.js'
11
11
  export type { IntersectOfProps, MapToProp } from './array/intersect_of_props.js'
12
12
  export type { Last } from './array/last.js'
@@ -77,6 +77,7 @@ export type {
77
77
  Zero
78
78
  } from './numeric/numeric_type.js'
79
79
  export type { IsNotPositive, IsPositive, NonPositive, Positive } from './numeric/positive.js'
80
+ export type { Required, RequiredExcept, RequiredPick } from './object/Required.js'
80
81
  export * from './object/index.js'
81
82
  export type { IsNotObject, IsObject, NotObjectType, ObjectType } from './object/object_type.js'
82
83
  export * from './predicates/index.js'
@@ -94,7 +95,7 @@ export type { IsNotString, IsString, NotStringType, StringType } from './string/
94
95
  export type { IsNotSymbol, IsSymbol, NotSymbolType, SymbolType } from './symbol/symbol_type.js'
95
96
  export * from './testing/stub.js'
96
97
  export * from './testing/test_type.js'
97
- export type { CommonPropKeys } from './tuple/common_prop_keys.js'
98
+ export type { CommonKeys, CommonPropKeys } from './tuple/common_prop_keys.js'
98
99
  export * from './tuple/create_tuple.js'
99
100
  export { drop } from './tuple/drop.js'
100
101
  export type { DropFirst, DropLast, DropMatch, DropNull, DropNullable, DropUndefined } from './tuple/drop.js'
@@ -110,12 +111,11 @@ export type {
110
111
  NotUndefinedType,
111
112
  UndefinedType
112
113
  } from './undefined/undefined_type.js'
114
+ export type { IsUnion, UnionType } from './union/union.js'
113
115
  export type { UnionKeys } from './union_keys.js'
114
116
  export type { IsNotUnknown, IsUnknown, NotUnknownType, UnknownType } from './unknown/unknown_type.js'
115
117
  export * from './unpartial.js'
116
118
  export * from './utils/index.js'
119
+ export type { MergeOptions as MergeCases } from './utils/options.js'
117
120
  export type { IsNotVoid, IsVoid, NotVoidType, VoidType } from './void/void_type.js'
118
121
 
119
-
120
-
121
-
@@ -55,3 +55,16 @@ export type IsNever<T, Then = true, Else = false> = NeverType<T, Then, Else>
55
55
  * type R = IsNotNever<never> // false
56
56
  */
57
57
  export type IsNotNever<T, Then = true, Else = false> = NeverType<T, Else, Then>
58
+
59
+ export namespace NeverType {
60
+ /**
61
+ * Type options when input type is `never`.
62
+ */
63
+ export interface Options {
64
+ caseNever?: unknown
65
+ }
66
+
67
+ export interface DefaultOptions {
68
+ caseNever: never
69
+ }
70
+ }
@@ -12,7 +12,6 @@ export type { Partial, PartialExcept, PartialOmit, PartialPick } from './Partial
12
12
  export type * from './optional_key.js'
13
13
  export type { RecursiveIntersect } from './RecursiveIntersect.js'
14
14
  export type { RecursiveRequired } from './RecursiveRequired.js'
15
- export type { RequiredExcept, RequiredPick } from './Required.js'
16
15
  export type { RequiredKeys } from './RequiredKeys.js'
17
16
  export type { SpreadRecord } from './SpreadRecord.js'
18
17
  export type { ValueOf } from './ValueOf.js'