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.
- package/README.md +81 -92
- package/cjs/array/array.entries.d.ts +4 -3
- package/cjs/array/array.entries.d.ts.map +1 -1
- package/cjs/array/array_index.d.ts +4 -1
- package/cjs/array/array_index.d.ts.map +1 -1
- package/cjs/array/array_plus.common_prop_keys.d.ts +27 -0
- package/cjs/array/array_plus.common_prop_keys.d.ts.map +1 -0
- package/cjs/array/array_plus.common_prop_keys.js +3 -0
- package/cjs/array/array_plus.common_prop_keys.js.map +1 -0
- package/cjs/array/array_plus.d.ts +6 -3
- package/cjs/array/array_plus.d.ts.map +1 -1
- package/cjs/array/array_plus.drop_match.d.ts +4 -0
- package/cjs/array/array_plus.drop_match.d.ts.map +1 -0
- package/cjs/array/array_plus.drop_match.js +3 -0
- package/cjs/array/array_plus.drop_match.js.map +1 -0
- package/cjs/array/array_plus.element_match.d.ts +44 -0
- package/cjs/array/array_plus.element_match.d.ts.map +1 -0
- package/cjs/array/array_plus.element_match.js +3 -0
- package/cjs/array/array_plus.element_match.js.map +1 -0
- package/cjs/array/array_plus.find.d.ts +57 -0
- package/cjs/array/array_plus.find.d.ts.map +1 -0
- package/cjs/array/array_plus.find.js +3 -0
- package/cjs/array/array_plus.find.js.map +1 -0
- package/cjs/array/array_plus.split_at.d.ts +20 -15
- package/cjs/array/array_plus.split_at.d.ts.map +1 -1
- package/cjs/array/find_first.d.ts +62 -0
- package/cjs/array/find_first.d.ts.map +1 -0
- package/cjs/array/{array.find.js → find_first.js} +1 -1
- package/cjs/array/find_first.js.map +1 -0
- package/cjs/array/head.d.ts +18 -6
- package/cjs/array/head.d.ts.map +1 -1
- package/cjs/array/last.d.ts +17 -6
- package/cjs/array/last.d.ts.map +1 -1
- package/cjs/assertion/assert_type.d.ts +4 -1
- package/cjs/assertion/assert_type.d.ts.map +1 -1
- package/cjs/assertion/assert_type.js.map +1 -1
- package/cjs/index.d.ts +5 -2
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/never/never_type.d.ts +11 -0
- package/cjs/never/never_type.d.ts.map +1 -1
- package/cjs/object/index.d.ts +0 -1
- package/cjs/object/index.d.ts.map +1 -1
- package/cjs/object/index.js.map +1 -1
- package/cjs/testing/test_type.d.ts +277 -276
- package/cjs/testing/test_type.d.ts.map +1 -1
- package/cjs/testing/test_type.js.map +1 -1
- package/cjs/tuple/common_prop_keys.d.ts +15 -10
- package/cjs/tuple/common_prop_keys.d.ts.map +1 -1
- package/cjs/tuple/drop.d.ts +45 -26
- package/cjs/tuple/drop.d.ts.map +1 -1
- package/cjs/tuple/drop.js.map +1 -1
- package/cjs/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
- package/cjs/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.common_prop_keys.js +3 -0
- package/cjs/tuple/tuple_plus.common_prop_keys.js.map +1 -0
- package/cjs/tuple/tuple_plus.d.ts +3 -0
- package/cjs/tuple/tuple_plus.d.ts.map +1 -1
- package/cjs/tuple/tuple_plus.drop_match.d.ts +6 -0
- package/cjs/tuple/tuple_plus.drop_match.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.drop_match.js +3 -0
- package/cjs/tuple/tuple_plus.drop_match.js.map +1 -0
- package/cjs/tuple/tuple_plus.filter.d.ts +2 -2
- package/cjs/tuple/tuple_plus.find.d.ts +64 -0
- package/cjs/tuple/tuple_plus.find.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.find.js +3 -0
- package/cjs/tuple/tuple_plus.find.js.map +1 -0
- package/cjs/tuple/tuple_plus.pad_start.d.ts +7 -6
- package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -1
- package/cjs/tuple/tuple_type.d.ts +41 -23
- package/cjs/tuple/tuple_type.d.ts.map +1 -1
- package/cjs/union/union.d.ts +33 -0
- package/cjs/union/union.d.ts.map +1 -0
- package/cjs/union/union.js +3 -0
- package/cjs/union/union.js.map +1 -0
- package/cjs/unknown/unknown_type.d.ts +12 -0
- package/cjs/unknown/unknown_type.d.ts.map +1 -1
- package/cjs/utils/options.d.ts +10 -0
- package/cjs/utils/options.d.ts.map +1 -0
- package/cjs/utils/options.js +3 -0
- package/cjs/utils/options.js.map +1 -0
- package/esm/array/array.entries.d.ts +4 -3
- package/esm/array/array.entries.d.ts.map +1 -1
- package/esm/array/array_index.d.ts +4 -1
- package/esm/array/array_index.d.ts.map +1 -1
- package/esm/array/array_plus.common_prop_keys.d.ts +27 -0
- package/esm/array/array_plus.common_prop_keys.d.ts.map +1 -0
- package/esm/array/array_plus.common_prop_keys.js +2 -0
- package/esm/array/array_plus.common_prop_keys.js.map +1 -0
- package/esm/array/array_plus.d.ts +6 -3
- package/esm/array/array_plus.d.ts.map +1 -1
- package/esm/array/array_plus.drop_match.d.ts +4 -0
- package/esm/array/array_plus.drop_match.d.ts.map +1 -0
- package/esm/array/array_plus.drop_match.js +2 -0
- package/esm/array/array_plus.drop_match.js.map +1 -0
- package/esm/array/array_plus.element_match.d.ts +44 -0
- package/esm/array/array_plus.element_match.d.ts.map +1 -0
- package/esm/array/array_plus.element_match.js +2 -0
- package/esm/array/array_plus.element_match.js.map +1 -0
- package/esm/array/array_plus.find.d.ts +57 -0
- package/esm/array/array_plus.find.d.ts.map +1 -0
- package/esm/array/array_plus.find.js +2 -0
- package/esm/array/array_plus.find.js.map +1 -0
- package/esm/array/array_plus.split_at.d.ts +20 -15
- package/esm/array/array_plus.split_at.d.ts.map +1 -1
- package/esm/array/find_first.d.ts +62 -0
- package/esm/array/find_first.d.ts.map +1 -0
- package/esm/array/find_first.js +2 -0
- package/esm/array/find_first.js.map +1 -0
- package/esm/array/head.d.ts +18 -6
- package/esm/array/head.d.ts.map +1 -1
- package/esm/array/last.d.ts +17 -6
- package/esm/array/last.d.ts.map +1 -1
- package/esm/assertion/assert_type.d.ts +4 -1
- package/esm/assertion/assert_type.d.ts.map +1 -1
- package/esm/assertion/assert_type.js.map +1 -1
- package/esm/index.d.ts +5 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/never/never_type.d.ts +11 -0
- package/esm/never/never_type.d.ts.map +1 -1
- package/esm/object/index.d.ts +0 -1
- package/esm/object/index.d.ts.map +1 -1
- package/esm/object/index.js.map +1 -1
- package/esm/testing/test_type.d.ts +277 -276
- package/esm/testing/test_type.d.ts.map +1 -1
- package/esm/testing/test_type.js.map +1 -1
- package/esm/tuple/common_prop_keys.d.ts +15 -10
- package/esm/tuple/common_prop_keys.d.ts.map +1 -1
- package/esm/tuple/drop.d.ts +45 -26
- package/esm/tuple/drop.d.ts.map +1 -1
- package/esm/tuple/drop.js.map +1 -1
- package/esm/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
- package/esm/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.common_prop_keys.js +2 -0
- package/esm/tuple/tuple_plus.common_prop_keys.js.map +1 -0
- package/esm/tuple/tuple_plus.d.ts +3 -0
- package/esm/tuple/tuple_plus.d.ts.map +1 -1
- package/esm/tuple/tuple_plus.drop_match.d.ts +6 -0
- package/esm/tuple/tuple_plus.drop_match.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.drop_match.js +2 -0
- package/esm/tuple/tuple_plus.drop_match.js.map +1 -0
- package/esm/tuple/tuple_plus.filter.d.ts +2 -2
- package/esm/tuple/tuple_plus.find.d.ts +64 -0
- package/esm/tuple/tuple_plus.find.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.find.js +2 -0
- package/esm/tuple/tuple_plus.find.js.map +1 -0
- package/esm/tuple/tuple_plus.pad_start.d.ts +7 -6
- package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -1
- package/esm/tuple/tuple_type.d.ts +41 -23
- package/esm/tuple/tuple_type.d.ts.map +1 -1
- package/esm/union/union.d.ts +33 -0
- package/esm/union/union.d.ts.map +1 -0
- package/esm/union/union.js +2 -0
- package/esm/union/union.js.map +1 -0
- package/esm/unknown/unknown_type.d.ts +12 -0
- package/esm/unknown/unknown_type.d.ts.map +1 -1
- package/esm/utils/options.d.ts +10 -0
- package/esm/utils/options.d.ts.map +1 -0
- package/esm/utils/options.js +2 -0
- package/esm/utils/options.js.map +1 -0
- package/package.json +12 -1
- package/ts/array/array.entries.ts +4 -2
- package/ts/array/array_index.ts +33 -23
- package/ts/array/array_plus.common_prop_keys.ts +35 -0
- package/ts/array/array_plus.drop_match.ts +16 -0
- package/ts/array/array_plus.element_match.ts +61 -0
- package/ts/array/array_plus.find.ts +71 -0
- package/ts/array/array_plus.split_at.ts +52 -23
- package/ts/array/array_plus.ts +6 -3
- package/ts/array/find_first.ts +71 -0
- package/ts/array/head.ts +28 -6
- package/ts/array/last.ts +26 -6
- package/ts/array/readme.md +152 -32
- package/ts/assertion/assert_type.ts +4 -1
- package/ts/assertion/readme.md +3 -2
- package/ts/index.ts +5 -5
- package/ts/never/never_type.ts +13 -0
- package/ts/object/index.ts +0 -1
- package/ts/testing/test_type.ts +279 -277
- package/ts/tuple/common_prop_keys.ts +18 -32
- package/ts/tuple/drop.ts +61 -60
- package/ts/tuple/readme.md +178 -39
- package/ts/tuple/tuple_plus.common_prop_keys.ts +47 -0
- package/ts/tuple/tuple_plus.drop_match.ts +20 -0
- package/ts/tuple/tuple_plus.filter.ts +2 -2
- package/ts/tuple/tuple_plus.find.ts +88 -0
- package/ts/tuple/tuple_plus.pad_start.ts +28 -25
- package/ts/tuple/tuple_plus.ts +3 -0
- package/ts/tuple/tuple_type.ts +67 -25
- package/ts/union/readme.md +81 -0
- package/ts/union/union.ts +37 -0
- package/ts/unknown/unknown_type.ts +13 -0
- package/ts/utils/options.ts +10 -0
- package/cjs/array/array.find.d.ts +0 -23
- package/cjs/array/array.find.d.ts.map +0 -1
- package/cjs/array/array.find.js.map +0 -1
- package/esm/array/array.find.d.ts +0 -23
- package/esm/array/array.find.d.ts.map +0 -1
- package/esm/array/array.find.js +0 -2
- package/esm/array/array.find.js.map +0 -1
- package/ts/array/array.find.ts +0 -34
package/ts/array/readme.md
CHANGED
|
@@ -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`](./
|
|
130
|
+
## [`FindFirst`](./find_first.ts#l52)
|
|
131
131
|
|
|
132
|
-
|
|
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#
|
|
199
|
+
## [`Head`](./head.ts#l23)
|
|
168
200
|
|
|
169
|
-
`Head<T,
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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`](./
|
|
255
|
-
|
|
256
|
-
> `ArrayPlus.Find<A, Criteria>
|
|
340
|
+
### [`ArrayPlus.Find`](./array_plus.find.ts#l49)
|
|
257
341
|
|
|
258
|
-
|
|
342
|
+
`ArrayPlus.Find<A, Criteria, Options { widen, caseNever, caseNotMatch, caseTuple, caseWiden, caseUnionNotMatch }>`
|
|
259
343
|
|
|
260
|
-
|
|
344
|
+
🦴 *utilities*
|
|
345
|
+
🔢 *customizable*
|
|
261
346
|
|
|
262
|
-
|
|
347
|
+
Finds the type in array `A` that matches `Criteria`.
|
|
263
348
|
|
|
264
349
|
```ts
|
|
265
|
-
ArrayPlus
|
|
266
|
-
|
|
267
|
-
ArrayPlus.Find<
|
|
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
|
-
|
|
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
|
-
|
|
406
|
+
It is the type level `splice()`.
|
|
301
407
|
|
|
302
408
|
```ts
|
|
303
|
-
|
|
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
|
|
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
|
-
-
|
|
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
|
-
*
|
|
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
|
package/ts/assertion/readme.md
CHANGED
|
@@ -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
|
-
💥
|
|
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
|
-
|
package/ts/never/never_type.ts
CHANGED
|
@@ -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
|
+
}
|
package/ts/object/index.ts
CHANGED
|
@@ -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'
|