@avstantso/ts 1.1.0 → 1.2.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/_global/_register.d.ts +80 -0
  3. package/dist/_global/array/_register.d.ts +28 -0
  4. package/dist/_global/array/arr-n.d.ts +21 -0
  5. package/dist/_global/array/create.d.ts +59 -0
  6. package/dist/_global/array/derivative.d.ts +197 -0
  7. package/dist/_global/array/find.d.ts +89 -0
  8. package/dist/_global/array/index.d.ts +8 -0
  9. package/dist/_global/array/low-level.d.ts +84 -0
  10. package/dist/_global/array/map-key-value.d.ts +121 -0
  11. package/dist/_global/array/min-max-sort.d.ts +244 -0
  12. package/dist/_global/ascii.d.ts +76 -0
  13. package/dist/_global/boolean.d.ts +74 -0
  14. package/dist/_global/comparisons.d.ts +85 -0
  15. package/dist/_global/func.d.ts +17 -0
  16. package/dist/_global/index.d.ts +14 -0
  17. package/dist/_global/literal.d.ts +180 -0
  18. package/dist/_global/numeric/domain/describes.d.ts +62 -0
  19. package/dist/_global/numeric/domain/generated.d.ts +11240 -0
  20. package/dist/_global/numeric/domain/inc-dec.d.ts +52 -0
  21. package/dist/_global/numeric/domain/independent.d.ts +203 -0
  22. package/dist/_global/numeric/domain/index.d.ts +4 -0
  23. package/dist/_global/numeric/inc-dec.d.ts +50 -0
  24. package/dist/_global/numeric/index.d.ts +3 -0
  25. package/dist/_global/numeric/math.d.ts +257 -0
  26. package/dist/_global/resolve.d.ts +45 -0
  27. package/dist/_global/string.d.ts +306 -0
  28. package/dist/_global/structure/_register.d.ts +93 -0
  29. package/dist/_global/structure/index.d.ts +2 -0
  30. package/dist/_global/structure/structure.d.ts +289 -0
  31. package/dist/_global/type/_register.d.ts +64 -0
  32. package/dist/_global/type/def.d.ts +47 -0
  33. package/dist/_global/type/index.d.ts +7 -0
  34. package/dist/_global/type/key-arr-def.d.ts +14 -0
  35. package/dist/_global/type/key-def.d.ts +76 -0
  36. package/dist/_global/type/key-literal-default-arr.d.ts +45 -0
  37. package/dist/_global/type/not.d.ts +44 -0
  38. package/dist/_global/type/union.d.ts +33 -0
  39. package/dist/_global/union.d.ts +79 -0
  40. package/dist/_global/utility/alt.d.ts +58 -0
  41. package/dist/_global/utility/flat.d.ts +60 -0
  42. package/dist/_global/utility/if-def.d.ts +22 -0
  43. package/dist/_global/utility/index.d.ts +9 -0
  44. package/dist/_global/utility/merge.d.ts +29 -0
  45. package/dist/_global/utility/opaque.d.ts +17 -0
  46. package/dist/_global/utility/options.d.ts +34 -0
  47. package/dist/_global/utility/override.d.ts +100 -0
  48. package/dist/_global/utility/replace-key.d.ts +33 -0
  49. package/dist/_global/utility/required-optional.d.ts +24 -0
  50. package/dist/_std-ext/index.d.ts +1 -0
  51. package/dist/_std-ext/object.d.ts +23 -0
  52. package/dist/export.d.ts +2 -0
  53. package/dist/index.d.ts +4 -0
  54. package/dist/index.js +480 -0
  55. package/dist/index.js.map +1 -0
  56. package/package.json +3 -3
