@avstantso/ts 1.1.0 → 1.3.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 (57) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +77 -4
  3. package/dist/_global/_register.d.ts +80 -0
  4. package/dist/_global/array/_register.d.ts +28 -0
  5. package/dist/_global/array/arr-n.d.ts +21 -0
  6. package/dist/_global/array/create.d.ts +59 -0
  7. package/dist/_global/array/derivative.d.ts +229 -0
  8. package/dist/_global/array/find.d.ts +89 -0
  9. package/dist/_global/array/index.d.ts +8 -0
  10. package/dist/_global/array/low-level.d.ts +84 -0
  11. package/dist/_global/array/map-key-value.d.ts +121 -0
  12. package/dist/_global/array/min-max-sort.d.ts +244 -0
  13. package/dist/_global/ascii.d.ts +84 -0
  14. package/dist/_global/boolean.d.ts +74 -0
  15. package/dist/_global/comparisons.d.ts +85 -0
  16. package/dist/_global/func.d.ts +17 -0
  17. package/dist/_global/index.d.ts +14 -0
  18. package/dist/_global/literal.d.ts +184 -0
  19. package/dist/_global/numeric/domain/describes.d.ts +62 -0
  20. package/dist/_global/numeric/domain/generated.d.ts +11240 -0
  21. package/dist/_global/numeric/domain/inc-dec.d.ts +52 -0
  22. package/dist/_global/numeric/domain/independent.d.ts +203 -0
  23. package/dist/_global/numeric/domain/index.d.ts +4 -0
  24. package/dist/_global/numeric/inc-dec.d.ts +50 -0
  25. package/dist/_global/numeric/index.d.ts +3 -0
  26. package/dist/_global/numeric/math.d.ts +257 -0
  27. package/dist/_global/resolve.d.ts +45 -0
  28. package/dist/_global/string.d.ts +335 -0
  29. package/dist/_global/structure/_register.d.ts +93 -0
  30. package/dist/_global/structure/index.d.ts +2 -0
  31. package/dist/_global/structure/structure.d.ts +289 -0
  32. package/dist/_global/type/_register.d.ts +70 -0
  33. package/dist/_global/type/def.d.ts +47 -0
  34. package/dist/_global/type/index.d.ts +7 -0
  35. package/dist/_global/type/key-arr-def.d.ts +14 -0
  36. package/dist/_global/type/key-def.d.ts +76 -0
  37. package/dist/_global/type/key-literal-default-arr.d.ts +45 -0
  38. package/dist/_global/type/not.d.ts +44 -0
  39. package/dist/_global/type/union.d.ts +33 -0
  40. package/dist/_global/union.d.ts +79 -0
  41. package/dist/_global/utility/alt.d.ts +58 -0
  42. package/dist/_global/utility/flat.d.ts +60 -0
  43. package/dist/_global/utility/if-def.d.ts +22 -0
  44. package/dist/_global/utility/index.d.ts +9 -0
  45. package/dist/_global/utility/merge.d.ts +29 -0
  46. package/dist/_global/utility/opaque.d.ts +17 -0
  47. package/dist/_global/utility/options.d.ts +34 -0
  48. package/dist/_global/utility/override.d.ts +100 -0
  49. package/dist/_global/utility/replace-key.d.ts +33 -0
  50. package/dist/_global/utility/required-optional.d.ts +24 -0
  51. package/dist/_std-ext/index.d.ts +1 -0
  52. package/dist/_std-ext/object.d.ts +23 -0
  53. package/dist/export.d.ts +2 -0
  54. package/dist/index.d.ts +4 -0
  55. package/dist/index.js +480 -0
  56. package/dist/index.js.map +1 -0
  57. package/package.json +3 -3
