@fncts/typelevel 0.0.1
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/Any.d.ts +48 -0
- package/Boolean.d.ts +39 -0
- package/BuiltIn.d.ts +3 -0
- package/Check.d.ts +70 -0
- package/Function.d.ts +11 -0
- package/HKT.d.ts +186 -0
- package/Intersection.d.ts +1 -0
- package/Iteration.d.ts +216 -0
- package/List.d.ts +15 -0
- package/Number.d.ts +56 -0
- package/Object.d.ts +118 -0
- package/String.d.ts +8 -0
- package/Union.d.ts +23 -0
- package/_cjs/Any.cjs +6 -0
- package/_cjs/Any.cjs.map +1 -0
- package/_cjs/Boolean.cjs +6 -0
- package/_cjs/Boolean.cjs.map +1 -0
- package/_cjs/BuiltIn.cjs +6 -0
- package/_cjs/BuiltIn.cjs.map +1 -0
- package/_cjs/Check.cjs +6 -0
- package/_cjs/Check.cjs.map +1 -0
- package/_cjs/Function.cjs +6 -0
- package/_cjs/Function.cjs.map +1 -0
- package/_cjs/HKT.cjs +26 -0
- package/_cjs/HKT.cjs.map +1 -0
- package/_cjs/Intersection.cjs +6 -0
- package/_cjs/Intersection.cjs.map +1 -0
- package/_cjs/Iteration.cjs +6 -0
- package/_cjs/Iteration.cjs.map +1 -0
- package/_cjs/List.cjs +6 -0
- package/_cjs/List.cjs.map +1 -0
- package/_cjs/Number.cjs +6 -0
- package/_cjs/Number.cjs.map +1 -0
- package/_cjs/Object.cjs +6 -0
- package/_cjs/Object.cjs.map +1 -0
- package/_cjs/String.cjs +6 -0
- package/_cjs/String.cjs.map +1 -0
- package/_cjs/Union.cjs +6 -0
- package/_cjs/Union.cjs.map +1 -0
- package/_cjs/index.cjs +51 -0
- package/_cjs/index.cjs.map +1 -0
- package/_mjs/Any.mjs +2 -0
- package/_mjs/Any.mjs.map +1 -0
- package/_mjs/Boolean.mjs +2 -0
- package/_mjs/Boolean.mjs.map +1 -0
- package/_mjs/BuiltIn.mjs +2 -0
- package/_mjs/BuiltIn.mjs.map +1 -0
- package/_mjs/Check.mjs +2 -0
- package/_mjs/Check.mjs.map +1 -0
- package/_mjs/Function.mjs +2 -0
- package/_mjs/Function.mjs.map +1 -0
- package/_mjs/HKT.mjs +19 -0
- package/_mjs/HKT.mjs.map +1 -0
- package/_mjs/Intersection.mjs +2 -0
- package/_mjs/Intersection.mjs.map +1 -0
- package/_mjs/Iteration.mjs +2 -0
- package/_mjs/Iteration.mjs.map +1 -0
- package/_mjs/List.mjs +2 -0
- package/_mjs/List.mjs.map +1 -0
- package/_mjs/Number.mjs +2 -0
- package/_mjs/Number.mjs.map +1 -0
- package/_mjs/Object.mjs +2 -0
- package/_mjs/Object.mjs.map +1 -0
- package/_mjs/String.mjs +2 -0
- package/_mjs/String.mjs.map +1 -0
- package/_mjs/Union.mjs +2 -0
- package/_mjs/Union.mjs.map +1 -0
- package/_mjs/index.mjs +21 -0
- package/_mjs/index.mjs.map +1 -0
- package/_src/Any.ts +100 -0
- package/_src/Boolean.ts +44 -0
- package/_src/BuiltIn.ts +7 -0
- package/_src/Check.ts +89 -0
- package/_src/Function.ts +24 -0
- package/_src/HKT.ts +349 -0
- package/_src/Intersection.ts +1 -0
- package/_src/Iteration.ts +224 -0
- package/_src/List.ts +47 -0
- package/_src/Number.ts +137 -0
- package/_src/Object.ts +332 -0
- package/_src/String.ts +28 -0
- package/_src/Union.ts +47 -0
- package/_src/index.ts +11 -0
- package/index.d.ts +11 -0
- package/package.json +13 -0
package/_src/Object.ts
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import type { At, Cast, Extends, Is, Key, Keys, Match } from "./Any.js";
|
|
2
|
+
import type { False, True } from "./Boolean.js";
|
|
3
|
+
import type { BuiltIn } from "./BuiltIn.js";
|
|
4
|
+
import type { Iteration, IterationOf, Next, Pos } from "./Iteration.js";
|
|
5
|
+
import type { Append, Head, Length, List, Pop, PrependAll, Tail } from "./List.js";
|
|
6
|
+
import type * as U from "./Union.js";
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* -------------------------------------------------------------------------------------------------
|
|
10
|
+
* Path
|
|
11
|
+
* -------------------------------------------------------------------------------------------------
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type _Path<O, P extends List<Key>, I extends Iteration = IterationOf<0>> = {
|
|
15
|
+
[False]: _Path<At<O, P[Pos<I>]>, P, Next<I>>;
|
|
16
|
+
[True]: O;
|
|
17
|
+
}[Extends<Pos<I>, Length<P>>];
|
|
18
|
+
|
|
19
|
+
export type Path<O, P extends List<Key>> = _Path<O & {}, P> extends infer X ? Cast<X, any> : never;
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* -------------------------------------------------------------------------------------------------
|
|
23
|
+
* AutoPath
|
|
24
|
+
* -------------------------------------------------------------------------------------------------
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
type Index = number | string;
|
|
28
|
+
|
|
29
|
+
type KeyToIndex<K extends Key, SP extends List<Index>> = number extends K ? Head<SP> : K & Index;
|
|
30
|
+
|
|
31
|
+
declare const __Cont: unique symbol;
|
|
32
|
+
type __Cont = typeof __Cont;
|
|
33
|
+
declare const __Path: unique symbol;
|
|
34
|
+
type __Path = typeof __Path;
|
|
35
|
+
|
|
36
|
+
type _MetaPath<O, SP extends List<Index> = [], P extends List<Index> = []> = {
|
|
37
|
+
[K in keyof O]: {
|
|
38
|
+
[__Cont]: _MetaPath<O[K], Tail<SP>, Append<P, KeyToIndex<K, SP>>>;
|
|
39
|
+
[__Path]: Append<P, KeyToIndex<K, SP>>;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type MetaPath<O, SP extends List<Index> = [], P extends List<Index> = []> = {
|
|
44
|
+
[__Cont]: _MetaPath<O, SP, P>;
|
|
45
|
+
[__Path]: [];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type NextPath<OP> = At<UnionOf<At<OP, __Cont>>, __Path> extends infer X
|
|
49
|
+
? undefined extends X
|
|
50
|
+
? never
|
|
51
|
+
: X
|
|
52
|
+
: never;
|
|
53
|
+
|
|
54
|
+
type ExecPath<A, SP extends List<Index>> = NextPath<Path<MetaPath<A, SP>, PrependAll<SP, __Cont>>>;
|
|
55
|
+
|
|
56
|
+
type HintPath<A, SP extends List<Index>, Exec extends List<Index>> = [Exec] extends [never]
|
|
57
|
+
? ExecPath<A, Pop<SP>>
|
|
58
|
+
: Exec | SP;
|
|
59
|
+
|
|
60
|
+
export type AutoPath<A, P extends List<Index>> = HintPath<A, P, ExecPath<A, P>>;
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* -------------------------------------------------------------------------------------------------
|
|
64
|
+
* UnionOf
|
|
65
|
+
* -------------------------------------------------------------------------------------------------
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
export type _UnionOf<O> = O[keyof O];
|
|
69
|
+
|
|
70
|
+
export type UnionOf<O> = O extends unknown ? _UnionOf<O> : never;
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
* -------------------------------------------------------------------------------------------------
|
|
74
|
+
* RequiredKeys
|
|
75
|
+
* -------------------------------------------------------------------------------------------------
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
export type _RequiredKeys<O> = {
|
|
79
|
+
[K in keyof O]-?: {} extends Pick<O, K> ? never : K;
|
|
80
|
+
}[keyof O];
|
|
81
|
+
|
|
82
|
+
export type RequiredKeys<O> = O extends unknown ? _RequiredKeys<O> : never;
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
* -------------------------------------------------------------------------------------------------
|
|
86
|
+
* OptionalKeys
|
|
87
|
+
* -------------------------------------------------------------------------------------------------
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
export type _OptionalKeys<O> = {
|
|
91
|
+
[K in keyof O]-?: {} extends Pick<O, K> ? K : never;
|
|
92
|
+
}[keyof O];
|
|
93
|
+
|
|
94
|
+
export type OptionalKeys<O> = O extends unknown ? _OptionalKeys<O> : never;
|
|
95
|
+
|
|
96
|
+
/*
|
|
97
|
+
* -------------------------------------------------------------------------------------------------
|
|
98
|
+
* Pick
|
|
99
|
+
* -------------------------------------------------------------------------------------------------
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
type __Pick<O, K extends keyof O> = {
|
|
103
|
+
[P in K]: O[P];
|
|
104
|
+
} & {};
|
|
105
|
+
|
|
106
|
+
export type _Pick<O, K extends Key> = __Pick<O, keyof O & K>;
|
|
107
|
+
|
|
108
|
+
export type Pick<O, K extends Key> = O extends unknown ? _Pick<O, K> : never;
|
|
109
|
+
|
|
110
|
+
/*
|
|
111
|
+
* -------------------------------------------------------------------------------------------------
|
|
112
|
+
* Pick
|
|
113
|
+
* -------------------------------------------------------------------------------------------------
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
export type _Omit<O, K extends Key> = _Pick<O, U.Exclude<keyof O, K>>;
|
|
117
|
+
|
|
118
|
+
export type Omit<O, K extends Key> = O extends unknown ? _Omit<O, K> : never;
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
* -------------------------------------------------------------------------------------------------
|
|
122
|
+
* Anyify
|
|
123
|
+
* -------------------------------------------------------------------------------------------------
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
export type Anyify<O> = {
|
|
127
|
+
[K in keyof O]: any;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/*
|
|
131
|
+
* -------------------------------------------------------------------------------------------------
|
|
132
|
+
* Exclude
|
|
133
|
+
* -------------------------------------------------------------------------------------------------
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
export type _ExcludeMatch<O, O1, M extends Match> = {
|
|
137
|
+
[K in keyof O]-?: {
|
|
138
|
+
[True]: never;
|
|
139
|
+
[False]: K;
|
|
140
|
+
}[Is<O[K], At<O1, K>, M>];
|
|
141
|
+
}[keyof O];
|
|
142
|
+
|
|
143
|
+
export type ExcludeMatch<O, O1, M extends Match> = O extends unknown
|
|
144
|
+
? _ExcludeMatch<O, O1, M>
|
|
145
|
+
: never;
|
|
146
|
+
|
|
147
|
+
export type ExcludeKeys<O, O1, M extends Match = "default"> = {
|
|
148
|
+
default: U.Exclude<Keys<O>, Keys<O1>>;
|
|
149
|
+
"contains->": ExcludeMatch<O, O1, "contains->">;
|
|
150
|
+
"extends->": ExcludeMatch<O, O1, "extends->">;
|
|
151
|
+
"<-contains": ExcludeMatch<O, O1, "<-contains">;
|
|
152
|
+
"<-extends": ExcludeMatch<O, O1, "<-extends">;
|
|
153
|
+
equals: ExcludeMatch<O, O1, "equals">;
|
|
154
|
+
}[M];
|
|
155
|
+
|
|
156
|
+
/*
|
|
157
|
+
* -------------------------------------------------------------------------------------------------
|
|
158
|
+
* Exclude
|
|
159
|
+
* -------------------------------------------------------------------------------------------------
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
export type Exclude<O, O1, M extends Match> = Pick<O, ExcludeKeys<O, O1, M>>;
|
|
163
|
+
|
|
164
|
+
/*
|
|
165
|
+
* -------------------------------------------------------------------------------------------------
|
|
166
|
+
* Merge
|
|
167
|
+
* -------------------------------------------------------------------------------------------------
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
type Longer<L extends List, L1 extends List> = L extends unknown
|
|
171
|
+
? L1 extends unknown
|
|
172
|
+
? U.Has<RequiredKeys<L>, RequiredKeys<L1>>
|
|
173
|
+
: never
|
|
174
|
+
: never;
|
|
175
|
+
|
|
176
|
+
type MergeProp<OK, O1K, Fill, OOKeys extends Key, K extends Key> = K extends OOKeys
|
|
177
|
+
? U.Exclude<OK, undefined> | O1K
|
|
178
|
+
: [OK] extends [never]
|
|
179
|
+
? O1K
|
|
180
|
+
: OK extends Fill
|
|
181
|
+
? O1K
|
|
182
|
+
: OK;
|
|
183
|
+
|
|
184
|
+
type MergeFlatObject<O, O1, Fill, OOKeys extends Key = OptionalKeys<O>> = {
|
|
185
|
+
[K in keyof (Anyify<O> & O1)]: MergeProp<At<O, K>, At<O1, K>, Fill, OOKeys, K>;
|
|
186
|
+
} & {};
|
|
187
|
+
|
|
188
|
+
type MergeFlatList<
|
|
189
|
+
L extends List,
|
|
190
|
+
L1 extends List,
|
|
191
|
+
Ignore,
|
|
192
|
+
Fill,
|
|
193
|
+
LOK extends Key = _OptionalKeys<L>,
|
|
194
|
+
> = number extends Length<L | L1>
|
|
195
|
+
? MergeFlatChoice<L[number], L1[number], Ignore, Fill>[]
|
|
196
|
+
: Longer<L, L1> extends True
|
|
197
|
+
? { [K in keyof L]: MergeProp<L[K], At<L1, K>, Fill, LOK, K> }
|
|
198
|
+
: { [K in keyof L1]: MergeProp<At<L, K>, L1[K], Fill, LOK, K> };
|
|
199
|
+
|
|
200
|
+
type MergeFlatChoice<O, O1, Ignore, Fill> = O extends Ignore
|
|
201
|
+
? O
|
|
202
|
+
: O1 extends Ignore
|
|
203
|
+
? O
|
|
204
|
+
: O extends List
|
|
205
|
+
? O1 extends List
|
|
206
|
+
? MergeFlatList<O, O1, Ignore, Fill>
|
|
207
|
+
: MergeFlatObject<O, O1, Fill>
|
|
208
|
+
: MergeFlatObject<O, O1, Fill>;
|
|
209
|
+
|
|
210
|
+
export type MergeFlat<O, O1, Ignore = BuiltIn, Fill = undefined> = O extends unknown
|
|
211
|
+
? O1 extends unknown
|
|
212
|
+
? MergeFlatChoice<O, O1, Ignore, Fill>
|
|
213
|
+
: never
|
|
214
|
+
: never;
|
|
215
|
+
|
|
216
|
+
type MergeDeepList<L extends List, L1 extends List, Ignore, Fill> = number extends Length<L | L1>
|
|
217
|
+
? MergeDeepChoice<L[number], L1[number], Ignore, Fill, never, any>[]
|
|
218
|
+
: Longer<L, L1> extends True
|
|
219
|
+
? { [K in keyof L]: MergeDeepChoice<L[K], At<L1, K>, Ignore, Fill, _OptionalKeys<L>, K> }
|
|
220
|
+
: { [K in keyof L1]: MergeDeepChoice<At<L, K>, L1[K], Ignore, Fill, _OptionalKeys<L>, K> };
|
|
221
|
+
|
|
222
|
+
type MergeDeepObject<O, O1, Ignore, Fill, OOKeys extends Key = _OptionalKeys<O>> = {
|
|
223
|
+
[K in keyof (Anyify<O> & O1)]: MergeDeepChoice<At<O, K>, At<O1, K>, Ignore, Fill, OOKeys, K>;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
type MergeDeepChoice<OK, O1K, Ignore, Fill, OOKeys extends Key, K extends Key> = [OK] extends [
|
|
227
|
+
never,
|
|
228
|
+
]
|
|
229
|
+
? MergeProp<OK, O1K, Fill, OOKeys, K>
|
|
230
|
+
: [O1K] extends [never]
|
|
231
|
+
? MergeProp<OK, O1K, Fill, OOKeys, K>
|
|
232
|
+
: OK extends Ignore
|
|
233
|
+
? MergeProp<OK, O1K, Fill, OOKeys, K>
|
|
234
|
+
: O1K extends Ignore
|
|
235
|
+
? MergeProp<OK, O1K, Fill, OOKeys, K>
|
|
236
|
+
: OK extends List
|
|
237
|
+
? O1K extends List
|
|
238
|
+
? MergeDeepList<OK, O1K, Ignore, Fill>
|
|
239
|
+
: MergeProp<OK, O1K, Fill, OOKeys, K>
|
|
240
|
+
: OK extends object
|
|
241
|
+
? O1K extends object
|
|
242
|
+
? MergeDeepObject<OK, O1K, Ignore, Fill>
|
|
243
|
+
: MergeProp<OK, O1K, Fill, OOKeys, K>
|
|
244
|
+
: MergeProp<OK, O1K, Fill, OOKeys, K>;
|
|
245
|
+
|
|
246
|
+
export type MergeDeep<O, O1, Ignore, Fill> = O extends unknown
|
|
247
|
+
? O1 extends unknown
|
|
248
|
+
? MergeDeepChoice<O, O1, Ignore, Fill, "x", "y">
|
|
249
|
+
: never
|
|
250
|
+
: never;
|
|
251
|
+
|
|
252
|
+
/*
|
|
253
|
+
* -------------------------------------------------------------------------------------------------
|
|
254
|
+
* Patch
|
|
255
|
+
* -------------------------------------------------------------------------------------------------
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
type PatchProp<OK, O1K, Fill, OKeys extends Key, K extends Key> = K extends OKeys
|
|
259
|
+
? OK extends Fill
|
|
260
|
+
? O1K
|
|
261
|
+
: OK
|
|
262
|
+
: O1K;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @hidden
|
|
266
|
+
*/
|
|
267
|
+
type PatchFlatObject<O, O1, Fill, OKeys extends Key = keyof O> = {
|
|
268
|
+
[K in keyof (O & _Omit<O1, OKeys>)]: PatchProp<At<O, K>, At<O1, K>, Fill, OKeys, K>;
|
|
269
|
+
} & {};
|
|
270
|
+
|
|
271
|
+
type PatchFlatList<L extends List, L1 extends List, Ignore, Fill> = number extends Length<L | L1>
|
|
272
|
+
? PatchFlatChoice<L[number], L1[number], Ignore, Fill>[]
|
|
273
|
+
: Longer<L, L1> extends True
|
|
274
|
+
? { [K in keyof L]: PatchProp<L[K], At<L1, K>, Fill, keyof L, K> }
|
|
275
|
+
: { [K in keyof L1]: PatchProp<At<L, K>, L1[K], Fill, keyof L, K> };
|
|
276
|
+
|
|
277
|
+
export type PatchFlatChoice<O, O1, Ignore, Fill> = O extends Ignore
|
|
278
|
+
? O
|
|
279
|
+
: O1 extends Ignore
|
|
280
|
+
? O
|
|
281
|
+
: O extends List
|
|
282
|
+
? O1 extends List
|
|
283
|
+
? PatchFlatList<O, O1, Ignore, Fill>
|
|
284
|
+
: PatchFlatObject<O, O1, Fill>
|
|
285
|
+
: PatchFlatObject<O, O1, Fill>;
|
|
286
|
+
|
|
287
|
+
export type PatchFlat<O, O1, Ignore = BuiltIn, Fill = never> = O extends unknown
|
|
288
|
+
? O1 extends unknown
|
|
289
|
+
? PatchFlatChoice<O, O1, Ignore, Fill>
|
|
290
|
+
: never
|
|
291
|
+
: never;
|
|
292
|
+
|
|
293
|
+
type PatchDeepList<L extends List, L1 extends List, Ignore, Fill> = number extends Length<L | L1>
|
|
294
|
+
? PatchDeepChoice<L[number], L1[number], Ignore, Fill, never, any>[]
|
|
295
|
+
: Longer<L, L1> extends True
|
|
296
|
+
? { [K in keyof L]: PatchDeepChoice<L[K], At<L1, K>, Ignore, Fill, keyof L, K> }
|
|
297
|
+
: { [K in keyof L1]: PatchDeepChoice<At<L, K>, L1[K], Ignore, Fill, keyof L, K> };
|
|
298
|
+
|
|
299
|
+
type PatchDeepObject<O, O1, Ignore, Fill, OKeys extends Key = keyof O> = {
|
|
300
|
+
[K in keyof (O & _Omit<O1, OKeys>)]: PatchDeepChoice<At<O, K>, At<O1, K>, Ignore, Fill, OKeys, K>;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
type PatchDeepChoice<OK, O1K, Ignore, fill, OKeys extends Key, K extends Key> = [OK] extends [never]
|
|
304
|
+
? PatchProp<OK, O1K, fill, OKeys, K>
|
|
305
|
+
: [O1K] extends [never]
|
|
306
|
+
? PatchProp<OK, O1K, fill, OKeys, K>
|
|
307
|
+
: OK extends Ignore
|
|
308
|
+
? PatchProp<OK, O1K, fill, OKeys, K>
|
|
309
|
+
: O1K extends Ignore
|
|
310
|
+
? PatchProp<OK, O1K, fill, OKeys, K>
|
|
311
|
+
: OK extends List
|
|
312
|
+
? O1K extends List
|
|
313
|
+
? PatchDeepList<OK, O1K, Ignore, fill>
|
|
314
|
+
: PatchProp<OK, O1K, fill, OKeys, K>
|
|
315
|
+
: OK extends object
|
|
316
|
+
? O1K extends object
|
|
317
|
+
? PatchDeepObject<OK, O1K, Ignore, fill>
|
|
318
|
+
: PatchProp<OK, O1K, fill, OKeys, K>
|
|
319
|
+
: PatchProp<OK, O1K, fill, OKeys, K>;
|
|
320
|
+
|
|
321
|
+
export type PatchDeep<O, O1, Ignore, Fill> = O extends unknown
|
|
322
|
+
? O1 extends unknown
|
|
323
|
+
? PatchDeepChoice<O, O1, Ignore, Fill, "x", "y"> // dummy x, y
|
|
324
|
+
: never
|
|
325
|
+
: never;
|
|
326
|
+
|
|
327
|
+
export type Diff<O, O1, M extends Match = "default"> = PatchFlat<
|
|
328
|
+
Exclude<O, O1, M>,
|
|
329
|
+
Exclude<O1, O, M>
|
|
330
|
+
>;
|
|
331
|
+
|
|
332
|
+
export type EnforceNonEmpty<O> = keyof O extends never ? never : O;
|
package/_src/String.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Cast, Literal } from "./Any.js";
|
|
2
|
+
import type { List, Pop } from "./List.js";
|
|
3
|
+
|
|
4
|
+
type _Join<T extends List, D extends string> = T extends []
|
|
5
|
+
? ""
|
|
6
|
+
: T extends [Literal]
|
|
7
|
+
? `${T[0]}`
|
|
8
|
+
: T extends [Literal, ...infer R]
|
|
9
|
+
? `${T[0]}${D}${_Join<R, D>}`
|
|
10
|
+
: string;
|
|
11
|
+
|
|
12
|
+
export type Join<T extends List<Literal>, D extends string = ""> = _Join<T, D> extends infer X
|
|
13
|
+
? Cast<X, string>
|
|
14
|
+
: never;
|
|
15
|
+
|
|
16
|
+
type __Split<
|
|
17
|
+
S extends string,
|
|
18
|
+
D extends string,
|
|
19
|
+
T extends string[] = [],
|
|
20
|
+
> = S extends `${infer BS}${D}${infer AS}` ? __Split<AS, D, [...T, BS]> : [...T, S];
|
|
21
|
+
|
|
22
|
+
type _Split<S extends string, D extends string = ""> = D extends ""
|
|
23
|
+
? Pop<__Split<S, D>>
|
|
24
|
+
: __Split<S, D>;
|
|
25
|
+
|
|
26
|
+
export type Split<S extends string, D extends string = ""> = _Split<S, D> extends infer X
|
|
27
|
+
? Cast<X, string[]>
|
|
28
|
+
: never;
|
package/_src/Union.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Cast, Equals, Extends, Is, Match } from "./Any.js";
|
|
2
|
+
import type { False,True } from "./Boolean.js";
|
|
3
|
+
import type { List, Prepend } from "./List.js";
|
|
4
|
+
|
|
5
|
+
export type IntersectionOf<U> = (U extends unknown ? (k: U) => void : never) extends (
|
|
6
|
+
k: infer I,
|
|
7
|
+
) => void
|
|
8
|
+
? I
|
|
9
|
+
: never;
|
|
10
|
+
|
|
11
|
+
export type Last<U> = IntersectionOf<U extends unknown ? (x: U) => void : never> extends (
|
|
12
|
+
x: infer P,
|
|
13
|
+
) => void
|
|
14
|
+
? P
|
|
15
|
+
: never;
|
|
16
|
+
|
|
17
|
+
type _ListOf<U, LN extends List = [], LastU = Last<U>> = Extends<[U], [never]> extends False
|
|
18
|
+
? _ListOf<Exclude<U, LastU>, Prepend<LN, LastU>>
|
|
19
|
+
: LN;
|
|
20
|
+
|
|
21
|
+
export type ListOf<U> = _ListOf<U> extends infer X ? Cast<X, List> : never;
|
|
22
|
+
|
|
23
|
+
export type Has<A, B> = [B] extends [A] ? True : False;
|
|
24
|
+
|
|
25
|
+
export type Select<U, M, _ extends Match = "default"> = U extends unknown
|
|
26
|
+
? {
|
|
27
|
+
[False]: never;
|
|
28
|
+
[True]: U & M;
|
|
29
|
+
}[Is<U, M, _>]
|
|
30
|
+
: never;
|
|
31
|
+
|
|
32
|
+
export type Filter<U, M, _ extends Match = "default"> = U extends unknown
|
|
33
|
+
? {
|
|
34
|
+
[False]: U & M;
|
|
35
|
+
[True]: never;
|
|
36
|
+
}[Is<U, M, _>]
|
|
37
|
+
: never;
|
|
38
|
+
|
|
39
|
+
export type Intersect<A, B> = A extends unknown
|
|
40
|
+
? B extends unknown
|
|
41
|
+
? { [True]: A; [False]: never }[Equals<A, B>]
|
|
42
|
+
: never
|
|
43
|
+
: never;
|
|
44
|
+
|
|
45
|
+
export type Exclude<A, B> = A extends B ? never : A;
|
|
46
|
+
|
|
47
|
+
export type Pop<U> = Exclude<U, Last<U>>;
|
package/_src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * as Any from "./Any.js";
|
|
2
|
+
export * as Boolean from "./Boolean.js";
|
|
3
|
+
export { Check } from "./Check.js";
|
|
4
|
+
export * as Function from "./Function.js";
|
|
5
|
+
export * as Intersection from "./Intersection.js";
|
|
6
|
+
export * as Iteration from "./Iteration.js";
|
|
7
|
+
export * as List from "./List.js";
|
|
8
|
+
export * as Number from "./Number.js";
|
|
9
|
+
export * as Object from "./Object.js";
|
|
10
|
+
export * as String from "./String.js";
|
|
11
|
+
export * as Union from "./Union.js";
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * as Any from "./Any.js";
|
|
2
|
+
export * as Boolean from "./Boolean.js";
|
|
3
|
+
export { Check } from "./Check.js";
|
|
4
|
+
export * as Function from "./Function.js";
|
|
5
|
+
export * as Intersection from "./Intersection.js";
|
|
6
|
+
export * as Iteration from "./Iteration.js";
|
|
7
|
+
export * as List from "./List.js";
|
|
8
|
+
export * as Number from "./Number.js";
|
|
9
|
+
export * as Object from "./Object.js";
|
|
10
|
+
export * as String from "./String.js";
|
|
11
|
+
export * as Union from "./Union.js";
|