@@ -0,0 +1,289 @@
1
+ declare namespace AVStantso.TS {
2
+ /**
3
+ * @summary If `T` is structure object.\
4
+ * Not extends special object types
5
+ * @example
6
+ * type n = CheckType<IfStructure<number>, false>;
7
+ * type s = CheckType<IfStructure<string>, false>;
8
+ * type o = CheckType<IfStructure<{}>, true>;
9
+ * type ob = CheckType<IfStructure<object>, true>;
10
+ * type a = CheckType<IfStructure<[]>, false>;
11
+ * type d = CheckType<IfStructure<Date>, false>;
12
+ * type b = CheckType<IfStructure<Buffer>, false>;
13
+ * type mp = CheckType<IfStructure<Map<unknown, unknown>>, false>;
14
+ * type st = CheckType<IfStructure<Set<unknown>>, false>;
15
+ *
16
+ * type fb = CheckType<IfStructure<(x: number) => string>, false>;
17
+ * type fe = CheckType<IfStructure<((x: number) => string) & { y: 15 }>, true>;
18
+ */
19
+ type IfStructure<T, IfTrue = true, IfFalse = false> = T extends undefined ? IfFalse : T extends object ? T extends Structure.NotRules ? IfFalse : T extends TS.Func ? [keyof T] extends [never] ? IfFalse : IfTrue : IfTrue : IfFalse;
20
+ /**
21
+ * @summary Constraint: `T` is structure object.\
22
+ * Not extends special object types
23
+ * @see IfStructure
24
+ * @see Structure.NotRules
25
+ */
26
+ type Structure<T extends object> = IfStructure<T, T, never>;
27
+ namespace Structure {
28
+ /**
29
+ * @summary Not strict Structure.
30
+ */
31
+ export type Wildcard = object | AVStantso.TS.Func;
32
+ /**
33
+ * @summary Used as rules source in `IfStructure`.
34
+ *
35
+ * If extends one of values — it is not a structure
36
+ */
37
+ export interface MapOfNotRules extends AtomicObjects {
38
+ Array: ReadonlyArray<unknown>;
39
+ Map: ReadonlyMap<unknown, unknown>;
40
+ Set: ReadonlySet<unknown>;
41
+ }
42
+ /**
43
+ * @summary Used as rules `IfStructure`.
44
+ */
45
+ export type NotRules = MapOfNotRules[keyof MapOfNotRules];
46
+ /**
47
+ * @summary Transform structure `O` to keys tuple
48
+ * @template O Structure
49
+ * @see Union.ToTuple
50
+ * @example
51
+ * type n = CheckType<ToKeysArray<never>, never>;
52
+ * type u = CheckType<ToKeysArray<undefined>, undefined>;
53
+ *
54
+ * type st1 = CheckType<ToKeysArray<{ a: 1, b: true }>, ['a', 'b']>;
55
+ * type st2 = CheckType<ToKeysArray<{ a: 1, b: true, c: () => null }>, ['a', 'b', 'c']>;
56
+ * type a = CheckType<ToKeysArray<[]>, never>;
57
+ */
58
+ export type ToKeysArray<O extends object> = O extends undefined ? O : IfStructure<O> extends true ? Union.ToTuple<keyof O> : never;
59
+ type _ToValuesArray<O extends object, Keys extends readonly (keyof O)[], R extends ArrR = []> = Keys extends readonly [infer F extends keyof O, ...infer Rest extends (keyof O)[]] ? _ToValuesArray<O, Rest, [...R, O[F]]> : R;
60
+ /**
61
+ * @summary Transform structure `O` to values tuple
62
+ * @template O Structure
63
+ * @see Union.ToTuple
64
+ * @example
65
+ * type n = CheckType<ToValuesArray<never>, never>;
66
+ * type u = CheckType<ToValuesArray<undefined>, undefined>;
67
+ *
68
+ * type st1 = CheckType<ToValuesArray<{ a: 1, b: true }>, [1, true]>;
69
+ * type st2 = CheckType<ToValuesArray<{ a: 1, b: true, c: () => null }>, [1, true, () => null]>;
70
+ * type a = CheckType<ToValuesArray<[]>, never>;
71
+ */
72
+ export type ToValuesArray<O extends object> = O extends undefined ? O : IfStructure<O> extends true ? _ToValuesArray<O, Extract<Union.ToTuple<keyof O>, readonly (keyof O)[]>> : never;
73
+ type _ToEntriesArray<O extends object, Keys extends readonly (keyof O)[], R extends ArrR = []> = Keys extends readonly [infer F extends keyof O, ...infer Rest extends (keyof O)[]] ? _ToEntriesArray<O, Rest, [...R, [F, O[F]]]> : R;
74
+ /**
75
+ * @summary Transform structure `O` to entries tuple
76
+ * @template O Structure
77
+ * @see Union.ToTuple
78
+ * @example
79
+ * type n = CheckType<ToEntriesArray<never>, never>;
80
+ * type u = CheckType<ToEntriesArray<undefined>, undefined>;
81
+ *
82
+ * type st1 = CheckType<ToEntriesArray<{ a: 1, b: true }>, [['a', 1], ['b', true]]>;
83
+ * type st2 = CheckType<
84
+ * ToEntriesArray<{ a: 1, b: true, c: () => null }>,
85
+ * [['a', 1], ['b', true], ['c', () => null]]
86
+ * >;
87
+ * type a = CheckType<ToEntriesArray<[]>, never>;
88
+ */
89
+ export type ToEntriesArray<O extends object> = O extends undefined ? O : IfStructure<O> extends true ? _ToEntriesArray<O, Extract<Union.ToTuple<keyof O>, readonly (keyof O)[]>> : never;
90
+ /**
91
+ * @summary Separate structure object `T` to `[<Plain>, <Structural>]`\
92
+ * ⚠ Unsafe, internal
93
+ * @example
94
+ * type nv = CheckType<_Separate<never>, [never, never]>; // ⚠
95
+ * type ud = CheckType<_Separate<undefined>, [undefined, undefined]>; // ⚠
96
+ * type n = CheckType<_Separate<number>, [number, number]>; // ⚠
97
+ * type s = CheckType<_Separate<string>, [string, string]>; // ⚠
98
+ * type a = CheckType<_Separate<[]>, [object, object]>; // ⚠All methods here
99
+ * type d = CheckType<_Separate<Date>, [object, object]>; // ⚠All methods here
100
+ * type b = CheckType<_Separate<Buffer>, [object, object]>; // ⚠All methods here
101
+ * type mp = CheckType<_Separate<Map<unknown, unknown>>, [object, object]>; // ⚠All methods here
102
+ * type st = CheckType<_Separate<Set<unknown>>, [object, object]>; // ⚠All methods here
103
+ *
104
+ * type o = CheckType<_Separate<{}>, [{}, {}]>;
105
+ * type ob = CheckType<_Separate<object>, [object, object]>;
106
+ *
107
+ * type x = CheckType<_Separate<
108
+ * { a: number; b: { c: string }, d: string, e: number[] }
109
+ * >, [{
110
+ * a: number;
111
+ * d: string;
112
+ * e: number[];
113
+ * }, {
114
+ * b: {
115
+ * c: string;
116
+ * };
117
+ * }]>;
118
+ *
119
+ * type f = CheckType<_Separate<
120
+ * {
121
+ * v: () => Buffer,
122
+ * w: (() => string) & { n: string }
123
+ * }
124
+ * >, [{
125
+ * v: () => Buffer,
126
+ * }, {
127
+ * w: (() => string) & { n: string }
128
+ * }]>;
129
+ */
130
+ export type _Separate<T, P = {
131
+ [K in keyof T as IfStructure<T[K], never, K>]: T[K];
132
+ }, S = {
133
+ [K in keyof T as IfStructure<T[K], K, never>]: T[K];
134
+ }> = [P, S];
135
+ /**
136
+ * @summary Separate structure object `T` to `[<Plain>, <Structural>]`
137
+ * @template T Structure object for separate
138
+ * @returns `[<Plain>, <Structural>]`
139
+ * @example
140
+ * type nv = CheckType<Separate<never>, never>;
141
+ * type ud = CheckType<Separate<undefined>, never>;
142
+ * type n = CheckType<Separate<number>, never>;
143
+ * type s = CheckType<Separate<string>, never>;
144
+ * type a = CheckType<Separate<[]>, never>;
145
+ * type d = CheckType<Separate<Date>, never>;
146
+ * type b = CheckType<Separate<Buffer>, never>;
147
+ * type mp = CheckType<Separate<Map<unknown, unknown>>, never>;
148
+ * type st = CheckType<Separate<Set<unknown>>, never>;
149
+ *
150
+ * type o = CheckType<Separate<{}>, [{}, {}]>;
151
+ * type ob = CheckType<Separate<object>, [object, object]>;
152
+ *
153
+ * type x = CheckType<Separate<
154
+ * { a: number; b: { c: string }, d: string, e: number[] }
155
+ * >, [{
156
+ * a: number;
157
+ * d: string;
158
+ * e: number[];
159
+ * }, {
160
+ * b: {
161
+ * c: string;
162
+ * };
163
+ * }]>;
164
+ *
165
+ * type f = CheckType<Separate<
166
+ * {
167
+ * v: () => Buffer,
168
+ * w: (() => string) & { n: string }
169
+ * }
170
+ * >, [{
171
+ * v: () => Buffer,
172
+ * }, {
173
+ * w: (() => string) & { n: string }
174
+ * }]>;
175
+ */
176
+ export type Separate<T> = T extends undefined ? never : IfStructure<T> extends true ? _Separate<T> : never;
177
+ /**
178
+ * @summary Reverse structure `object` `T` to map value-key.\
179
+ * Non keyable values is ignored\
180
+ * except `object` if defined `TProviderFiled` and it's have this key
181
+ * @template T Structure object for reverse
182
+ * @template TProviderFiled Sub key of `object` values for extract value
183
+ * @example
184
+ * type r_simple = CheckType<
185
+ * Reverse<{ x: 1; y: 'ABC'; z: { a: true } }>,
186
+ * {
187
+ * 1: 'x';
188
+ * ABC: 'y';
189
+ * }
190
+ * >;
191
+ *
192
+ * type r_provider = CheckType<
193
+ * Reverse<{ x: 1; y: 'ABC'; z: { a: 15 } }, 'a'>,
194
+ * {
195
+ * 1: 'x';
196
+ * ABC: 'y';
197
+ * 15: 'z';
198
+ * }
199
+ * >;
200
+ */
201
+ export type Reverse<T extends object, TProviderFiled extends Key = undefined> = {
202
+ [K in keyof T as T[K] extends Key ? T[K] : T[K] extends {
203
+ [K0 in TProviderFiled]: unknown;
204
+ } ? Extract<T[K][TProviderFiled], Key> : never]: K;
205
+ };
206
+ type _Split<O extends object, Keys extends readonly (keyof O)[], R extends Arr = []> = Keys extends readonly [infer F extends keyof O, ...infer Rest extends (keyof O)[]] ? _Split<O, Rest, [
207
+ ...R,
208
+ {
209
+ [K in F]: O[F];
210
+ }
211
+ ]> : R;
212
+ /**
213
+ * @summary Split structural object `O` to array of objects with one field in each
214
+ * @template O Object to split.
215
+ * @returns Array of objects for each key or `never` if not structural object passed as `O`
216
+ * @see Union.ToTuple
217
+ * @example
218
+ * type n = CheckType<Split<never>, never>;
219
+ * type u = CheckType<Split<undefined>, undefined>;
220
+ *
221
+ * type a1 = CheckType<Split<[]>, never>;
222
+ * type a2 = CheckType<Split<[1, 2, 3]>, never>;
223
+ *
224
+ * type d3 = {
225
+ * a: number;
226
+ * b: string;
227
+ * c: { x: bigint }
228
+ * };
229
+ * type r3 = [
230
+ * { a: number; },
231
+ * { b: string; },
232
+ * { c: { x: bigint; }; }
233
+ * ];
234
+ * type s3 = CheckType<Split<d3>, r3>;
235
+ *
236
+ * type d6 = d3 & {
237
+ * d: object;
238
+ * e: string[];
239
+ * f: { y: undefined }
240
+ * };
241
+ * type r6 = [
242
+ * ...r3,
243
+ * { d: object },
244
+ * { e: string[] },
245
+ * { f: { y: undefined } }
246
+ * ];
247
+ * type s6 = CheckType<Split<d6>, r6>;
248
+ *
249
+ * type d7 = d6 & {
250
+ * g: Buffer;
251
+ * };
252
+ * type r7 = [
253
+ * ...r6,
254
+ * { g: Buffer; }
255
+ * ];
256
+ *
257
+ * type s7 = CheckType<Split<d7>, r7>;
258
+ */
259
+ export type Split<O extends object> = O extends undefined ? undefined : IfStructure<O> extends true ? _Split<O, Extract<Union.ToTuple<keyof O>, readonly (keyof O)[]>> : never;
260
+ type _Combine<A extends readonly object[], R extends object = {}> = A extends readonly [infer F extends object, ...infer Rest extends object[]] ? _Combine<Rest, R & F> : {
261
+ [K in keyof R]: R[K];
262
+ };
263
+ /**
264
+ * @summary Combine array `A` of structural object parts
265
+ * @template A Array to combine
266
+ * @returns Structural object or `never`
267
+ * @example
268
+ * type n = CheckType<Combine<never>, never>;
269
+ * type u = CheckType<Combine<undefined>, undefined>;
270
+ *
271
+ * type s = CheckType<
272
+ * Combine<readonly [
273
+ * { a: number },
274
+ * { b: string },
275
+ * { c: { x: bigint } }
276
+ * ]>,
277
+ * {
278
+ * a: number;
279
+ * b: string;
280
+ * c: { x: bigint; };
281
+ * }
282
+ * >;
283
+ *
284
+ * type a1 = CheckType<Combine<[]>, {}>;
285
+ */
286
+ export type Combine<A extends readonly object[]> = A extends undefined ? A : A extends ArrN ? _Combine<A> : never;
287
+ export {};
288
+ }
289
+ }
@@ -0,0 +1,64 @@
1
+ declare namespace AVStantso {
2
+ namespace TS {
3
+ /**
4
+ * @summary Available types for value
5
+ */
6
+ type Type = Literal.Map[Literal];
7
+ }
8
+ namespace Code {
9
+ namespace TS {
10
+ namespace Type {
11
+ /**
12
+ * @summary Create type definition array `[<key>, <type literal>, <default value>?]`
13
+ */
14
+ type KLD = {
15
+ /**
16
+ * @summary Create type definition array `[<key>, <type literal>, <default value>?]`
17
+ * @template K Key constraint
18
+ * @template L Literal constraint
19
+ * @template D Default constraint
20
+ * @param key Key value
21
+ * @param type Literal type value
22
+ * @param def Resolved type default value
23
+ */
24
+ <K extends AVStantso.TS.Key, L extends AVStantso.TS.Literal, D extends AVStantso.TS.Resolve<L> = undefined>(key: K, type: L, def?: D): AVStantso.TS.Type.KLD<K, L, D>;
25
+ /**
26
+ * @summary Parse params like `[K, L]` or `[[K, L]]`
27
+ *
28
+ * `⚠ Without strict control`
29
+ */
30
+ Parse(params: AVStantso.TS.Arr): AVStantso.TS.Type.KLD;
31
+ };
32
+ }
33
+ /**
34
+ * @summary `AVStantso.TS.Type` utility
35
+ */
36
+ interface Type {
37
+ /**
38
+ * @summary Create keyed type definition structure
39
+ * @template K Key constraint
40
+ * @template L Literal constraint
41
+ * @param key Key value
42
+ * @param type Literal type value
43
+ */
44
+ KeyDef<K extends AVStantso.TS.Key, L extends AVStantso.TS.Literal>(key: K, type: L): AVStantso.TS.Type.KeyDef.Make<K, L>;
45
+ /**
46
+ * @summary Create type definition array `[<key>, <type literal>, <default value>?]`
47
+ * @template K Key constraint
48
+ * @template L Literal constraint
49
+ * @template D Default constraint
50
+ * @param key Key value
51
+ * @param type Literal type value
52
+ * @param def Resolved type default value
53
+ */
54
+ KLD: Type.KLD;
55
+ }
56
+ }
57
+ interface TS {
58
+ /**
59
+ * @summary `AVStantso.TS.Type` utility
60
+ */
61
+ Type: TS.Type;
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,47 @@
1
+ declare namespace AVStantso.TS.Type {
2
+ /**
3
+ * @summary Type definition structure
4
+ */
5
+ type Def = {
6
+ /**
7
+ * @summary Literal
8
+ */
9
+ L: Literal;
10
+ /**
11
+ * @summary Type
12
+ */
13
+ T?: unknown;
14
+ } | {
15
+ L?: Literal;
16
+ T: unknown;
17
+ };
18
+ namespace Def {
19
+ /**
20
+ * @summary Make type definition structure
21
+ */
22
+ type Make<T, L extends Literal = undefined> = L extends undefined ? {
23
+ T: T;
24
+ } : {
25
+ L: L;
26
+ T: T;
27
+ };
28
+ /**
29
+ * @summary Get type definition structure from type union or structure, and literal
30
+ */
31
+ type From<T, L extends Literal> = T extends Def ? Make<T['T'], IfDefKey<'L', Def, T> | (L extends undefined ? never : L)> : Make<T, L>;
32
+ namespace Or {
33
+ /**
34
+ * @summary Type definition structure or literal
35
+ */
36
+ type L = Def | Literal;
37
+ }
38
+ /**
39
+ * @summary Test type is `TS.Type.Def`
40
+ * @template TOrDef Tested `TS.Type.Def`
41
+ * @template IfTrue Result, if `TOrDef` is `TS.Type.TArr`
42
+ * @template IfFalse Result, if `TOrDef` NOT is `TS.Type.TArr`
43
+ * @returns `IfFalse` or `IfTrue` param
44
+ */
45
+ type Is<TOrDef, IfTrue = true, IfFalse = false> = TOrDef extends Def ? IfTrue : IfFalse;
46
+ }
47
+ }
@@ -0,0 +1,7 @@
1
+ import './_register';
2
+ import './key-literal-default-arr';
3
+ import './def';
4
+ import './key-arr-def';
5
+ import './key-def';
6
+ import './not';
7
+ import './union';
@@ -0,0 +1,14 @@
1
+ declare namespace AVStantso.TS.Type {
2
+ /**
3
+ * @summary Key or type definition array or keyed type definition structure
4
+ */
5
+ type KeyArrDef = Key | KLD | KeyDef;
6
+ namespace KeyArrDef {
7
+ /**
8
+ * @summary Constraint for `TS.Type.KeyArrDef` next type parameter
9
+ * @template TKeyArrDef Type def for constraint
10
+ * @template TIfSatisfy Type if constraint is satisfied
11
+ */
12
+ type Constraint<TKeyArrDef extends KeyArrDef, TIfSatisfy = unknown> = TKeyArrDef extends object ? never : TIfSatisfy;
13
+ }
14
+ }
@@ -0,0 +1,76 @@
1
+ declare namespace AVStantso.TS.Type {
2
+ /**
3
+ * @summary Keyed type definition structure
4
+ */
5
+ type KeyDef = {
6
+ /**
7
+ * @summary Key
8
+ */
9
+ K: Key;
10
+ } & Def;
11
+ namespace KeyDef {
12
+ /**
13
+ * @summary Keyed type definition abstract structure
14
+ */
15
+ export type Abstract = {
16
+ K: Key;
17
+ } & Def;
18
+ type _Make<K extends Key, DL extends Def.Or.L, TforL extends Make.Constraint<DL>, Debug extends boolean, T = DL extends Def ? Extract<keyof DL, 'T'> extends never ? {} : {
19
+ T: DL['T'];
20
+ } : [TforL] extends [never] ? {} : {
21
+ T: TforL;
22
+ }, L = DL extends Def ? Extract<keyof DL, 'L'> extends never ? {} : {
23
+ L: DL['L'];
24
+ } : {
25
+ L: DL;
26
+ }, KD = {
27
+ K: K;
28
+ } & T & L, R = Debug extends true ? {
29
+ K: K;
30
+ DL: DL;
31
+ T: T;
32
+ L: L;
33
+ KD: KD;
34
+ } : {
35
+ [K in keyof KD]: KD[K];
36
+ }> = R;
37
+ /**
38
+ * @summary Make keyed type definition structure by `Key` and `Def`
39
+ */
40
+ export type Make<K extends Key, DL extends Def.Or.L, T extends Make.Constraint<DL> = never> = _Make<K, DL, T, false>;
41
+ export namespace Make {
42
+ /**
43
+ * @summary Constraint for last params in kake keyed type definition structure by `Key` and `Def`
44
+ */
45
+ type Constraint<DL extends Def.Or.L> = DL extends Def ? never : unknown;
46
+ }
47
+ type _From<TKA extends Key | KLD, T extends KeyArrDef.Constraint<TKA>, Debug extends boolean, K extends Key = TKA extends KLD ? TKA[0] : TKA, P = TKA extends KLD ? TKA[1] : T, L = {} extends P ? never : Extract<Literal, P>, O = Exclude<P, Literal>, D = (L extends never ? never : {
48
+ L: L;
49
+ }) | (O extends never ? never : {
50
+ T: O;
51
+ }), R = {
52
+ K: K;
53
+ } & D> = Debug extends true ? {
54
+ TKeyOrArr: TKA;
55
+ TProperty: T;
56
+ K: K;
57
+ L: L;
58
+ O: O;
59
+ D: D;
60
+ R: R;
61
+ } : R;
62
+ /**
63
+ * @summary Get keyed type definition structure from `TS.Type.KeyArrDef` and property type `T`
64
+ */
65
+ export type From<TKAD extends KeyArrDef, T extends KeyArrDef.Constraint<TKAD> = KeyArrDef.Constraint<TKAD>> = TKAD extends KeyDef ? TKAD : _From<Exclude<TKAD, KeyDef>, T, false>;
66
+ /**
67
+ * @summary Merge keyed type definition structure with type field `T`
68
+ */
69
+ export type Merge<KD extends KeyDef, T = unknown> = Omit<KD, 'T'> & (Extract<'T', keyof KD> extends never ? {
70
+ T: T;
71
+ } : {
72
+ T: KD['T'] | T;
73
+ });
74
+ export {};
75
+ }
76
+ }
@@ -0,0 +1,45 @@
1
+ declare namespace AVStantso.TS.Type {
2
+ /**
3
+ * @summary Type definition array `[<key>, <type literal>, <default value>?]`
4
+ * @template K Key constraint
5
+ * @template L Literal constraint
6
+ * @template D Default value
7
+ */
8
+ type KLD<K extends Key = Key, L extends Literal = Literal, D extends Resolve<L> = any> = [K, L, D?];
9
+ namespace KLD {
10
+ /**
11
+ * @summary Type definition map by array of definition arrays
12
+ */
13
+ export namespace Map {
14
+ /**
15
+ * @summary Type definition map item with default value
16
+ * @template L Literal constraint
17
+ * @template D Default value
18
+ */
19
+ type DefRec<L extends Literal = Literal, D extends Resolve<L> = any> = {
20
+ type: L;
21
+ def: D;
22
+ };
23
+ /**
24
+ * @summary Type definition map item depend on `TAllowDefaults`
25
+ * @template TAllowDefaults If 'true' — allow put default values into map
26
+ * @template L Literal constraint
27
+ * @template D Default value
28
+ */
29
+ type Item<TAllowDefaults extends boolean, L extends Literal = Literal, D extends Resolve<L> = any> = TAllowDefaults extends true ? DefRec<L, D> : L;
30
+ }
31
+ export type Map<TAllowDefaults extends boolean> = NodeJS.Dict<Map.Item<TAllowDefaults>>;
32
+ type _ToMap<TArrOfArr extends KLD[], TAllowDefaults extends boolean, R extends {} = {}, I extends number = 0> = AVStantso.TS.Array.IfEnd<TArrOfArr, I> extends true ? {
33
+ [K in keyof R]: R[K];
34
+ } : _ToMap<TArrOfArr, TAllowDefaults, R & {
35
+ [K in TArrOfArr[I][0]]: Map.Item<TAllowDefaults, TArrOfArr[I][1], TArrOfArr[I][2]>;
36
+ }, AVStantso.TS.Increment<I>>;
37
+ /**
38
+ * @summary Create type definition map by array of definition arrays
39
+ * @template TArrOfArr Array of definition arrays
40
+ * @template TAllowDefaults If 'true' — allow put default values into map
41
+ */
42
+ export type ToMap<TArrOfArr extends KLD[], TAllowDefaults extends boolean = false> = _ToMap<TArrOfArr, TAllowDefaults>;
43
+ export {};
44
+ }
45
+ }
@@ -0,0 +1,44 @@
1
+ declare namespace AVStantso.TS.Type {
2
+ type _Not<T extends Type | Literal, Debug extends boolean, L = HasString<T, never, Extract<Literal, T>>, O = Exclude<T, Literal>, R = L | true extends true ? Exclude<Type, O> : O | true extends true ? Exclude<Literal, L> : never> = Debug extends true ? {
3
+ T: T;
4
+ L: L;
5
+ O: O;
6
+ R: R;
7
+ } : R;
8
+ /**
9
+ * @summary Available types for value (`Type`) xor `Literal`, exclude specified.
10
+ * If `T` union includes `string` — literals is ignored,
11
+ * else if types and literals is mixed — returns `never`
12
+ * @example
13
+ * type xor = CheckType<Not<boolean | 'boolean'>, never>;
14
+ *
15
+ * type s = CheckType<Not<string>, number | bigint | boolean | symbol | object | Function>;
16
+ *
17
+ * // ⚠ literals is ignored:
18
+ * type tslb = CheckType<
19
+ * Not<string | 'boolean'>,
20
+ * number | bigint | boolean | symbol | object | Function
21
+ * >;
22
+ *
23
+ * type lbls = CheckType<
24
+ * Not<'boolean' | 'string'>,
25
+ * 'number' | 'bigint' | 'symbol' | 'undefined' | 'object' | 'function' | 'Date' | 'Buffer'
26
+ * >;
27
+ */
28
+ export type Not<T extends Type | Literal> = _Not<T, false>;
29
+ export namespace Not {
30
+ /**
31
+ * @summary Available types for value, exclude `Function`
32
+ */
33
+ type Function = Exclude<Type, globalThis.Function>;
34
+ /**
35
+ * @summary Available types for value, exclude `object`
36
+ */
37
+ type Object = Exclude<Type, object>;
38
+ /**
39
+ * @summary Available types for value, exclude `string`
40
+ */
41
+ type String = Exclude<Type, string>;
42
+ }
43
+ export {};
44
+ }
@@ -0,0 +1,33 @@
1
+ declare namespace AVStantso.TS.Type {
2
+ type _Union<TOrDef, TLiteral extends Union.Constraint<TOrDef>, Debug extends boolean, L extends Literal = TOrDef extends Def ? IfDefKey<'L', Def, TOrDef, never> : TLiteral, O = TOrDef extends Def ? IfDefKey<'T', Def, TOrDef> : TOrDef, R = HasString<O, O, O | L>> = Debug extends true ? {
3
+ TOrDef: TOrDef;
4
+ TLiteral: TLiteral;
5
+ L: L;
6
+ O: O;
7
+ R: R;
8
+ } : R;
9
+ /**
10
+ * @summary Type union `T` with `Literal`.
11
+ * With type `string` literals NOT supported
12
+ * @example
13
+ * type nv = CheckType<Union<never>, never>;
14
+ * type ud = CheckType<Union<undefined>, unknown>;
15
+ *
16
+ * // ⛔ literals NOT supported:
17
+ * type ts = CheckType<Union<string | 'bigint'>, string>;
18
+ *
19
+ * type r0 = CheckType<Union<number, 'string' | 'bigint'>, number | 'string' | 'bigint'>;
20
+ *
21
+ * type r1 = CheckType<Union<{ T: Function; L: 'boolean' }>, 'boolean' | Function>;
22
+ *
23
+ * type r2 = CheckType<Union<object>, object | Literal>;
24
+ */
25
+ export type Union<TOrDef, TLiteral extends Union.Constraint<TOrDef> = Union.Constraint<TOrDef>> = _Union<TOrDef, TLiteral, false>;
26
+ export namespace Union {
27
+ /**
28
+ * @summary Constraint for `TS.Type.Union` second type parameter
29
+ */
30
+ type Constraint<TOrDef> = Def.Is<TOrDef, never, Literal>;
31
+ }
32
+ export {};
33
+ }