@planet-matrix/mobius-model 0.3.0 → 0.5.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/CHANGELOG.md +15 -0
- package/README.md +30 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +22 -4
- package/package.json +3 -3
- package/scripts/build.ts +4 -4
- package/src/basic/README.md +144 -0
- package/src/basic/array.ts +872 -0
- package/src/basic/bigint.ts +114 -0
- package/src/basic/boolean.ts +180 -0
- package/src/basic/enhance.ts +10 -0
- package/src/basic/error.ts +51 -0
- package/src/basic/function.ts +453 -0
- package/src/basic/helper.ts +276 -0
- package/src/basic/index.ts +17 -0
- package/src/basic/is.ts +320 -0
- package/src/basic/number.ts +178 -0
- package/src/basic/object.ts +140 -0
- package/src/basic/promise.ts +464 -0
- package/src/basic/regexp.ts +7 -0
- package/src/basic/stream.ts +140 -0
- package/src/basic/string.ts +308 -0
- package/src/basic/symbol.ts +164 -0
- package/src/basic/temporal.ts +224 -0
- package/src/encoding/README.md +105 -0
- package/src/encoding/base64.ts +98 -0
- package/src/encoding/index.ts +1 -0
- package/src/index.ts +4 -0
- package/src/random/README.md +109 -0
- package/src/random/index.ts +1 -0
- package/src/random/uuid.ts +103 -0
- package/src/type/README.md +330 -0
- package/src/type/array.ts +5 -0
- package/src/type/boolean.ts +471 -0
- package/src/type/class.ts +419 -0
- package/src/type/function.ts +1519 -0
- package/src/type/helper.ts +135 -0
- package/src/type/index.ts +14 -0
- package/src/type/intersection.ts +93 -0
- package/src/type/is.ts +247 -0
- package/src/type/iteration.ts +233 -0
- package/src/type/number.ts +732 -0
- package/src/type/object.ts +788 -0
- package/src/type/path.ts +73 -0
- package/src/type/string.ts +1004 -0
- package/src/type/tuple.ts +2424 -0
- package/src/type/union.ts +108 -0
- package/tests/unit/basic/array.spec.ts +290 -0
- package/tests/unit/basic/bigint.spec.ts +50 -0
- package/tests/unit/basic/boolean.spec.ts +74 -0
- package/tests/unit/basic/error.spec.ts +32 -0
- package/tests/unit/basic/function.spec.ts +175 -0
- package/tests/unit/basic/helper.spec.ts +118 -0
- package/tests/unit/basic/number.spec.ts +74 -0
- package/tests/unit/basic/object.spec.ts +46 -0
- package/tests/unit/basic/promise.spec.ts +232 -0
- package/tests/unit/basic/regexp.spec.ts +11 -0
- package/tests/unit/basic/stream.spec.ts +120 -0
- package/tests/unit/basic/string.spec.ts +74 -0
- package/tests/unit/basic/symbol.spec.ts +72 -0
- package/tests/unit/basic/temporal.spec.ts +78 -0
- package/tests/unit/encoding/base64.spec.ts +40 -0
- package/tests/unit/random/uuid.spec.ts +37 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/reactor/index.d.ts +0 -3
- package/dist/reactor/index.d.ts.map +0 -1
- package/dist/reactor/reactor-core/flags.d.ts +0 -99
- package/dist/reactor/reactor-core/flags.d.ts.map +0 -1
- package/dist/reactor/reactor-core/index.d.ts +0 -4
- package/dist/reactor/reactor-core/index.d.ts.map +0 -1
- package/dist/reactor/reactor-core/primitive.d.ts +0 -276
- package/dist/reactor/reactor-core/primitive.d.ts.map +0 -1
- package/dist/reactor/reactor-core/reactive-system.d.ts +0 -241
- package/dist/reactor/reactor-core/reactive-system.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/branch.d.ts +0 -19
- package/dist/reactor/reactor-operators/branch.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/convert.d.ts +0 -30
- package/dist/reactor/reactor-operators/convert.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/create.d.ts +0 -26
- package/dist/reactor/reactor-operators/create.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/filter.d.ts +0 -269
- package/dist/reactor/reactor-operators/filter.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/index.d.ts +0 -8
- package/dist/reactor/reactor-operators/index.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/join.d.ts +0 -48
- package/dist/reactor/reactor-operators/join.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/map.d.ts +0 -165
- package/dist/reactor/reactor-operators/map.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/utility.d.ts +0 -48
- package/dist/reactor/reactor-operators/utility.d.ts.map +0 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Helpers
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
interface InternalIterationMap {
|
|
6
|
+
__: [number, "__", "__", number]
|
|
7
|
+
"-50": [-50, "__", "-49", 0]
|
|
8
|
+
"-49": [-49, "-50", "-48", 1]
|
|
9
|
+
"-48": [-48, "-49", "-47", 2]
|
|
10
|
+
"-47": [-47, "-48", "-46", 3]
|
|
11
|
+
"-46": [-46, "-47", "-45", 4]
|
|
12
|
+
"-45": [-45, "-46", "-44", 5]
|
|
13
|
+
"-44": [-44, "-45", "-43", 6]
|
|
14
|
+
"-43": [-43, "-44", "-42", 7]
|
|
15
|
+
"-42": [-42, "-43", "-41", 8]
|
|
16
|
+
"-41": [-41, "-42", "-40", 9]
|
|
17
|
+
"-40": [-40, "-41", "-39", 10]
|
|
18
|
+
"-39": [-39, "-40", "-38", 11]
|
|
19
|
+
"-38": [-38, "-39", "-37", 12]
|
|
20
|
+
"-37": [-37, "-38", "-36", 13]
|
|
21
|
+
"-36": [-36, "-37", "-35", 14]
|
|
22
|
+
"-35": [-35, "-36", "-34", 15]
|
|
23
|
+
"-34": [-34, "-35", "-33", 16]
|
|
24
|
+
"-33": [-33, "-34", "-32", 17]
|
|
25
|
+
"-32": [-32, "-33", "-31", 18]
|
|
26
|
+
"-31": [-31, "-32", "-30", 19]
|
|
27
|
+
"-30": [-30, "-31", "-29", 20]
|
|
28
|
+
"-29": [-29, "-30", "-28", 21]
|
|
29
|
+
"-28": [-28, "-29", "-27", 22]
|
|
30
|
+
"-27": [-27, "-28", "-26", 23]
|
|
31
|
+
"-26": [-26, "-27", "-25", 24]
|
|
32
|
+
"-25": [-25, "-26", "-24", 25]
|
|
33
|
+
"-24": [-24, "-25", "-23", 26]
|
|
34
|
+
"-23": [-23, "-24", "-22", 27]
|
|
35
|
+
"-22": [-22, "-23", "-21", 28]
|
|
36
|
+
"-21": [-21, "-22", "-20", 29]
|
|
37
|
+
"-20": [-20, "-21", "-19", 30]
|
|
38
|
+
"-19": [-19, "-20", "-18", 31]
|
|
39
|
+
"-18": [-18, "-19", "-17", 32]
|
|
40
|
+
"-17": [-17, "-18", "-16", 33]
|
|
41
|
+
"-16": [-16, "-17", "-15", 34]
|
|
42
|
+
"-15": [-15, "-16", "-14", 35]
|
|
43
|
+
"-14": [-14, "-15", "-13", 36]
|
|
44
|
+
"-13": [-13, "-14", "-12", 37]
|
|
45
|
+
"-12": [-12, "-13", "-11", 38]
|
|
46
|
+
"-11": [-11, "-12", "-10", 39]
|
|
47
|
+
"-10": [-10, "-11", "-9", 40]
|
|
48
|
+
"-9": [-9, "-10", "-8", 41]
|
|
49
|
+
"-8": [-8, "-9", "-7", 42]
|
|
50
|
+
"-7": [-7, "-8", "-6", 43]
|
|
51
|
+
"-6": [-6, "-7", "-5", 44]
|
|
52
|
+
"-5": [-5, "-6", "-4", 45]
|
|
53
|
+
"-4": [-4, "-5", "-3", 46]
|
|
54
|
+
"-3": [-3, "-4", "-2", 47]
|
|
55
|
+
"-2": [-2, "-3", "-1", 48]
|
|
56
|
+
"-1": [-1, "-2", "0", 49]
|
|
57
|
+
"0": [0, "-1", "1", 50]
|
|
58
|
+
"1": [1, "0", "2", 51]
|
|
59
|
+
"2": [2, "1", "3", 52]
|
|
60
|
+
"3": [3, "2", "4", 53]
|
|
61
|
+
"4": [4, "3", "5", 54]
|
|
62
|
+
"5": [5, "4", "6", 55]
|
|
63
|
+
"6": [6, "5", "7", 56]
|
|
64
|
+
"7": [7, "6", "8", 57]
|
|
65
|
+
"8": [8, "7", "9", 58]
|
|
66
|
+
"9": [9, "8", "10", 59]
|
|
67
|
+
"10": [10, "9", "11", 60]
|
|
68
|
+
"11": [11, "10", "12", 61]
|
|
69
|
+
"12": [12, "11", "13", 62]
|
|
70
|
+
"13": [13, "12", "14", 63]
|
|
71
|
+
"14": [14, "13", "15", 64]
|
|
72
|
+
"15": [15, "14", "16", 65]
|
|
73
|
+
"16": [16, "15", "17", 66]
|
|
74
|
+
"17": [17, "16", "18", 67]
|
|
75
|
+
"18": [18, "17", "19", 68]
|
|
76
|
+
"19": [19, "18", "20", 69]
|
|
77
|
+
"20": [20, "19", "21", 70]
|
|
78
|
+
"21": [21, "20", "22", 71]
|
|
79
|
+
"22": [22, "21", "23", 72]
|
|
80
|
+
"23": [23, "22", "24", 73]
|
|
81
|
+
"24": [24, "23", "25", 74]
|
|
82
|
+
"25": [25, "24", "26", 75]
|
|
83
|
+
"26": [26, "25", "27", 76]
|
|
84
|
+
"27": [27, "26", "28", 77]
|
|
85
|
+
"28": [28, "27", "29", 78]
|
|
86
|
+
"29": [29, "28", "30", 79]
|
|
87
|
+
"30": [30, "29", "31", 80]
|
|
88
|
+
"31": [31, "30", "32", 81]
|
|
89
|
+
"32": [32, "31", "33", 82]
|
|
90
|
+
"33": [33, "32", "34", 83]
|
|
91
|
+
"34": [34, "33", "35", 84]
|
|
92
|
+
"35": [35, "34", "36", 85]
|
|
93
|
+
"36": [36, "35", "37", 86]
|
|
94
|
+
"37": [37, "36", "38", 87]
|
|
95
|
+
"38": [38, "37", "39", 88]
|
|
96
|
+
"39": [39, "38", "40", 89]
|
|
97
|
+
"40": [40, "39", "41", 90]
|
|
98
|
+
"41": [41, "40", "42", 91]
|
|
99
|
+
"42": [42, "41", "43", 92]
|
|
100
|
+
"43": [43, "42", "44", 93]
|
|
101
|
+
"44": [44, "43", "45", 94]
|
|
102
|
+
"45": [45, "44", "46", 95]
|
|
103
|
+
"46": [46, "45", "47", 96]
|
|
104
|
+
"47": [47, "46", "48", 97]
|
|
105
|
+
"48": [48, "47", "49", 98]
|
|
106
|
+
"49": [49, "48", "50", 99]
|
|
107
|
+
"50": [50, "49", "__", 100]
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
type InternalIterationKey = keyof InternalIterationMap
|
|
111
|
+
type InternalIterationNumberKey = Exclude<InternalIterationKey, "__">
|
|
112
|
+
|
|
113
|
+
// ============================================================================
|
|
114
|
+
// Primitives
|
|
115
|
+
// ============================================================================
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Define the iteration tuple type.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```
|
|
122
|
+
* // Expect: [0, "-1", "1", 50]
|
|
123
|
+
* type Example1 = IterationOf<0>
|
|
124
|
+
* // Expect: Iteration
|
|
125
|
+
* type Example2 = Iteration
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export type Iteration = InternalIterationMap[InternalIterationKey]
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get the iteration tuple for a number.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```
|
|
135
|
+
* // Expect: [3, "2", "4", 53]
|
|
136
|
+
* type Example1 = IterationOf<3>
|
|
137
|
+
* // Expect: [-2, "-3", "-1", 48]
|
|
138
|
+
* type Example2 = IterationOf<-2>
|
|
139
|
+
* // Expect: [number, "__", "__", number]
|
|
140
|
+
* type Example3 = IterationOf<999>
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export type IterationOf<N extends number> = `${N}` extends InternalIterationKey
|
|
144
|
+
? InternalIterationMap[`${N}`]
|
|
145
|
+
: InternalIterationMap["__"]
|
|
146
|
+
|
|
147
|
+
// ============================================================================
|
|
148
|
+
// Validation
|
|
149
|
+
// ============================================================================
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Check if a type is an Iteration tuple.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```
|
|
156
|
+
* // Expect: true
|
|
157
|
+
* type Example1 = IterationIsIteration<IterationOf<1>>
|
|
158
|
+
* // Expect: false
|
|
159
|
+
* type Example2 = IterationIsIteration<number>
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export type IterationIsIteration<T> = T extends Iteration ? true : false
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Check if a number is within the built-in iteration range.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```
|
|
169
|
+
* // Expect: true
|
|
170
|
+
* type Example1 = IterationIsInRange<10>
|
|
171
|
+
* // Expect: false
|
|
172
|
+
* type Example2 = IterationIsInRange<120>
|
|
173
|
+
* // Expect: true
|
|
174
|
+
* type Example3 = IterationIsInRange<-50>
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export type IterationIsInRange<N extends number> = `${N}` extends InternalIterationNumberKey ? true : false
|
|
178
|
+
|
|
179
|
+
// ============================================================================
|
|
180
|
+
// Query
|
|
181
|
+
// ============================================================================
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Get the key (numeric value) of an iteration.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```
|
|
188
|
+
* // Expect: 5
|
|
189
|
+
* type Example1 = Key<IterationOf<5>>
|
|
190
|
+
* // Expect: -1
|
|
191
|
+
* type Example2 = Key<IterationOf<-1>>
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export type Key<I extends Iteration> = I[0]
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Get the position index of an iteration.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```
|
|
201
|
+
* // Expect: 50
|
|
202
|
+
* type Example1 = Pos<IterationOf<0>>
|
|
203
|
+
* // Expect: 49
|
|
204
|
+
* type Example2 = Pos<IterationOf<-1>>
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export type Pos<I extends Iteration> = I[3]
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Get the previous iteration.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```
|
|
214
|
+
* // Expect: [2, "1", "3", 52]
|
|
215
|
+
* type Example1 = Prev<IterationOf<3>>
|
|
216
|
+
* // Expect: [number, "__", "__", number]
|
|
217
|
+
* type Example2 = Prev<IterationOf<-50>>
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export type Prev<I extends Iteration> = InternalIterationMap[I[1]]
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Get the next iteration.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```
|
|
227
|
+
* // Expect: [4, "3", "5", 54]
|
|
228
|
+
* type Example1 = Next<IterationOf<3>>
|
|
229
|
+
* // Expect: [number, "__", "__", number]
|
|
230
|
+
* type Example2 = Next<IterationOf<50>>
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export type Next<I extends Iteration> = InternalIterationMap[I[2]]
|