@@ -0,0 +1,85 @@
1
+ declare namespace AVStantso.TS {
2
+ type Args<Item1 = unknown, Item2 = Item1, IfTrue = unknown, IfFalse = unknown> = [Item1, Item2, IfTrue, IfFalse];
3
+ namespace Number {
4
+ type _LT_For<Ag extends Args<number>, I extends number = 0> = I extends Ag[0] ? Ag[2] : I extends Ag[1] ? Ag[3] : _LT_For<Ag, Increment<I>>;
5
+ type _LT_Digit<Ag extends Args<Arr>> = Ag[0] extends [`${infer AF extends number}`, ...infer ARest] ? Ag[1] extends [`${infer BF extends number}`, ...infer BRest] ? AF extends BF ? _LT_Digit<[ARest, BRest, Ag[2], Ag[3]]> : _LT_For<[AF, BF, Ag[2], Ag[3]]> : never : never;
6
+ type _LT_Length<Ag extends Args<number>, LA extends number = TS.String._Length<`${Ag[0]}`>, LB extends number = TS.String._Length<`${Ag[1]}`>> = LA extends LB ? _LT_Digit<[
7
+ TS.String._SplitToChars<`${Ag[0]}`>,
8
+ TS.String._SplitToChars<`${Ag[1]}`>,
9
+ Ag[2],
10
+ Ag[3]
11
+ ]> : _LT_For<[LA, LB, Ag[2], Ag[3]]>;
12
+ type _LT_Sign<Ag extends Args<number>> = `${Ag[0]}` extends `-${infer A extends number}` ? `${Ag[1]}` extends `-${infer B extends number}` ? _LT_Length<[B, A, Ag[2], Ag[3]]> : Ag[2] : `${Ag[1]}` extends `-${number}` ? Ag[3] : _LT_Length<Ag>;
13
+ }
14
+ namespace String {
15
+ type _LT<Ag extends Args<string>> = Ag[0] extends `${infer AC}${infer AE}` ? Ag[1] extends `${infer BC}${infer BE}` ? AC extends BC ? _LT<[AE, BE, Ag[2], Ag[3]]> : Number._LT_Length<[ASCII.Code<AC>, ASCII.Code<BC>, Ag[2], Ag[3]]> : Ag[3] : Ag[2];
16
+ }
17
+ /**
18
+ * @summary Low-level test `Eq===true ? A <= B : A < B`
19
+ * @template Ag Arguments `[A, B, IfTrue, IfFalse]`
20
+ * @template Eq `true` — `<=`, `false` — `<`
21
+ * @returns `Ag[2] | Ag[3]`
22
+ * @example
23
+ * type nt = CheckType<_LT<[1, 2, true, false]>, true>;
24
+ * type st = CheckType<_LT<['a', 'b', true, false]>, true>;
25
+ * type nf = CheckType<_LT<[2, 1, true, false]>, false>;
26
+ * type sf = CheckType<_LT<['c', 'b', true, false]>, false>;
27
+ *
28
+ * type n_large_p = CheckType<_LT<[9999998, 9999999, true, false]>, true>;
29
+ * type n_large_n = CheckType<_LT<[-9999999, -9999998, true, false]>, true>;
30
+ */
31
+ export type _LT<Ag extends Args, Eq extends boolean = false> = Ag[0] extends Ag[1] ? Eq extends true ? Ag[2] : Ag[3] : Ag extends [number, number, unknown, unknown] ? Number._LT_Sign<Ag> : Ag extends [string, string, unknown, unknown] ? String._LT<Ag> : never;
32
+ /**
33
+ * @summary Low-level test `Eq===true ? IsLT===true ? A <= B : A => B : IsLT ? A < B : A > B`
34
+ * @template Ag Arguments `[A, B, IfTrue, IfFalse]`
35
+ * @template IsLT `true` — `<`, `false` — `>`
36
+ * @template Eq `true` — `<=`, `false` — `<`
37
+ * @returns `Ag[2] | Ag[3]`
38
+ * @example
39
+ * type nt = CheckType<_LT_GT<[1, 2, true, false], true>, true>;
40
+ * type st = CheckType<_LT_GT<['a', 'b', true, false], true>, true>;
41
+ * type nf = CheckType<_LT_GT<[2, 1, true, false], true>, false>;
42
+ * type sf = CheckType<_LT_GT<['c', 'b', true, false], true>, false>;
43
+ *
44
+ * type n_large_p = CheckType<_LT_GT<[9999998, 9999999, true, false], true>, true>;
45
+ * type n_large_n = CheckType<_LT_GT<[-9999999, -9999998, true, false], true>, true>;
46
+ */
47
+ export type _LT_GT<Ag extends Args, IsLT extends boolean, Eq extends boolean = false> = _LT<IsLT extends true ? Ag : [Ag[1], Ag[0], Ag[2], Ag[3]], Eq>;
48
+ /**
49
+ * @summary Test `A < B`
50
+ * @template A argument for comparision
51
+ * @template B argument for comparision
52
+ * @template IfTrue Result, if `A < B`
53
+ * @template IfFalse Result, if `A >= B`
54
+ * @returns `IfFalse` or `IfTrue` param
55
+ */
56
+ export type LT<A extends number | string, B extends number | string, IfTrue = true, IfFalse = false> = _LT<[A, B, IfTrue, IfFalse]>;
57
+ /**
58
+ * @summary Test `A <= B`
59
+ * @template A argument for comparision
60
+ * @template B argument for comparision
61
+ * @template IfTrue Result, if `A <= B`
62
+ * @template IfFalse Result, if `A > B`
63
+ * @returns `IfFalse` or `IfTrue` param
64
+ */
65
+ export type LTE<A extends number | string, B extends number | string, IfTrue = true, IfFalse = false> = _LT<[A, B, IfTrue, IfFalse], true>;
66
+ /**
67
+ * @summary Test `A > B`
68
+ * @template A argument for comparision
69
+ * @template B argument for comparision
70
+ * @template IfTrue Result, if `A > B`
71
+ * @template IfFalse Result, if `A <= B`
72
+ * @returns `IfFalse` or `IfTrue` param
73
+ */
74
+ export type GT<A extends number | string, B extends number | string, IfTrue = true, IfFalse = false> = _LT<[B, A, IfTrue, IfFalse]>;
75
+ /**
76
+ * @summary Test `A >= B`
77
+ * @template A argument for comparision
78
+ * @template B argument for comparision
79
+ * @template IfTrue Result, if `A >= B`
80
+ * @template IfFalse Result, if `A < B`
81
+ * @returns `IfFalse` or `IfTrue` param
82
+ */
83
+ export type GTE<A extends number | string, B extends number | string, IfTrue = true, IfFalse = false> = _LT<[B, A, IfTrue, IfFalse], true>;
84
+ export {};
85
+ }
@@ -0,0 +1,17 @@
1
+ declare namespace AVStantso.TS.Func {
2
+ /**
3
+ * @summary Nested function type
4
+ * @template Depth nesting depth
5
+ * @example
6
+ * type n = CheckType<Nested<never>, never>;
7
+ * type u = CheckType<Nested<undefined>, (...params: Arr) => unknown>;
8
+ *
9
+ * type r0 = CheckType<Nested<0>, (...params: Arr) => unknown>;
10
+ * type r1 = CheckType<Nested<1>, (...params: Arr) => (...params: Arr) => unknown>;
11
+ * type r2 = CheckType<
12
+ * Nested<2>,
13
+ * (...params: Arr) => (...params: Arr) => (...params: Arr) => unknown
14
+ * >;
15
+ */
16
+ type Nested<Depth extends number = 1, R = unknown, P extends Arr = Arr> = Depth extends 0 ? Func<R, P> : Func<Nested<Decrement<Depth>, R, P>>;
17
+ }
@@ -0,0 +1,14 @@
1
+ import './_register';
2
+ import './func';
3
+ import './union';
4
+ import './array';
5
+ import './ascii';
6
+ import './boolean';
7
+ import './comparisons';
8
+ import './numeric';
9
+ import './string';
10
+ import './literal';
11
+ import './structure';
12
+ import './resolve';
13
+ import './type';
14
+ import './utility';
@@ -0,0 +1,184 @@
1
+ declare namespace AVStantso {
2
+ namespace TS {
3
+ /**
4
+ * @summary Literal for available types for value
5
+ */
6
+ type Literal = keyof Literal.Map & {};
7
+ namespace Literal {
8
+ /**
9
+ * @summary Map for available builtin types for value
10
+ */
11
+ type Builtins = {
12
+ string: string;
13
+ number: number;
14
+ bigint: bigint;
15
+ boolean: boolean;
16
+ symbol: symbol;
17
+ undefined: undefined;
18
+ object: object;
19
+ function: Function;
20
+ };
21
+ /**
22
+ * @summary Union for available builtin types for value
23
+ */
24
+ type Builtin = keyof Builtins & {};
25
+ /**
26
+ * @summary Map for available types for value
27
+ */
28
+ interface Map extends AtomicObjects, Builtins {
29
+ }
30
+ /**
31
+ * @summary Map for number-like types.
32
+ *
33
+ * ⚠ Key is significant, value ignored
34
+ */
35
+ interface NumberLike {
36
+ number: 0;
37
+ bigint: 0;
38
+ Date: 0;
39
+ }
40
+ /**
41
+ * @summary If `L` is number-like returns `IfTrue` else `IfFalse`
42
+ * @template L Tested literal
43
+ * @template IfTrue Result, if `L` is number-like
44
+ * @template IfFalse Result, if `L` NOT is number-like
45
+ * @returns `IfFalse` or `IfTrue` param
46
+ * @example
47
+ * type n = CheckType<IsNumberLike<never>, never>;
48
+ * type u = CheckType<IsNumberLike<undefined>, undefined>;
49
+ *
50
+ * type t = CheckType<IsNumberLike<'number'>, true>;
51
+ * type f = CheckType<IsNumberLike<'object'>, false>;
52
+ */
53
+ type IsNumberLike<L extends Literal, IfTrue = true, IfFalse = false> = L extends undefined ? undefined : [Extract<L, keyof NumberLike>] extends [never] ? IfFalse : IfTrue;
54
+ /**
55
+ * @summary Map for string-like types.
56
+ *
57
+ * ⚠ Key is significant, value ignored
58
+ */
59
+ interface StringLike {
60
+ string: 0;
61
+ Buffer: 0;
62
+ }
63
+ /**
64
+ * @summary If `L` is string-like returns `IfTrue` else `IfFalse`
65
+ * @template L Tested literal
66
+ * @template IfTrue Result, if `L` is string-like
67
+ * @template IfFalse Result, if `L` NOT is string-like
68
+ * @returns `IfFalse` or `IfTrue` param
69
+ * @example
70
+ * type n = CheckType<IsStringLike<never>, never>;
71
+ * type u = CheckType<IsStringLike<undefined>, undefined>;
72
+ *
73
+ * type t = CheckType<IsStringLike<'string'>, true>;
74
+ * type f = CheckType<IsStringLike<'object'>, false>;
75
+ */
76
+ type IsStringLike<L extends Literal, IfTrue = true, IfFalse = false> = L extends undefined ? undefined : [Extract<L, keyof StringLike>] extends [never] ? IfFalse : IfTrue;
77
+ /**
78
+ * @summary Literals array for available types for value
79
+ */
80
+ type List = Union.ToTuple<Literal>;
81
+ namespace List {
82
+ /**
83
+ * @summary Literals array for available builtin types for value
84
+ */
85
+ type Builtins = Union.ToTuple<keyof Literal.Builtins>;
86
+ /**
87
+ * @summary Literals array for available builtin object key types for value
88
+ */
89
+ type CanBeObjKey = ['string', 'number', 'symbol'];
90
+ /**
91
+ * @summary Literals array for available builtin structural types for value
92
+ */
93
+ type Structural = ['object', 'function'];
94
+ }
95
+ /**
96
+ * @summary Literals key-to-key record
97
+ */
98
+ type Key2KeyRec = Array._ToKey2Key<List>;
99
+ }
100
+ }
101
+ namespace Code {
102
+ namespace TS {
103
+ /**
104
+ * @summary Literals key-to-key record + utils
105
+ */
106
+ interface Literal extends AVStantso.TS.Literal.Key2KeyRec {
107
+ /**
108
+ * @summary Literals array for available builtin types for value
109
+ */
110
+ Builtins: readonly [...AVStantso.TS.Literal.List.Builtins];
111
+ /**
112
+ * @summary Literals array for available builtin object key types for value
113
+ */
114
+ CanBeObjKey: readonly [...AVStantso.TS.Literal.List.CanBeObjKey];
115
+ /**
116
+ * @summary Literals array for available builtin structural types for value
117
+ */
118
+ Structural: readonly [...AVStantso.TS.Literal.List.Structural];
119
+ /**
120
+ * @summary Literals array for available types for value
121
+ */
122
+ List: AVStantso.TS.Literal.List;
123
+ /**
124
+ * @summary Empty value for `Literal`
125
+ * @param type Type literal
126
+ * @returns Resolved literal empty value
127
+ */
128
+ Empty: {
129
+ /**
130
+ * @summary Empty value for `Literal`
131
+ * @param type Type literal
132
+ * @returns Resolved literal empty value
133
+ */
134
+ <L extends AVStantso.TS.Literal>(type: L): AVStantso.TS.Resolve<L>;
135
+ } & {
136
+ [K in AVStantso.TS.Literal]: AVStantso.TS.Resolve<K>;
137
+ };
138
+ /**
139
+ * @summary Is `value` a resolved `type` of `L`
140
+ * @param type Type literal
141
+ * @param value Tested value
142
+ */
143
+ IsValue: {
144
+ /**
145
+ * @summary Is `value` a resolved `type` of `L`
146
+ * @param type Type literal
147
+ * @param value Tested value
148
+ */
149
+ <L extends AVStantso.TS.Literal>(type: L, value: unknown): value is AVStantso.TS.Resolve<L>;
150
+ } & {
151
+ [K in AVStantso.TS.Literal]: (value: unknown) => value is AVStantso.TS.Resolve<K>;
152
+ };
153
+ /**
154
+ * @summary Registrate extended literal
155
+ * @template L Literal type
156
+ * @param literal Literal value
157
+ * @example
158
+ * type XYZ = {x: string; y: number; z: boolean; };
159
+ *
160
+ * namespace AVStantso.TS.Literal {
161
+ * export interface Map {
162
+ * xyz: XYZ;
163
+ * }
164
+ * }
165
+ *
166
+ * avstantso.TS.Literal._Register('xyz');
167
+ *
168
+ * ///////////////
169
+ *
170
+ * type t = CheckType<AVStantso.TS.Resolve<'xyz'>, XYZ>;
171
+ *
172
+ * console.log(avstantso.TS.Literal.List.includes('xyz')); // prints true
173
+ */
174
+ _Register<L extends AVStantso.TS.Literal>(literal: L, empty?: AVStantso.TS.Resolve<L>): void;
175
+ }
176
+ }
177
+ interface TS {
178
+ /**
179
+ * @summary Literals key-to-key record + utils
180
+ */
181
+ Literal: TS.Literal;
182
+ }
183
+ }
184
+ }
@@ -0,0 +1,62 @@
1
+ declare namespace AVStantso.TS {
2
+ /**
3
+ * @summary Numeric types and "functions"
4
+ */
5
+ namespace Numeric {
6
+ /**
7
+ * @summary Domain of a functions of `Numeric` type
8
+ */
9
+ namespace Domain {
10
+ /**
11
+ * @summary Numeric literals `1-max(Domain.Positive)`.
12
+ *
13
+ * Used in `Numeric` type "functions"
14
+ *
15
+ * For full ASCII need `255`
16
+ *
17
+ */
18
+ namespace Positive { }
19
+ /**
20
+ * @summary Numeric literals `-1-(-max(Domain.Negative))`.
21
+ *
22
+ * Used in `Numeric` type "functions"
23
+ *
24
+ */
25
+ namespace Negative { }
26
+ /**
27
+ * @summary Summs `0—9 x 0—9` by table.
28
+ *
29
+ * Used in `Numeric.Summ` type "functions"
30
+ */
31
+ namespace Summs {
32
+ /**
33
+ * @summary Calc summ `0—9 x 0—9` by table.
34
+ *
35
+ * Used in `Numeric.Summ` type "functions"
36
+ * @return `[<Current digit>, <Next digit coef>]`
37
+ */
38
+ type Calc<X extends number, Y extends number> = Summs[X][Y];
39
+ }
40
+ /**
41
+ * @summary Diffs `0—9 x -1—9` table.
42
+ *
43
+ * Used in `Numeric.Summ` type "functions"
44
+ */
45
+ namespace Diffs {
46
+ /**
47
+ * @summary Calc summ `0—9 x -9—9` by table.
48
+ *
49
+ * Used in `Numeric.Diff` type "functions"
50
+ * @return `[<Current digit>, <Next digit coef>]`
51
+ */
52
+ type Calc<X extends number, Y extends number> = Diffs[X][Increment<Y>];
53
+ }
54
+ /**
55
+ * @summary Power map.
56
+ *
57
+ * Used in `Numeric.Power` type "functions"
58
+ */
59
+ namespace Power { }
60
+ }
61
+ }
62
+ }