@byloth/core 2.0.0 → 2.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/dist/core.js +885 -182
- package/dist/core.js.map +1 -1
- package/dist/core.umd.cjs +2 -2
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +10 -9
- package/src/index.ts +1 -1
- package/src/models/aggregators/aggregated-async-iterator.ts +156 -1
- package/src/models/aggregators/aggregated-iterator.ts +141 -1
- package/src/models/aggregators/reduced-iterator.ts +130 -3
- package/src/models/callbacks/publisher.ts +21 -0
- package/src/models/callbacks/switchable-callback.ts +94 -21
- package/src/models/exceptions/core.ts +20 -0
- package/src/models/exceptions/index.ts +65 -0
- package/src/models/iterators/smart-async-iterator.ts +140 -0
- package/src/models/iterators/smart-iterator.ts +125 -0
- package/src/models/json/json-storage.ts +120 -0
- package/src/models/promises/deferred-promise.ts +10 -0
- package/src/models/promises/smart-promise.ts +40 -0
- package/src/models/promises/timed-promise.ts +5 -0
- package/src/models/timers/clock.ts +18 -0
- package/src/models/timers/countdown.ts +25 -0
- package/src/models/timers/game-loop.ts +23 -0
- package/src/utils/curve.ts +10 -0
- package/src/utils/random.ts +30 -0
package/dist/core.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var a = (i, t, e) =>
|
|
1
|
+
var De = Object.defineProperty;
|
|
2
|
+
var ze = (i, t, e) => t in i ? De(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
3
|
+
var a = (i, t, e) => ze(i, typeof t != "symbol" ? t + "" : t, e);
|
|
4
4
|
const Oe = typeof window < "u" && typeof window.document < "u";
|
|
5
5
|
var I;
|
|
6
|
-
const
|
|
6
|
+
const We = typeof process < "u" && !!((I = process.versions) != null && I.node);
|
|
7
7
|
var A;
|
|
8
|
-
const
|
|
8
|
+
const Ue = typeof self == "object" && ((A = self.constructor) == null ? void 0 : A.name) === "DedicatedWorkerGlobalScope";
|
|
9
9
|
var N, O;
|
|
10
|
-
class
|
|
10
|
+
class u extends (O = Error, N = Symbol.toStringTag, O) {
|
|
11
11
|
/**
|
|
12
12
|
* Initializes a new instance of the {@link Exception} class.
|
|
13
13
|
*
|
|
14
|
+
* ---
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
14
17
|
* ```ts
|
|
15
18
|
* throw new Exception("An error occurred while processing the request.");
|
|
16
19
|
* ```
|
|
17
20
|
*
|
|
21
|
+
* ---
|
|
22
|
+
*
|
|
18
23
|
* @param message The message that describes the error.
|
|
19
24
|
* @param cause The previous caught error that caused this one, if any.
|
|
20
25
|
* @param name The name of the exception. Default is `"Exception"`.
|
|
@@ -31,6 +36,9 @@ Caused by ${n}`);
|
|
|
31
36
|
/**
|
|
32
37
|
* A static method to convert a generic caught error, ensuring it's an instance of the {@link Exception} class.
|
|
33
38
|
*
|
|
39
|
+
* ---
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
34
42
|
* ```ts
|
|
35
43
|
* try { [...] }
|
|
36
44
|
* catch (error)
|
|
@@ -41,29 +49,36 @@ Caused by ${n}`);
|
|
|
41
49
|
* }
|
|
42
50
|
* ```
|
|
43
51
|
*
|
|
52
|
+
* ---
|
|
53
|
+
*
|
|
44
54
|
* @param error The caught error to convert.
|
|
45
55
|
*
|
|
46
56
|
* @returns An instance of the {@link Exception} class.
|
|
47
57
|
*/
|
|
48
58
|
static FromUnknown(e) {
|
|
49
|
-
if (e instanceof
|
|
59
|
+
if (e instanceof u)
|
|
50
60
|
return e;
|
|
51
61
|
if (e instanceof Error) {
|
|
52
|
-
const n = new
|
|
62
|
+
const n = new u(e.message);
|
|
53
63
|
return n.stack = e.stack, n.name = e.name, n;
|
|
54
64
|
}
|
|
55
|
-
return new
|
|
65
|
+
return new u(`${e}`);
|
|
56
66
|
}
|
|
57
67
|
}
|
|
58
68
|
var $, q;
|
|
59
|
-
class x extends (q =
|
|
69
|
+
class x extends (q = u, $ = Symbol.toStringTag, q) {
|
|
60
70
|
/**
|
|
61
71
|
* Initializes a new instance of the {@link FatalErrorException} class.
|
|
62
72
|
*
|
|
73
|
+
* ---
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
63
76
|
* ```ts
|
|
64
77
|
* throw new FatalErrorException("This error should never happen. Please, contact the support team.");
|
|
65
78
|
* ```
|
|
66
79
|
*
|
|
80
|
+
* ---
|
|
81
|
+
*
|
|
67
82
|
* @param message The message that describes the error.
|
|
68
83
|
* @param cause The previous caught error that caused this one, if any.
|
|
69
84
|
* @param name The name of the exception. Default is `"FatalErrorException"`.
|
|
@@ -74,15 +89,20 @@ class x extends (q = c, $ = Symbol.toStringTag, q) {
|
|
|
74
89
|
a(this, $, "FatalErrorException");
|
|
75
90
|
}
|
|
76
91
|
}
|
|
77
|
-
var
|
|
78
|
-
class Be extends (
|
|
92
|
+
var D, z;
|
|
93
|
+
class Be extends (z = x, D = Symbol.toStringTag, z) {
|
|
79
94
|
/**
|
|
80
95
|
* Initializes a new instance of the {@link NotImplementedException} class.
|
|
81
96
|
*
|
|
97
|
+
* ---
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
82
100
|
* ```ts
|
|
83
101
|
* throw new NotImplementedException("This method hasn't been implemented yet. Check back later.");
|
|
84
102
|
* ```
|
|
85
103
|
*
|
|
104
|
+
* ---
|
|
105
|
+
*
|
|
86
106
|
* @param message The message that describes the error.
|
|
87
107
|
* @param cause The previous caught error that caused this one, if any.
|
|
88
108
|
* @param name The name of the exception. Default is `"NotImplementedException"`.
|
|
@@ -90,18 +110,23 @@ class Be extends (D = x, z = Symbol.toStringTag, D) {
|
|
|
90
110
|
constructor(e, n, s = "NotImplementedException") {
|
|
91
111
|
e === void 0 && (e = "This feature isn't implemented yet. Please, try again later.");
|
|
92
112
|
super(e, n, s);
|
|
93
|
-
a(this,
|
|
113
|
+
a(this, D, "NotImplementedException");
|
|
94
114
|
}
|
|
95
115
|
}
|
|
96
116
|
var B, J;
|
|
97
|
-
class $e extends (J =
|
|
117
|
+
class $e extends (J = u, B = Symbol.toStringTag, J) {
|
|
98
118
|
/**
|
|
99
119
|
* Initializes a new instance of the {@link FileException} class.
|
|
100
120
|
*
|
|
121
|
+
* ---
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
101
124
|
* ```ts
|
|
102
125
|
* throw new FileException("An error occurred while trying to read the file.");
|
|
103
126
|
* ```
|
|
104
127
|
*
|
|
128
|
+
* ---
|
|
129
|
+
*
|
|
105
130
|
* @param message The message that describes the error.
|
|
106
131
|
* @param cause The previous caught error that caused this one, if any.
|
|
107
132
|
* @param name The name of the exception. Default is `"FileException"`.
|
|
@@ -112,14 +137,19 @@ class $e extends (J = c, B = Symbol.toStringTag, J) {
|
|
|
112
137
|
}
|
|
113
138
|
}
|
|
114
139
|
var Y, L;
|
|
115
|
-
class
|
|
140
|
+
class et extends (L = $e, Y = Symbol.toStringTag, L) {
|
|
116
141
|
/**
|
|
117
142
|
* Initializes a new instance of the {@link FileExistsException} class.
|
|
118
143
|
*
|
|
144
|
+
* ---
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
119
147
|
* ```ts
|
|
120
148
|
* throw new FileExistsException("The file named 'data.json' already exists on the server.");
|
|
121
149
|
* ```
|
|
122
150
|
*
|
|
151
|
+
* ---
|
|
152
|
+
*
|
|
123
153
|
* @param message The message that describes the error.
|
|
124
154
|
* @param cause The previous caught error that caused this one, if any.
|
|
125
155
|
* @param name The name of the exception. Default is `"FileExistsException"`.
|
|
@@ -130,14 +160,19 @@ class Ue extends (L = $e, Y = Symbol.toStringTag, L) {
|
|
|
130
160
|
}
|
|
131
161
|
}
|
|
132
162
|
var G, K;
|
|
133
|
-
class
|
|
163
|
+
class tt extends (K = $e, G = Symbol.toStringTag, K) {
|
|
134
164
|
/**
|
|
135
165
|
* Initializes a new instance of the {@link FileNotFoundException} class.
|
|
136
166
|
*
|
|
167
|
+
* ---
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
137
170
|
* ```ts
|
|
138
171
|
* throw new FileNotFoundException("The file named 'data.json' wasn't found on the server.");
|
|
139
172
|
* ```
|
|
140
173
|
*
|
|
174
|
+
* ---
|
|
175
|
+
*
|
|
141
176
|
* @param message The message that describes the error.
|
|
142
177
|
* @param cause The previous caught error that caused this one, if any.
|
|
143
178
|
* @param name The name of the exception. Default is `"FileNotFoundException"`.
|
|
@@ -148,14 +183,19 @@ class et extends (K = $e, G = Symbol.toStringTag, K) {
|
|
|
148
183
|
}
|
|
149
184
|
}
|
|
150
185
|
var H, Q;
|
|
151
|
-
class
|
|
186
|
+
class _ extends (Q = u, H = Symbol.toStringTag, Q) {
|
|
152
187
|
/**
|
|
153
188
|
* Initializes a new instance of the {@link KeyException} class.
|
|
154
189
|
*
|
|
190
|
+
* ---
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
155
193
|
* ```ts
|
|
156
194
|
* throw new KeyException("The 'id' key wasn't found in the dictionary.");
|
|
157
195
|
* ```
|
|
158
196
|
*
|
|
197
|
+
* ---
|
|
198
|
+
*
|
|
159
199
|
* @param message The message that describes the error.
|
|
160
200
|
* @param cause The previous caught error that caused this one, if any.
|
|
161
201
|
* @param name The name of the exception. Default is `"KeyException"`.
|
|
@@ -166,14 +206,19 @@ class b extends (Q = c, H = Symbol.toStringTag, Q) {
|
|
|
166
206
|
}
|
|
167
207
|
}
|
|
168
208
|
var V, X;
|
|
169
|
-
class
|
|
209
|
+
class nt extends (X = u, V = Symbol.toStringTag, X) {
|
|
170
210
|
/**
|
|
171
211
|
* Initializes a new instance of the {@link NetworkException} class.
|
|
172
212
|
*
|
|
213
|
+
* ---
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
173
216
|
* ```ts
|
|
174
217
|
* throw new NetworkException("Couldn't connect to the server. Please, try again later.");
|
|
175
218
|
* ```
|
|
176
219
|
*
|
|
220
|
+
* ---
|
|
221
|
+
*
|
|
177
222
|
* @param message The message that describes the error.
|
|
178
223
|
* @param cause The previous caught error that caused this one, if any.
|
|
179
224
|
* @param name The name of the exception. Default is `"NetworkException"`.
|
|
@@ -184,14 +229,19 @@ class tt extends (X = c, V = Symbol.toStringTag, X) {
|
|
|
184
229
|
}
|
|
185
230
|
}
|
|
186
231
|
var Z, W;
|
|
187
|
-
class
|
|
232
|
+
class st extends (W = u, Z = Symbol.toStringTag, W) {
|
|
188
233
|
/**
|
|
189
234
|
* Initializes a new instance of the {@link PermissionException} class.
|
|
190
235
|
*
|
|
236
|
+
* ---
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
191
239
|
* ```ts
|
|
192
240
|
* throw new PermissionException("You don't have permission to access this resource.");
|
|
193
241
|
* ```
|
|
194
242
|
*
|
|
243
|
+
* ---
|
|
244
|
+
*
|
|
195
245
|
* @param message The message that describes the error.
|
|
196
246
|
* @param cause The previous caught error that caused this one, if any.
|
|
197
247
|
* @param name The name of the exception. Default is `"PermissionException"`.
|
|
@@ -202,14 +252,19 @@ class nt extends (W = c, Z = Symbol.toStringTag, W) {
|
|
|
202
252
|
}
|
|
203
253
|
}
|
|
204
254
|
var U, ee;
|
|
205
|
-
class C extends (ee =
|
|
255
|
+
class C extends (ee = u, U = Symbol.toStringTag, ee) {
|
|
206
256
|
/**
|
|
207
257
|
* Initializes a new instance of the {@link ReferenceException} class.
|
|
208
258
|
*
|
|
259
|
+
* ---
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
209
262
|
* ```ts
|
|
210
263
|
* throw new ReferenceException("The 'canvas' element wasn't found in the document.");
|
|
211
264
|
* ```
|
|
212
265
|
*
|
|
266
|
+
* ---
|
|
267
|
+
*
|
|
213
268
|
* @param message The message that describes the error.
|
|
214
269
|
* @param cause The previous caught error that caused this one, if any.
|
|
215
270
|
* @param name The name of the exception. Default is `"ReferenceException"`.
|
|
@@ -220,14 +275,19 @@ class C extends (ee = c, U = Symbol.toStringTag, ee) {
|
|
|
220
275
|
}
|
|
221
276
|
}
|
|
222
277
|
var te, ne;
|
|
223
|
-
class y extends (ne =
|
|
278
|
+
class y extends (ne = u, te = Symbol.toStringTag, ne) {
|
|
224
279
|
/**
|
|
225
280
|
* Initializes a new instance of the {@link RuntimeException} class.
|
|
226
281
|
*
|
|
282
|
+
* ---
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
227
285
|
* ```ts
|
|
228
286
|
* throw new RuntimeException("The received input seems to be malformed or corrupted.");
|
|
229
287
|
* ```
|
|
230
288
|
*
|
|
289
|
+
* ---
|
|
290
|
+
*
|
|
231
291
|
* @param message The message that describes the error.
|
|
232
292
|
* @param cause The previous caught error that caused this one, if any.
|
|
233
293
|
* @param name The name of the exception. Default is `"RuntimeException"`.
|
|
@@ -242,10 +302,15 @@ class Je extends (re = y, se = Symbol.toStringTag, re) {
|
|
|
242
302
|
/**
|
|
243
303
|
* Initializes a new instance of the {@link EnvironmentException} class.
|
|
244
304
|
*
|
|
305
|
+
* ---
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
245
308
|
* ```ts
|
|
246
309
|
* throw new EnvironmentException("The required environment variable 'API_KEY' isn't set.");
|
|
247
310
|
* ```
|
|
248
311
|
*
|
|
312
|
+
* ---
|
|
313
|
+
*
|
|
249
314
|
* @param message The message that describes the error.
|
|
250
315
|
* @param cause The previous caught error that caused this one, if any.
|
|
251
316
|
* @param name The name of the exception. Default is `"EnvironmentException"`.
|
|
@@ -256,14 +321,19 @@ class Je extends (re = y, se = Symbol.toStringTag, re) {
|
|
|
256
321
|
}
|
|
257
322
|
}
|
|
258
323
|
var ie, oe;
|
|
259
|
-
class Ye extends (oe =
|
|
324
|
+
class Ye extends (oe = u, ie = Symbol.toStringTag, oe) {
|
|
260
325
|
/**
|
|
261
326
|
* Initializes a new instance of the {@link TimeoutException} class.
|
|
262
327
|
*
|
|
328
|
+
* ---
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
263
331
|
* ```ts
|
|
264
332
|
* throw new TimeoutException("The task took too long to complete.");
|
|
265
333
|
* ```
|
|
266
334
|
*
|
|
335
|
+
* ---
|
|
336
|
+
*
|
|
267
337
|
* @param message The message that describes the error.
|
|
268
338
|
* @param cause The previous caught error that caused this one, if any.
|
|
269
339
|
* @param name The name of the exception. Default is `"TimeoutException"`.
|
|
@@ -274,14 +344,19 @@ class Ye extends (oe = c, ie = Symbol.toStringTag, oe) {
|
|
|
274
344
|
}
|
|
275
345
|
}
|
|
276
346
|
var ae, le;
|
|
277
|
-
class
|
|
347
|
+
class rt extends (le = u, ae = Symbol.toStringTag, le) {
|
|
278
348
|
/**
|
|
279
349
|
* Initializes a new instance of the {@link TypeException} class.
|
|
280
350
|
*
|
|
351
|
+
* ---
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
281
354
|
* ```ts
|
|
282
355
|
* throw new TypeException("The 'username' argument must be a valid string.");
|
|
283
356
|
* ```
|
|
284
357
|
*
|
|
358
|
+
* ---
|
|
359
|
+
*
|
|
285
360
|
* @param message The message that describes the error.
|
|
286
361
|
* @param cause The previous caught error that caused this one, if any.
|
|
287
362
|
* @param name The name of the exception. Default is `"TypeException"`.
|
|
@@ -291,33 +366,43 @@ class st extends (le = c, ae = Symbol.toStringTag, le) {
|
|
|
291
366
|
a(this, ae, "TypeException");
|
|
292
367
|
}
|
|
293
368
|
}
|
|
294
|
-
var
|
|
295
|
-
class d extends (
|
|
369
|
+
var ce, ue;
|
|
370
|
+
class d extends (ue = u, ce = Symbol.toStringTag, ue) {
|
|
296
371
|
/**
|
|
297
372
|
* Initializes a new instance of the {@link ValueException} class.
|
|
298
373
|
*
|
|
374
|
+
* ---
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
299
377
|
* ```ts
|
|
300
378
|
* throw new ValueException("The 'grade' argument cannot be negative.");
|
|
301
379
|
* ```
|
|
302
380
|
*
|
|
381
|
+
* ---
|
|
382
|
+
*
|
|
303
383
|
* @param message The message that describes the error.
|
|
304
384
|
* @param cause The previous caught error that caused this one, if any.
|
|
305
385
|
* @param name The name of the exception. Default is `"ValueException"`.
|
|
306
386
|
*/
|
|
307
387
|
constructor(e, n, s = "ValueException") {
|
|
308
388
|
super(e, n, s);
|
|
309
|
-
a(this,
|
|
389
|
+
a(this, ce, "ValueException");
|
|
310
390
|
}
|
|
311
391
|
}
|
|
312
392
|
var he, fe;
|
|
313
|
-
class
|
|
393
|
+
class b extends (fe = d, he = Symbol.toStringTag, fe) {
|
|
314
394
|
/**
|
|
315
395
|
* Initializes a new instance of the {@link RangeException} class.
|
|
316
396
|
*
|
|
397
|
+
* ---
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
317
400
|
* ```ts
|
|
318
401
|
* throw new RangeException("The 'percentage' argument must be between 0 and 100.");
|
|
319
402
|
* ```
|
|
320
403
|
*
|
|
404
|
+
* ---
|
|
405
|
+
*
|
|
321
406
|
* @param message The message that describes the error.
|
|
322
407
|
* @param cause The previous caught error that caused this one, if any.
|
|
323
408
|
* @param name The name of the exception. Default is `"RangeException"`.
|
|
@@ -328,7 +413,7 @@ class p extends (fe = d, he = Symbol.toStringTag, fe) {
|
|
|
328
413
|
}
|
|
329
414
|
}
|
|
330
415
|
var de;
|
|
331
|
-
class
|
|
416
|
+
class c {
|
|
332
417
|
constructor(t) {
|
|
333
418
|
/**
|
|
334
419
|
* The native {@link Iterator} object that is being wrapped by this instance.
|
|
@@ -350,6 +435,9 @@ class u {
|
|
|
350
435
|
*
|
|
351
436
|
* If the iterator is infinite and every element satisfies the condition, the method will never return.
|
|
352
437
|
*
|
|
438
|
+
* ---
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
353
441
|
* ```ts
|
|
354
442
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
355
443
|
* const result = iterator.every((value) => value < 0);
|
|
@@ -357,6 +445,8 @@ class u {
|
|
|
357
445
|
* console.log(result); // false
|
|
358
446
|
* ```
|
|
359
447
|
*
|
|
448
|
+
* ---
|
|
449
|
+
*
|
|
360
450
|
* @param predicate The condition to check for each element of the iterator.
|
|
361
451
|
*
|
|
362
452
|
* @returns `true` if all elements satisfy the condition, `false` otherwise.
|
|
@@ -385,6 +475,9 @@ class u {
|
|
|
385
475
|
*
|
|
386
476
|
* If the iterator is infinite and no element satisfies the condition, the method will never return.
|
|
387
477
|
*
|
|
478
|
+
* ---
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
388
481
|
* ```ts
|
|
389
482
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
390
483
|
* const result = iterator.some((value) => value < 0);
|
|
@@ -392,6 +485,8 @@ class u {
|
|
|
392
485
|
* console.log(result); // true
|
|
393
486
|
* ```
|
|
394
487
|
*
|
|
488
|
+
* ---
|
|
489
|
+
*
|
|
395
490
|
* @param predicate The condition to check for each element of the iterator.
|
|
396
491
|
*
|
|
397
492
|
* @returns `true` if any element satisfies the condition, `false` otherwise.
|
|
@@ -409,7 +504,7 @@ class u {
|
|
|
409
504
|
}
|
|
410
505
|
filter(t) {
|
|
411
506
|
const e = this._iterator;
|
|
412
|
-
return new
|
|
507
|
+
return new c(function* () {
|
|
413
508
|
let n = 0;
|
|
414
509
|
for (; ; ) {
|
|
415
510
|
const s = e.next();
|
|
@@ -432,6 +527,9 @@ class u {
|
|
|
432
527
|
* This means that the original iterator won't be consumed until the
|
|
433
528
|
* new one is and that consuming one of them will consume the other as well.
|
|
434
529
|
*
|
|
530
|
+
* ---
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
435
533
|
* ```ts
|
|
436
534
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
437
535
|
* const result = iterator.map((value) => Math.abs(value));
|
|
@@ -439,6 +537,8 @@ class u {
|
|
|
439
537
|
* console.log(result.toArray()); // [2, 1, 0, 1, 2]
|
|
440
538
|
* ```
|
|
441
539
|
*
|
|
540
|
+
* ---
|
|
541
|
+
*
|
|
442
542
|
* @template V The type of the elements after the transformation.
|
|
443
543
|
*
|
|
444
544
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -447,7 +547,7 @@ class u {
|
|
|
447
547
|
*/
|
|
448
548
|
map(t) {
|
|
449
549
|
const e = this._iterator;
|
|
450
|
-
return new
|
|
550
|
+
return new c(function* () {
|
|
451
551
|
let n = 0;
|
|
452
552
|
for (; ; ) {
|
|
453
553
|
const s = e.next();
|
|
@@ -485,6 +585,9 @@ class u {
|
|
|
485
585
|
* This means that the original iterator won't be consumed until the
|
|
486
586
|
* new one is and that consuming one of them will consume the other as well.
|
|
487
587
|
*
|
|
588
|
+
* ---
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
488
591
|
* ```ts
|
|
489
592
|
* const iterator = new SmartIterator<number[]>([[-2, -1], 0, 1, 2, [3, 4, 5]]);
|
|
490
593
|
* const result = iterator.flatMap((value) => value);
|
|
@@ -492,6 +595,8 @@ class u {
|
|
|
492
595
|
* console.log(result.toArray()); // [-2, -1, 0, 1, 2, 3, 4, 5]
|
|
493
596
|
* ```
|
|
494
597
|
*
|
|
598
|
+
* ---
|
|
599
|
+
*
|
|
495
600
|
* @template V The type of the elements after the transformation.
|
|
496
601
|
*
|
|
497
602
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -500,7 +605,7 @@ class u {
|
|
|
500
605
|
*/
|
|
501
606
|
flatMap(t) {
|
|
502
607
|
const e = this._iterator;
|
|
503
|
-
return new
|
|
608
|
+
return new c(function* () {
|
|
504
609
|
let n = 0;
|
|
505
610
|
for (; ; ) {
|
|
506
611
|
const s = e.next();
|
|
@@ -531,6 +636,9 @@ class u {
|
|
|
531
636
|
* Only the dropped elements will be consumed in the process.
|
|
532
637
|
* The rest of the iterator will be consumed only once the new one is.
|
|
533
638
|
*
|
|
639
|
+
* ---
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
534
642
|
* ```ts
|
|
535
643
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
536
644
|
* const result = iterator.drop(3);
|
|
@@ -538,13 +646,15 @@ class u {
|
|
|
538
646
|
* console.log(result.toArray()); // [1, 2]
|
|
539
647
|
* ```
|
|
540
648
|
*
|
|
649
|
+
* ---
|
|
650
|
+
*
|
|
541
651
|
* @param count The number of elements to drop.
|
|
542
652
|
*
|
|
543
653
|
* @returns A new {@link SmartIterator} containing the remaining elements.
|
|
544
654
|
*/
|
|
545
655
|
drop(t) {
|
|
546
656
|
const e = this._iterator;
|
|
547
|
-
return new
|
|
657
|
+
return new c(function* () {
|
|
548
658
|
let n = 0;
|
|
549
659
|
for (; n < t; ) {
|
|
550
660
|
if (e.next().done)
|
|
@@ -574,6 +684,9 @@ class u {
|
|
|
574
684
|
* Only the taken elements will be consumed from the original iterator.
|
|
575
685
|
* The rest of the original iterator will be available for further consumption.
|
|
576
686
|
*
|
|
687
|
+
* ---
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
577
690
|
* ```ts
|
|
578
691
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
579
692
|
* const result = iterator.take(3);
|
|
@@ -582,13 +695,15 @@ class u {
|
|
|
582
695
|
* console.log(iterator.toArray()); // [1, 2]
|
|
583
696
|
* ```
|
|
584
697
|
*
|
|
698
|
+
* ---
|
|
699
|
+
*
|
|
585
700
|
* @param limit The number of elements to take.
|
|
586
701
|
*
|
|
587
702
|
* @returns A new {@link SmartIterator} containing the taken elements.
|
|
588
703
|
*/
|
|
589
704
|
take(t) {
|
|
590
705
|
const e = this._iterator;
|
|
591
|
-
return new
|
|
706
|
+
return new c(function* () {
|
|
592
707
|
let n = 0;
|
|
593
708
|
for (; n < t; ) {
|
|
594
709
|
const s = e.next();
|
|
@@ -620,6 +735,9 @@ class u {
|
|
|
620
735
|
* This means that the original iterator won't be consumed until the
|
|
621
736
|
* new one is and that consuming one of them will consume the other as well.
|
|
622
737
|
*
|
|
738
|
+
* ---
|
|
739
|
+
*
|
|
740
|
+
* @example
|
|
623
741
|
* ```ts
|
|
624
742
|
* const iterator = new SmartIterator<string>(["A", "M", "N", "Z"]);
|
|
625
743
|
* const result = iterator.enumerate();
|
|
@@ -627,6 +745,8 @@ class u {
|
|
|
627
745
|
* console.log(result.toArray()); // [[0, "A"], [1, "M"], [2, "N"], [3, "Z"]]
|
|
628
746
|
* ```
|
|
629
747
|
*
|
|
748
|
+
* ---
|
|
749
|
+
*
|
|
630
750
|
* @returns A new {@link SmartIterator} containing the enumerated elements.
|
|
631
751
|
*/
|
|
632
752
|
enumerate() {
|
|
@@ -643,6 +763,9 @@ class u {
|
|
|
643
763
|
* This means that the original iterator won't be consumed until the
|
|
644
764
|
* new one is and that consuming one of them will consume the other as well.
|
|
645
765
|
*
|
|
766
|
+
* ---
|
|
767
|
+
*
|
|
768
|
+
* @example
|
|
646
769
|
* ```ts
|
|
647
770
|
* const iterator = new SmartIterator<number>([1, 1, 2, 3, 2, 3, 4, 5, 5, 4]);
|
|
648
771
|
* const result = iterator.unique();
|
|
@@ -650,11 +773,13 @@ class u {
|
|
|
650
773
|
* console.log(result.toArray()); // [1, 2, 3, 4, 5]
|
|
651
774
|
* ```
|
|
652
775
|
*
|
|
776
|
+
* ---
|
|
777
|
+
*
|
|
653
778
|
* @returns A new {@link SmartIterator} containing only the unique elements.
|
|
654
779
|
*/
|
|
655
780
|
unique() {
|
|
656
781
|
const t = this._iterator;
|
|
657
|
-
return new
|
|
782
|
+
return new c(function* () {
|
|
658
783
|
const e = /* @__PURE__ */ new Set();
|
|
659
784
|
for (; ; ) {
|
|
660
785
|
const n = t.next();
|
|
@@ -670,6 +795,9 @@ class u {
|
|
|
670
795
|
*
|
|
671
796
|
* If the iterator is infinite, the method will never return.
|
|
672
797
|
*
|
|
798
|
+
* ---
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
673
801
|
* ```ts
|
|
674
802
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);
|
|
675
803
|
* const result = iterator.count();
|
|
@@ -677,6 +805,8 @@ class u {
|
|
|
677
805
|
* console.log(result); // 5
|
|
678
806
|
* ```
|
|
679
807
|
*
|
|
808
|
+
* ---
|
|
809
|
+
*
|
|
680
810
|
* @returns The number of elements in the iterator.
|
|
681
811
|
*/
|
|
682
812
|
count() {
|
|
@@ -694,6 +824,9 @@ class u {
|
|
|
694
824
|
* This method will consume the entire iterator in the process.
|
|
695
825
|
* If the iterator is infinite, the method will never return.
|
|
696
826
|
*
|
|
827
|
+
* ---
|
|
828
|
+
*
|
|
829
|
+
* @example
|
|
697
830
|
* ```ts
|
|
698
831
|
* const iterator = new SmartIterator<number>(["A", "M", "N", "Z"]);
|
|
699
832
|
* iterator.forEach((value, index) =>
|
|
@@ -702,6 +835,8 @@ class u {
|
|
|
702
835
|
* }
|
|
703
836
|
* ```
|
|
704
837
|
*
|
|
838
|
+
* ---
|
|
839
|
+
*
|
|
705
840
|
* @param iteratee The function to apply to each element of the iterator.
|
|
706
841
|
*/
|
|
707
842
|
forEach(t) {
|
|
@@ -719,6 +854,9 @@ class u {
|
|
|
719
854
|
*
|
|
720
855
|
* Once the iterator is done, the method will return an object with the `done` property set to `true`.
|
|
721
856
|
*
|
|
857
|
+
* ---
|
|
858
|
+
*
|
|
859
|
+
* @example
|
|
722
860
|
* ```ts
|
|
723
861
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);
|
|
724
862
|
*
|
|
@@ -733,6 +871,8 @@ class u {
|
|
|
733
871
|
* console.log(result); // { done: true, value: undefined }
|
|
734
872
|
* ```
|
|
735
873
|
*
|
|
874
|
+
* ---
|
|
875
|
+
*
|
|
736
876
|
* @param values The value to pass to the next element, if required.
|
|
737
877
|
*
|
|
738
878
|
* @returns The result of the iteration, containing the value of the operation.
|
|
@@ -745,6 +885,9 @@ class u {
|
|
|
745
885
|
* free the resources and perform any cleanup operation.
|
|
746
886
|
* It may also be used to signal the end or to compute a specific final result of the iteration process.
|
|
747
887
|
*
|
|
888
|
+
* ---
|
|
889
|
+
*
|
|
890
|
+
* @example
|
|
748
891
|
* ```ts
|
|
749
892
|
* const iterator = new SmartIterator<number>({
|
|
750
893
|
* _index: 0,
|
|
@@ -763,6 +906,8 @@ class u {
|
|
|
763
906
|
* }
|
|
764
907
|
* ```
|
|
765
908
|
*
|
|
909
|
+
* ---
|
|
910
|
+
*
|
|
766
911
|
* @param value The final value of the iterator.
|
|
767
912
|
*
|
|
768
913
|
* @returns The result of the iterator.
|
|
@@ -775,6 +920,9 @@ class u {
|
|
|
775
920
|
* free the resources and perform any cleanup operation.
|
|
776
921
|
* It may also be used to signal that an error occurred during the iteration process or to handle it.
|
|
777
922
|
*
|
|
923
|
+
* ---
|
|
924
|
+
*
|
|
925
|
+
* @example
|
|
778
926
|
* ```ts
|
|
779
927
|
* const iterator = new SmartIterator<number>({
|
|
780
928
|
* _index: 0,
|
|
@@ -802,6 +950,8 @@ class u {
|
|
|
802
950
|
* }
|
|
803
951
|
* ```
|
|
804
952
|
*
|
|
953
|
+
* ---
|
|
954
|
+
*
|
|
805
955
|
* @param error The error to throw into the iterator.
|
|
806
956
|
*
|
|
807
957
|
* @returns The final result of the iterator.
|
|
@@ -823,6 +973,9 @@ class u {
|
|
|
823
973
|
* This means that the original iterator won't be consumed until the
|
|
824
974
|
* the new one is and that consuming one of them will consume the other as well.
|
|
825
975
|
*
|
|
976
|
+
* ---
|
|
977
|
+
*
|
|
978
|
+
* @example
|
|
826
979
|
* ```ts
|
|
827
980
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
828
981
|
* const result = iterator.groupBy<string>((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -830,6 +983,8 @@ class u {
|
|
|
830
983
|
* console.log(result.toObject()); // { odd: [1, 3, 5, 7, 9], even: [2, 4, 6, 8, 10] }
|
|
831
984
|
* ```
|
|
832
985
|
*
|
|
986
|
+
* ---
|
|
987
|
+
*
|
|
833
988
|
* @template K The type of the keys used to group the elements.
|
|
834
989
|
*
|
|
835
990
|
* @param iteratee The key function to apply to each element of the iterator.
|
|
@@ -845,6 +1000,9 @@ class u {
|
|
|
845
1000
|
*
|
|
846
1001
|
* If the iterator is infinite, the method will never return.
|
|
847
1002
|
*
|
|
1003
|
+
* ---
|
|
1004
|
+
*
|
|
1005
|
+
* @example
|
|
848
1006
|
* ```ts
|
|
849
1007
|
* const iterator = new SmartIterator(function* ()
|
|
850
1008
|
* {
|
|
@@ -855,6 +1013,8 @@ class u {
|
|
|
855
1013
|
* console.log(result); // [0, 1, 2, 3, 4]
|
|
856
1014
|
* ```
|
|
857
1015
|
*
|
|
1016
|
+
* ---
|
|
1017
|
+
*
|
|
858
1018
|
* @returns The {@link Array} containing all elements of the iterator.
|
|
859
1019
|
*/
|
|
860
1020
|
toArray() {
|
|
@@ -864,16 +1024,16 @@ class u {
|
|
|
864
1024
|
return this;
|
|
865
1025
|
}
|
|
866
1026
|
}
|
|
867
|
-
var
|
|
868
|
-
|
|
869
|
-
const
|
|
1027
|
+
var we;
|
|
1028
|
+
we = Symbol.toStringTag;
|
|
1029
|
+
const p = class p {
|
|
870
1030
|
constructor(t) {
|
|
871
1031
|
/**
|
|
872
1032
|
* The internal {@link SmartIterator} object that holds the reduced elements.
|
|
873
1033
|
*/
|
|
874
1034
|
a(this, "_elements");
|
|
875
|
-
a(this,
|
|
876
|
-
this._elements = new
|
|
1035
|
+
a(this, we, "ReducedIterator");
|
|
1036
|
+
this._elements = new c(t);
|
|
877
1037
|
}
|
|
878
1038
|
/**
|
|
879
1039
|
* Determines whether all elements of the reduced iterator satisfy the given condition.
|
|
@@ -888,6 +1048,9 @@ const _ = class _ {
|
|
|
888
1048
|
*
|
|
889
1049
|
* If the iterator is infinite and every element satisfies the condition, the method will never return.
|
|
890
1050
|
*
|
|
1051
|
+
* ---
|
|
1052
|
+
*
|
|
1053
|
+
* @example
|
|
891
1054
|
* ```ts
|
|
892
1055
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
893
1056
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -897,6 +1060,8 @@ const _ = class _ {
|
|
|
897
1060
|
* console.log(results); // true
|
|
898
1061
|
* ```
|
|
899
1062
|
*
|
|
1063
|
+
* ---
|
|
1064
|
+
*
|
|
900
1065
|
* @param predicate The condition to check for each element of the iterator.
|
|
901
1066
|
*
|
|
902
1067
|
* @returns `true` if all elements satisfy the condition, `false` otherwise.
|
|
@@ -920,6 +1085,9 @@ const _ = class _ {
|
|
|
920
1085
|
*
|
|
921
1086
|
* If the iterator is infinite and no element satisfies the condition, the method will never return.
|
|
922
1087
|
*
|
|
1088
|
+
* ---
|
|
1089
|
+
*
|
|
1090
|
+
* @example
|
|
923
1091
|
* ```ts
|
|
924
1092
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
925
1093
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -929,6 +1097,8 @@ const _ = class _ {
|
|
|
929
1097
|
* console.log(results); // true
|
|
930
1098
|
* ```
|
|
931
1099
|
*
|
|
1100
|
+
* ---
|
|
1101
|
+
*
|
|
932
1102
|
* @param predicate The condition to check for each element of the iterator.
|
|
933
1103
|
*
|
|
934
1104
|
* @returns `true` if any element satisfies the condition, `false` otherwise.
|
|
@@ -941,7 +1111,7 @@ const _ = class _ {
|
|
|
941
1111
|
}
|
|
942
1112
|
filter(t) {
|
|
943
1113
|
const e = this._elements.enumerate();
|
|
944
|
-
return new
|
|
1114
|
+
return new p(function* () {
|
|
945
1115
|
for (const [n, [s, r]] of e)
|
|
946
1116
|
t(s, r, n) && (yield [s, r]);
|
|
947
1117
|
});
|
|
@@ -959,6 +1129,9 @@ const _ = class _ {
|
|
|
959
1129
|
* This means that the original iterator won't be consumed until the
|
|
960
1130
|
* new one is and that consuming one of them will consume the other as well.
|
|
961
1131
|
*
|
|
1132
|
+
* ---
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
962
1135
|
* ```ts
|
|
963
1136
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
964
1137
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -968,6 +1141,8 @@ const _ = class _ {
|
|
|
968
1141
|
* console.log(results.toObject()); // { odd: 8, even: 32 }
|
|
969
1142
|
* ```
|
|
970
1143
|
*
|
|
1144
|
+
* ---
|
|
1145
|
+
*
|
|
971
1146
|
* @template V The type of the elements after the transformation.
|
|
972
1147
|
*
|
|
973
1148
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -976,7 +1151,7 @@ const _ = class _ {
|
|
|
976
1151
|
*/
|
|
977
1152
|
map(t) {
|
|
978
1153
|
const e = this._elements.enumerate();
|
|
979
|
-
return new
|
|
1154
|
+
return new p(function* () {
|
|
980
1155
|
for (const [n, [s, r]] of e)
|
|
981
1156
|
yield [s, t(s, r, n)];
|
|
982
1157
|
});
|
|
@@ -1006,6 +1181,9 @@ const _ = class _ {
|
|
|
1006
1181
|
* This means that the original iterator won't be consumed until the
|
|
1007
1182
|
* new one is and that consuming one of them will consume the other as well.
|
|
1008
1183
|
*
|
|
1184
|
+
* ---
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1009
1187
|
* ```ts
|
|
1010
1188
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1011
1189
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1015,6 +1193,8 @@ const _ = class _ {
|
|
|
1015
1193
|
* console.log(results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
1016
1194
|
* ```
|
|
1017
1195
|
*
|
|
1196
|
+
* ---
|
|
1197
|
+
*
|
|
1018
1198
|
* @template V The type of the elements after the transformation.
|
|
1019
1199
|
*
|
|
1020
1200
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -1049,6 +1229,9 @@ const _ = class _ {
|
|
|
1049
1229
|
* Only the dropped elements will be consumed in the process.
|
|
1050
1230
|
* The rest of the iterator will be consumed once the new iterator is.
|
|
1051
1231
|
*
|
|
1232
|
+
* ---
|
|
1233
|
+
*
|
|
1234
|
+
* @example
|
|
1052
1235
|
* ```ts
|
|
1053
1236
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1054
1237
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1064,7 +1247,7 @@ const _ = class _ {
|
|
|
1064
1247
|
*/
|
|
1065
1248
|
drop(t) {
|
|
1066
1249
|
const e = this._elements.enumerate();
|
|
1067
|
-
return new
|
|
1250
|
+
return new p(function* () {
|
|
1068
1251
|
for (const [n, [s, r]] of e)
|
|
1069
1252
|
n >= t && (yield [s, r]);
|
|
1070
1253
|
});
|
|
@@ -1084,6 +1267,9 @@ const _ = class _ {
|
|
|
1084
1267
|
* Only the taken elements will be consumed from the original reduced iterator.
|
|
1085
1268
|
* The rest of the original reduced iterator will be available for further consumption.
|
|
1086
1269
|
*
|
|
1270
|
+
* ---
|
|
1271
|
+
*
|
|
1272
|
+
* @example
|
|
1087
1273
|
* ```ts
|
|
1088
1274
|
* const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1089
1275
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1095,13 +1281,15 @@ const _ = class _ {
|
|
|
1095
1281
|
* console.log(reduced.toObject()); // { even: [0, 2, 6, 8] }
|
|
1096
1282
|
* ```
|
|
1097
1283
|
*
|
|
1098
|
-
*
|
|
1284
|
+
* ---
|
|
1285
|
+
*
|
|
1286
|
+
* @param limit The number of elements to take.
|
|
1099
1287
|
*
|
|
1100
1288
|
* @returns A new {@link ReducedIterator} containing the taken elements.
|
|
1101
1289
|
*/
|
|
1102
1290
|
take(t) {
|
|
1103
1291
|
const e = this._elements.enumerate();
|
|
1104
|
-
return new
|
|
1292
|
+
return new p(function* () {
|
|
1105
1293
|
for (const [n, [s, r]] of e) {
|
|
1106
1294
|
if (n >= t)
|
|
1107
1295
|
break;
|
|
@@ -1125,6 +1313,9 @@ const _ = class _ {
|
|
|
1125
1313
|
* This means that the original iterator won't be consumed until the
|
|
1126
1314
|
* new one is and that consuming one of them will consume the other as well.
|
|
1127
1315
|
*
|
|
1316
|
+
* ---
|
|
1317
|
+
*
|
|
1318
|
+
* @example
|
|
1128
1319
|
* ```ts
|
|
1129
1320
|
* const results = new ReducedIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1130
1321
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1134,6 +1325,8 @@ const _ = class _ {
|
|
|
1134
1325
|
* console.log(results.toObject()); // [[0, 4], [1, 16]]
|
|
1135
1326
|
* ```
|
|
1136
1327
|
*
|
|
1328
|
+
* ---
|
|
1329
|
+
*
|
|
1137
1330
|
* @returns A new {@link ReducedIterator} object containing the enumerated elements.
|
|
1138
1331
|
*/
|
|
1139
1332
|
enumerate() {
|
|
@@ -1150,6 +1343,9 @@ const _ = class _ {
|
|
|
1150
1343
|
* This means that the original iterator won't be consumed until the
|
|
1151
1344
|
* new one is and that consuming one of them will consume the other as well.
|
|
1152
1345
|
*
|
|
1346
|
+
* ---
|
|
1347
|
+
*
|
|
1348
|
+
* @example
|
|
1153
1349
|
* ```ts
|
|
1154
1350
|
* const results = new ReducedIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 1, 5, 6, 8, 7, 2])
|
|
1155
1351
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1163,7 +1359,7 @@ const _ = class _ {
|
|
|
1163
1359
|
*/
|
|
1164
1360
|
unique() {
|
|
1165
1361
|
const t = this._elements;
|
|
1166
|
-
return new
|
|
1362
|
+
return new p(function* () {
|
|
1167
1363
|
const e = /* @__PURE__ */ new Set();
|
|
1168
1364
|
for (const [n, s] of t)
|
|
1169
1365
|
e.has(s) || (e.add(s), yield [n, s]);
|
|
@@ -1175,6 +1371,9 @@ const _ = class _ {
|
|
|
1175
1371
|
*
|
|
1176
1372
|
* If the iterator is infinite, the method will never return.
|
|
1177
1373
|
*
|
|
1374
|
+
* ---
|
|
1375
|
+
*
|
|
1376
|
+
* @example
|
|
1178
1377
|
* ```ts
|
|
1179
1378
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1180
1379
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1184,6 +1383,8 @@ const _ = class _ {
|
|
|
1184
1383
|
* console.log(results); // 2
|
|
1185
1384
|
* ```
|
|
1186
1385
|
*
|
|
1386
|
+
* ---
|
|
1387
|
+
*
|
|
1187
1388
|
* @returns The number of elements in the iterator.
|
|
1188
1389
|
*/
|
|
1189
1390
|
count() {
|
|
@@ -1199,6 +1400,9 @@ const _ = class _ {
|
|
|
1199
1400
|
* This method will consume the entire iterator in the process.
|
|
1200
1401
|
* If the iterator is infinite, the method will never return.
|
|
1201
1402
|
*
|
|
1403
|
+
* ---
|
|
1404
|
+
*
|
|
1405
|
+
* @example
|
|
1202
1406
|
* ```ts
|
|
1203
1407
|
* const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1204
1408
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1210,6 +1414,8 @@ const _ = class _ {
|
|
|
1210
1414
|
* });
|
|
1211
1415
|
* ```
|
|
1212
1416
|
*
|
|
1417
|
+
* ---
|
|
1418
|
+
*
|
|
1213
1419
|
* @param iteratee The function to apply to each element of the reduced iterator.
|
|
1214
1420
|
*/
|
|
1215
1421
|
forEach(t) {
|
|
@@ -1227,6 +1433,9 @@ const _ = class _ {
|
|
|
1227
1433
|
* This means that the original iterator won't be consumed until the
|
|
1228
1434
|
* new one is and that consuming one of them will consume the other as well.
|
|
1229
1435
|
*
|
|
1436
|
+
* ---
|
|
1437
|
+
*
|
|
1438
|
+
* @example
|
|
1230
1439
|
* ```ts
|
|
1231
1440
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, -6, -8])
|
|
1232
1441
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1236,6 +1445,8 @@ const _ = class _ {
|
|
|
1236
1445
|
* console.log(results.toObject()); // { positive: 4, negative: -12 }
|
|
1237
1446
|
* ```
|
|
1238
1447
|
*
|
|
1448
|
+
* ---
|
|
1449
|
+
*
|
|
1239
1450
|
* @template J The type of the new keys used to group the elements.
|
|
1240
1451
|
*
|
|
1241
1452
|
* @param iteratee The function to determine the new key of each element of the iterator.
|
|
@@ -1260,6 +1471,9 @@ const _ = class _ {
|
|
|
1260
1471
|
* This means that the original iterator won't be consumed until the
|
|
1261
1472
|
* new one is and that consuming one of them will consume the other as well.
|
|
1262
1473
|
*
|
|
1474
|
+
* ---
|
|
1475
|
+
*
|
|
1476
|
+
* @example
|
|
1263
1477
|
* ```ts
|
|
1264
1478
|
* const keys = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1265
1479
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1269,11 +1483,13 @@ const _ = class _ {
|
|
|
1269
1483
|
* console.log(keys.toArray()); // ["odd", "even"]
|
|
1270
1484
|
* ```
|
|
1271
1485
|
*
|
|
1486
|
+
* ---
|
|
1487
|
+
*
|
|
1272
1488
|
* @returns A new {@link SmartIterator} containing all the keys of the iterator.
|
|
1273
1489
|
*/
|
|
1274
1490
|
keys() {
|
|
1275
1491
|
const t = this._elements;
|
|
1276
|
-
return new
|
|
1492
|
+
return new c(function* () {
|
|
1277
1493
|
for (const [e] of t)
|
|
1278
1494
|
yield e;
|
|
1279
1495
|
});
|
|
@@ -1290,6 +1506,9 @@ const _ = class _ {
|
|
|
1290
1506
|
* This means that the original iterator won't be consumed until the
|
|
1291
1507
|
* new one is and that consuming one of them will consume the other as well.
|
|
1292
1508
|
*
|
|
1509
|
+
* ---
|
|
1510
|
+
*
|
|
1511
|
+
* @example
|
|
1293
1512
|
* ```ts
|
|
1294
1513
|
* const entries = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1295
1514
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1299,6 +1518,8 @@ const _ = class _ {
|
|
|
1299
1518
|
* console.log(entries.toArray()); // [["odd", 4], ["even", 16]]
|
|
1300
1519
|
* ```
|
|
1301
1520
|
*
|
|
1521
|
+
* ---
|
|
1522
|
+
*
|
|
1302
1523
|
* @returns A new {@link SmartIterator} containing all the entries of the iterator.
|
|
1303
1524
|
*/
|
|
1304
1525
|
entries() {
|
|
@@ -1315,6 +1536,9 @@ const _ = class _ {
|
|
|
1315
1536
|
* This means that the original iterator won't be consumed until the
|
|
1316
1537
|
* new one is and that consuming one of them will consume the other as well.
|
|
1317
1538
|
*
|
|
1539
|
+
* ---
|
|
1540
|
+
*
|
|
1541
|
+
* @example
|
|
1318
1542
|
* ```ts
|
|
1319
1543
|
* const values = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1320
1544
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1324,11 +1548,13 @@ const _ = class _ {
|
|
|
1324
1548
|
* console.log(values.toArray()); // [4, 16]
|
|
1325
1549
|
* ```
|
|
1326
1550
|
*
|
|
1551
|
+
* ---
|
|
1552
|
+
*
|
|
1327
1553
|
* @returns A new {@link SmartIterator} containing all the values of the iterator.
|
|
1328
1554
|
*/
|
|
1329
1555
|
values() {
|
|
1330
1556
|
const t = this._elements;
|
|
1331
|
-
return new
|
|
1557
|
+
return new c(function* () {
|
|
1332
1558
|
for (const [e, n] of t)
|
|
1333
1559
|
yield n;
|
|
1334
1560
|
});
|
|
@@ -1339,6 +1565,9 @@ const _ = class _ {
|
|
|
1339
1565
|
*
|
|
1340
1566
|
* If the iterator is infinite, the method will never return.
|
|
1341
1567
|
*
|
|
1568
|
+
* ---
|
|
1569
|
+
*
|
|
1570
|
+
* @example
|
|
1342
1571
|
* ```ts
|
|
1343
1572
|
* const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1344
1573
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1347,6 +1576,8 @@ const _ = class _ {
|
|
|
1347
1576
|
* console.log(reduced.toArray()); // [4, 16]
|
|
1348
1577
|
* ```
|
|
1349
1578
|
*
|
|
1579
|
+
* ---
|
|
1580
|
+
*
|
|
1350
1581
|
* @returns The {@link Array} containing all elements of the iterator.
|
|
1351
1582
|
*/
|
|
1352
1583
|
toArray() {
|
|
@@ -1358,6 +1589,9 @@ const _ = class _ {
|
|
|
1358
1589
|
*
|
|
1359
1590
|
* If the iterator is infinite, the method will never return.
|
|
1360
1591
|
*
|
|
1592
|
+
* ---
|
|
1593
|
+
*
|
|
1594
|
+
* @example
|
|
1361
1595
|
* ```ts
|
|
1362
1596
|
* const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1363
1597
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1366,6 +1600,8 @@ const _ = class _ {
|
|
|
1366
1600
|
* console.log(reduced.toMap()); // Map(2) { "odd" => 4, "even" => 16 }
|
|
1367
1601
|
* ```
|
|
1368
1602
|
*
|
|
1603
|
+
* ---
|
|
1604
|
+
*
|
|
1369
1605
|
* @returns The {@link Map} containing all elements of the iterator.
|
|
1370
1606
|
*/
|
|
1371
1607
|
toMap() {
|
|
@@ -1377,6 +1613,9 @@ const _ = class _ {
|
|
|
1377
1613
|
*
|
|
1378
1614
|
* If the iterator is infinite, the method will never return.
|
|
1379
1615
|
*
|
|
1616
|
+
* ---
|
|
1617
|
+
*
|
|
1618
|
+
* @example
|
|
1380
1619
|
* ```ts
|
|
1381
1620
|
* const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1382
1621
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1385,22 +1624,24 @@ const _ = class _ {
|
|
|
1385
1624
|
* console.log(reduced.toObject()); // { odd: 4, even: 16 }
|
|
1386
1625
|
* ```
|
|
1387
1626
|
*
|
|
1627
|
+
* ---
|
|
1628
|
+
*
|
|
1388
1629
|
* @returns The {@link Object} containing all elements of the iterator.
|
|
1389
1630
|
*/
|
|
1390
1631
|
toObject() {
|
|
1391
1632
|
return Object.fromEntries(this.entries());
|
|
1392
1633
|
}
|
|
1393
1634
|
};
|
|
1394
|
-
let h =
|
|
1395
|
-
var
|
|
1396
|
-
|
|
1397
|
-
const
|
|
1635
|
+
let h = p;
|
|
1636
|
+
var me;
|
|
1637
|
+
me = Symbol.toStringTag;
|
|
1638
|
+
const w = class w {
|
|
1398
1639
|
constructor(t) {
|
|
1399
1640
|
/**
|
|
1400
1641
|
* The internal {@link SmartAsyncIterator} object that holds the elements to aggregate.
|
|
1401
1642
|
*/
|
|
1402
1643
|
a(this, "_elements");
|
|
1403
|
-
a(this,
|
|
1644
|
+
a(this, me, "AggregatedAsyncIterator");
|
|
1404
1645
|
this._elements = new f(t);
|
|
1405
1646
|
}
|
|
1406
1647
|
/**
|
|
@@ -1416,6 +1657,9 @@ const m = class m {
|
|
|
1416
1657
|
* object that will contain all the boolean results for each group.
|
|
1417
1658
|
* If the iterator is infinite, the method will never return.
|
|
1418
1659
|
*
|
|
1660
|
+
* ---
|
|
1661
|
+
*
|
|
1662
|
+
* @example
|
|
1419
1663
|
* ```ts
|
|
1420
1664
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1421
1665
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1424,6 +1668,8 @@ const m = class m {
|
|
|
1424
1668
|
* console.log(await results.toObject()); // { odd: false, even: true }
|
|
1425
1669
|
* ```
|
|
1426
1670
|
*
|
|
1671
|
+
* ---
|
|
1672
|
+
*
|
|
1427
1673
|
* @param predicate The condition to check for each element of the iterator.
|
|
1428
1674
|
*
|
|
1429
1675
|
* @returns
|
|
@@ -1453,6 +1699,9 @@ const m = class m {
|
|
|
1453
1699
|
* object that will contain all the boolean results for each group.
|
|
1454
1700
|
* If the iterator is infinite, the method will never return.
|
|
1455
1701
|
*
|
|
1702
|
+
* ---
|
|
1703
|
+
*
|
|
1704
|
+
* @example
|
|
1456
1705
|
* ```ts
|
|
1457
1706
|
* const results = new SmartAsyncIterator<number>([-5, -4, -3, -2, -1, 0])
|
|
1458
1707
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1461,6 +1710,8 @@ const m = class m {
|
|
|
1461
1710
|
* console.log(await results.toObject()); // { odd: false, even: true }
|
|
1462
1711
|
* ```
|
|
1463
1712
|
*
|
|
1713
|
+
* ---
|
|
1714
|
+
*
|
|
1464
1715
|
* @param predicate The condition to check for each element of the iterator.
|
|
1465
1716
|
*
|
|
1466
1717
|
* @returns
|
|
@@ -1479,7 +1730,7 @@ const m = class m {
|
|
|
1479
1730
|
}
|
|
1480
1731
|
filter(t) {
|
|
1481
1732
|
const e = this._elements;
|
|
1482
|
-
return new
|
|
1733
|
+
return new w(async function* () {
|
|
1483
1734
|
const n = /* @__PURE__ */ new Map();
|
|
1484
1735
|
for await (const [s, r] of e) {
|
|
1485
1736
|
const o = n.get(s) ?? 0;
|
|
@@ -1500,6 +1751,9 @@ const m = class m {
|
|
|
1500
1751
|
* This means that the original iterator won't be consumed until the
|
|
1501
1752
|
* new one is and that consuming one of them will consume the other as well.
|
|
1502
1753
|
*
|
|
1754
|
+
* ---
|
|
1755
|
+
*
|
|
1756
|
+
* @example
|
|
1503
1757
|
* ```ts
|
|
1504
1758
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1505
1759
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1508,6 +1762,8 @@ const m = class m {
|
|
|
1508
1762
|
* console.log(await results.toObject()); // { odd: [3, 1, 3, 5], even: [0, 2, 6, 8] }
|
|
1509
1763
|
* ```
|
|
1510
1764
|
*
|
|
1765
|
+
* ---
|
|
1766
|
+
*
|
|
1511
1767
|
* @template V The type of the elements after the transformation.
|
|
1512
1768
|
*
|
|
1513
1769
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -1516,7 +1772,7 @@ const m = class m {
|
|
|
1516
1772
|
*/
|
|
1517
1773
|
map(t) {
|
|
1518
1774
|
const e = this._elements;
|
|
1519
|
-
return new
|
|
1775
|
+
return new w(async function* () {
|
|
1520
1776
|
const n = /* @__PURE__ */ new Map();
|
|
1521
1777
|
for await (const [s, r] of e) {
|
|
1522
1778
|
const o = n.get(s) ?? 0;
|
|
@@ -1556,6 +1812,9 @@ const m = class m {
|
|
|
1556
1812
|
* This means that the original iterator won't be consumed until the
|
|
1557
1813
|
* new one is and that consuming one of them will consume the other as well.
|
|
1558
1814
|
*
|
|
1815
|
+
* ---
|
|
1816
|
+
*
|
|
1817
|
+
* @example
|
|
1559
1818
|
* ```ts
|
|
1560
1819
|
* const results = new SmartAsyncIterator<number>([[-3, -1], 0, 2, 3, 5, [6, 8]])
|
|
1561
1820
|
* .groupBy(async (values) =>
|
|
@@ -1568,6 +1827,8 @@ const m = class m {
|
|
|
1568
1827
|
* console.log(await results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
1569
1828
|
* ```
|
|
1570
1829
|
*
|
|
1830
|
+
* ---
|
|
1831
|
+
*
|
|
1571
1832
|
* @template V The type of the elements after the transformation.
|
|
1572
1833
|
*
|
|
1573
1834
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -1576,7 +1837,7 @@ const m = class m {
|
|
|
1576
1837
|
*/
|
|
1577
1838
|
flatMap(t) {
|
|
1578
1839
|
const e = this._elements;
|
|
1579
|
-
return new
|
|
1840
|
+
return new w(async function* () {
|
|
1580
1841
|
const n = /* @__PURE__ */ new Map();
|
|
1581
1842
|
for await (const [s, r] of e) {
|
|
1582
1843
|
const o = n.get(s) ?? 0, l = await t(s, r, o);
|
|
@@ -1601,6 +1862,9 @@ const m = class m {
|
|
|
1601
1862
|
* This means that the original iterator won't be consumed until the
|
|
1602
1863
|
* new one is and that consuming one of them will consume the other as well.
|
|
1603
1864
|
*
|
|
1865
|
+
* ---
|
|
1866
|
+
*
|
|
1867
|
+
* @example
|
|
1604
1868
|
* ```ts
|
|
1605
1869
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1606
1870
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1609,13 +1873,15 @@ const m = class m {
|
|
|
1609
1873
|
* console.log(await results.toObject()); // { odd: [3, 5], even: [6, 8] }
|
|
1610
1874
|
* ```
|
|
1611
1875
|
*
|
|
1876
|
+
* ---
|
|
1877
|
+
*
|
|
1612
1878
|
* @param count The number of elements to drop from the beginning of each group.
|
|
1613
1879
|
*
|
|
1614
1880
|
* @returns A new {@link AggregatedAsyncIterator} containing the remaining elements.
|
|
1615
1881
|
*/
|
|
1616
1882
|
drop(t) {
|
|
1617
1883
|
const e = this._elements;
|
|
1618
|
-
return new
|
|
1884
|
+
return new w(async function* () {
|
|
1619
1885
|
const n = /* @__PURE__ */ new Map();
|
|
1620
1886
|
for await (const [s, r] of e) {
|
|
1621
1887
|
const o = n.get(s) ?? 0;
|
|
@@ -1639,6 +1905,9 @@ const m = class m {
|
|
|
1639
1905
|
* This means that the original iterator won't be consumed until the
|
|
1640
1906
|
* new one is and that consuming one of them will consume the other as well.
|
|
1641
1907
|
*
|
|
1908
|
+
* ---
|
|
1909
|
+
*
|
|
1910
|
+
* @example
|
|
1642
1911
|
* ```ts
|
|
1643
1912
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1644
1913
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1647,13 +1916,15 @@ const m = class m {
|
|
|
1647
1916
|
* console.log(await results.toObject()); // { odd: [-3, -1], even: [0, 2] }
|
|
1648
1917
|
* ```
|
|
1649
1918
|
*
|
|
1650
|
-
*
|
|
1919
|
+
* ---
|
|
1920
|
+
*
|
|
1921
|
+
* @param limit The number of elements to take from the beginning of each group.
|
|
1651
1922
|
*
|
|
1652
1923
|
* @returns A new {@link AggregatedAsyncIterator} containing the taken elements.
|
|
1653
1924
|
*/
|
|
1654
1925
|
take(t) {
|
|
1655
1926
|
const e = this._elements;
|
|
1656
|
-
return new
|
|
1927
|
+
return new w(async function* () {
|
|
1657
1928
|
const n = /* @__PURE__ */ new Map();
|
|
1658
1929
|
for await (const [s, r] of e) {
|
|
1659
1930
|
const o = n.get(s) ?? 0;
|
|
@@ -1683,6 +1954,9 @@ const m = class m {
|
|
|
1683
1954
|
* This means that the original iterator won't be consumed until the
|
|
1684
1955
|
* new one is and that consuming one of them will consume the other as well.
|
|
1685
1956
|
*
|
|
1957
|
+
* ---
|
|
1958
|
+
*
|
|
1959
|
+
* @example
|
|
1686
1960
|
* ```ts
|
|
1687
1961
|
* const results = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
|
|
1688
1962
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1691,6 +1965,8 @@ const m = class m {
|
|
|
1691
1965
|
* console.log(results.toObject()); // { odd: [[0, -3], [1, -1], [2, 3]], even: [[0, 0], [1, 2]] }
|
|
1692
1966
|
* ```
|
|
1693
1967
|
*
|
|
1968
|
+
* ---
|
|
1969
|
+
*
|
|
1694
1970
|
* @returns A new {@link AggregatedAsyncIterator} containing the enumerated elements.
|
|
1695
1971
|
*/
|
|
1696
1972
|
enumerate() {
|
|
@@ -1707,6 +1983,9 @@ const m = class m {
|
|
|
1707
1983
|
* This means that the original iterator won't be consumed until the
|
|
1708
1984
|
* new one is and that consuming one of them will consume the other as well.
|
|
1709
1985
|
*
|
|
1986
|
+
* ---
|
|
1987
|
+
*
|
|
1988
|
+
* @example
|
|
1710
1989
|
* ```ts
|
|
1711
1990
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 0, 5, 6, 8, 0, 2])
|
|
1712
1991
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1715,11 +1994,13 @@ const m = class m {
|
|
|
1715
1994
|
* console.log(await results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
1716
1995
|
* ```
|
|
1717
1996
|
*
|
|
1997
|
+
* ---
|
|
1998
|
+
*
|
|
1718
1999
|
* @returns A new {@link AggregatedAsyncIterator} containing only the unique elements.
|
|
1719
2000
|
*/
|
|
1720
2001
|
unique() {
|
|
1721
2002
|
const t = this._elements;
|
|
1722
|
-
return new
|
|
2003
|
+
return new w(async function* () {
|
|
1723
2004
|
const e = /* @__PURE__ */ new Map();
|
|
1724
2005
|
for await (const [n, s] of t) {
|
|
1725
2006
|
const r = e.get(n) ?? /* @__PURE__ */ new Set();
|
|
@@ -1733,6 +2014,9 @@ const m = class m {
|
|
|
1733
2014
|
*
|
|
1734
2015
|
* If the iterator is infinite, the method will never return.
|
|
1735
2016
|
*
|
|
2017
|
+
* ---
|
|
2018
|
+
*
|
|
2019
|
+
* @example
|
|
1736
2020
|
* ```ts
|
|
1737
2021
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1738
2022
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1741,6 +2025,8 @@ const m = class m {
|
|
|
1741
2025
|
* console.log(await results.toObject()); // { odd: 4, even: 4 }
|
|
1742
2026
|
* ```
|
|
1743
2027
|
*
|
|
2028
|
+
* ---
|
|
2029
|
+
*
|
|
1744
2030
|
* @returns
|
|
1745
2031
|
* A {@link Promise} resolving to a new {@link ReducedIterator} containing the number of elements for each group.
|
|
1746
2032
|
*/
|
|
@@ -1762,6 +2048,9 @@ const m = class m {
|
|
|
1762
2048
|
* This method will consume the entire iterator in the process.
|
|
1763
2049
|
* If the iterator is infinite, the method will never return.
|
|
1764
2050
|
*
|
|
2051
|
+
* ---
|
|
2052
|
+
*
|
|
2053
|
+
* @example
|
|
1765
2054
|
* ```ts
|
|
1766
2055
|
* const aggregator = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
|
|
1767
2056
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1772,6 +2061,8 @@ const m = class m {
|
|
|
1772
2061
|
* };
|
|
1773
2062
|
* ```
|
|
1774
2063
|
*
|
|
2064
|
+
* ---
|
|
2065
|
+
*
|
|
1775
2066
|
* @param iteratee The function to execute for each element of the iterator.
|
|
1776
2067
|
*
|
|
1777
2068
|
* @returns A {@link Promise} that will resolve once the iteration is complete.
|
|
@@ -1794,6 +2085,9 @@ const m = class m {
|
|
|
1794
2085
|
* This means that the original iterator won't be consumed until the
|
|
1795
2086
|
* new one is and that consuming one of them will consume the other as well.
|
|
1796
2087
|
*
|
|
2088
|
+
* ---
|
|
2089
|
+
*
|
|
2090
|
+
* @example
|
|
1797
2091
|
* ```ts
|
|
1798
2092
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1799
2093
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1803,6 +2097,8 @@ const m = class m {
|
|
|
1803
2097
|
* console.log(await results.toObject()); // { "+": [1, 0, 3, 6], "-": [-3, -2, -5, -8] }
|
|
1804
2098
|
* ```
|
|
1805
2099
|
*
|
|
2100
|
+
* ---
|
|
2101
|
+
*
|
|
1806
2102
|
* @template J The type of the new key.
|
|
1807
2103
|
*
|
|
1808
2104
|
* @param iteratee The function to determine the new key for each element of the iterator.
|
|
@@ -1811,7 +2107,7 @@ const m = class m {
|
|
|
1811
2107
|
*/
|
|
1812
2108
|
reorganizeBy(t) {
|
|
1813
2109
|
const e = this._elements;
|
|
1814
|
-
return new
|
|
2110
|
+
return new w(async function* () {
|
|
1815
2111
|
const n = /* @__PURE__ */ new Map();
|
|
1816
2112
|
for await (const [s, r] of e) {
|
|
1817
2113
|
const o = n.get(s) ?? 0;
|
|
@@ -1830,6 +2126,9 @@ const m = class m {
|
|
|
1830
2126
|
* This means that the original iterator won't be consumed until the
|
|
1831
2127
|
* new one is and that consuming one of them will consume the other as well.
|
|
1832
2128
|
*
|
|
2129
|
+
* ---
|
|
2130
|
+
*
|
|
2131
|
+
* @example
|
|
1833
2132
|
* ```ts
|
|
1834
2133
|
* const keys = new SmartAsyncIterator([-3, Symbol(), "A", { }, null, [1 , 2, 3], false])
|
|
1835
2134
|
* .groupBy(async (value) => typeof value)
|
|
@@ -1838,6 +2137,8 @@ const m = class m {
|
|
|
1838
2137
|
* console.log(await keys.toArray()); // ["number", "symbol", "string", "object", "boolean"]
|
|
1839
2138
|
* ```
|
|
1840
2139
|
*
|
|
2140
|
+
* ---
|
|
2141
|
+
*
|
|
1841
2142
|
* @returns A new {@link SmartAsyncIterator} containing all the keys of the iterator.
|
|
1842
2143
|
*/
|
|
1843
2144
|
keys() {
|
|
@@ -1860,6 +2161,9 @@ const m = class m {
|
|
|
1860
2161
|
* This means that the original iterator won't be consumed until the
|
|
1861
2162
|
* new one is and that consuming one of them will consume the other as well.
|
|
1862
2163
|
*
|
|
2164
|
+
* ---
|
|
2165
|
+
*
|
|
2166
|
+
* @example
|
|
1863
2167
|
* ```ts
|
|
1864
2168
|
* const entries = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
|
|
1865
2169
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1868,6 +2172,8 @@ const m = class m {
|
|
|
1868
2172
|
* console.log(await entries.toArray()); // [["odd", -3], ["even", 0], ["even", 2], ["odd", -1], ["odd", 3]]
|
|
1869
2173
|
* ```
|
|
1870
2174
|
*
|
|
2175
|
+
* ---
|
|
2176
|
+
*
|
|
1871
2177
|
* @returns A new {@link SmartAsyncIterator} containing all the entries of the iterator.
|
|
1872
2178
|
*/
|
|
1873
2179
|
entries() {
|
|
@@ -1884,6 +2190,9 @@ const m = class m {
|
|
|
1884
2190
|
* This means that the original iterator won't be consumed until the
|
|
1885
2191
|
* new one is and that consuming one of them will consume the other as well.
|
|
1886
2192
|
*
|
|
2193
|
+
* ---
|
|
2194
|
+
*
|
|
2195
|
+
* @example
|
|
1887
2196
|
* ```ts
|
|
1888
2197
|
* const values = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1889
2198
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1892,6 +2201,8 @@ const m = class m {
|
|
|
1892
2201
|
* console.log(await values.toArray()); // [-3, -1, 0, 2, 3, 5, 6, 8]
|
|
1893
2202
|
* ```
|
|
1894
2203
|
*
|
|
2204
|
+
* ---
|
|
2205
|
+
*
|
|
1895
2206
|
* @returns A new {@link SmartAsyncIterator} containing all the values of the iterator.
|
|
1896
2207
|
*/
|
|
1897
2208
|
values() {
|
|
@@ -1907,6 +2218,9 @@ const m = class m {
|
|
|
1907
2218
|
*
|
|
1908
2219
|
* If the iterator is infinite, the method will never return.
|
|
1909
2220
|
*
|
|
2221
|
+
* ---
|
|
2222
|
+
*
|
|
2223
|
+
* @example
|
|
1910
2224
|
* ```ts
|
|
1911
2225
|
* const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1912
2226
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1914,6 +2228,8 @@ const m = class m {
|
|
|
1914
2228
|
* console.log(await aggregator.toArray()); // [[-3, -1, 3, 5], [0, 2, 6, 8]]
|
|
1915
2229
|
* ```
|
|
1916
2230
|
*
|
|
2231
|
+
* ---
|
|
2232
|
+
*
|
|
1917
2233
|
* @returns A {@link Promise} resolving to an {@link Array} containing all the values of the iterator.
|
|
1918
2234
|
*/
|
|
1919
2235
|
async toArray() {
|
|
@@ -1926,6 +2242,9 @@ const m = class m {
|
|
|
1926
2242
|
*
|
|
1927
2243
|
* If the iterator is infinite, the method will never return.
|
|
1928
2244
|
*
|
|
2245
|
+
* ---
|
|
2246
|
+
*
|
|
2247
|
+
* @example
|
|
1929
2248
|
* ```ts
|
|
1930
2249
|
* const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1931
2250
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1933,6 +2252,8 @@ const m = class m {
|
|
|
1933
2252
|
* console.log(await aggregator.toMap()); // Map(2) { "odd" => [-3, -1, 3, 5], "even" => [0, 2, 6, 8] }
|
|
1934
2253
|
* ```
|
|
1935
2254
|
*
|
|
2255
|
+
* ---
|
|
2256
|
+
*
|
|
1936
2257
|
* @returns A {@link Promise} resolving to a {@link Map} containing all the entries of the iterator.
|
|
1937
2258
|
*/
|
|
1938
2259
|
async toMap() {
|
|
@@ -1949,6 +2270,9 @@ const m = class m {
|
|
|
1949
2270
|
*
|
|
1950
2271
|
* If the iterator is infinite, the method will never return.
|
|
1951
2272
|
*
|
|
2273
|
+
* ---
|
|
2274
|
+
*
|
|
2275
|
+
* @example
|
|
1952
2276
|
* ```ts
|
|
1953
2277
|
* const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1954
2278
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1956,6 +2280,8 @@ const m = class m {
|
|
|
1956
2280
|
* console.log(await aggregator.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
1957
2281
|
* ```
|
|
1958
2282
|
*
|
|
2283
|
+
* ---
|
|
2284
|
+
*
|
|
1959
2285
|
* @returns A {@link Promise} resolving to an object containing all the entries of the iterator.
|
|
1960
2286
|
*/
|
|
1961
2287
|
async toObject() {
|
|
@@ -1967,7 +2293,7 @@ const m = class m {
|
|
|
1967
2293
|
return t;
|
|
1968
2294
|
}
|
|
1969
2295
|
};
|
|
1970
|
-
let T =
|
|
2296
|
+
let T = w;
|
|
1971
2297
|
var ye;
|
|
1972
2298
|
class f {
|
|
1973
2299
|
constructor(t) {
|
|
@@ -2023,6 +2349,9 @@ class f {
|
|
|
2023
2349
|
*
|
|
2024
2350
|
* If the iterator is infinite and every element satisfies the condition, the method will never return.
|
|
2025
2351
|
*
|
|
2352
|
+
* ---
|
|
2353
|
+
*
|
|
2354
|
+
* @example
|
|
2026
2355
|
* ```ts
|
|
2027
2356
|
* const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
|
|
2028
2357
|
* const result = await iterator.every(async (value) => value < 0);
|
|
@@ -2030,6 +2359,8 @@ class f {
|
|
|
2030
2359
|
* console.log(result); // false
|
|
2031
2360
|
* ```
|
|
2032
2361
|
*
|
|
2362
|
+
* ---
|
|
2363
|
+
*
|
|
2033
2364
|
* @param predicate The condition to check for each element of the iterator.
|
|
2034
2365
|
*
|
|
2035
2366
|
* @returns
|
|
@@ -2059,6 +2390,9 @@ class f {
|
|
|
2059
2390
|
*
|
|
2060
2391
|
* If the iterator is infinite and no element satisfies the condition, the method will never return.
|
|
2061
2392
|
*
|
|
2393
|
+
* ---
|
|
2394
|
+
*
|
|
2395
|
+
* @example
|
|
2062
2396
|
* ```ts
|
|
2063
2397
|
* const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
|
|
2064
2398
|
* const result = await iterator.some(async (value) => value > 0);
|
|
@@ -2066,6 +2400,8 @@ class f {
|
|
|
2066
2400
|
* console.log(result); // true
|
|
2067
2401
|
* ```
|
|
2068
2402
|
*
|
|
2403
|
+
* ---
|
|
2404
|
+
*
|
|
2069
2405
|
* @param predicate The condition to check for each element of the iterator.
|
|
2070
2406
|
*
|
|
2071
2407
|
* @returns
|
|
@@ -2107,6 +2443,9 @@ class f {
|
|
|
2107
2443
|
* This means that the original iterator won't be consumed until the
|
|
2108
2444
|
* new one is and that consuming one of them will consume the other as well.
|
|
2109
2445
|
*
|
|
2446
|
+
* ---
|
|
2447
|
+
*
|
|
2448
|
+
* @example
|
|
2110
2449
|
* ```ts
|
|
2111
2450
|
* const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
|
|
2112
2451
|
* const result = iterator.map(async (value) => Math.abs(value));
|
|
@@ -2114,6 +2453,8 @@ class f {
|
|
|
2114
2453
|
* console.log(await result.toArray()); // [2, 1, 0, 1, 2]
|
|
2115
2454
|
* ```
|
|
2116
2455
|
*
|
|
2456
|
+
* ---
|
|
2457
|
+
*
|
|
2117
2458
|
* @template V The type of the elements after the transformation.
|
|
2118
2459
|
*
|
|
2119
2460
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -2160,6 +2501,9 @@ class f {
|
|
|
2160
2501
|
* This means that the original iterator won't be consumed until the
|
|
2161
2502
|
* new one is and that consuming one of them will consume the other as well.
|
|
2162
2503
|
*
|
|
2504
|
+
* ---
|
|
2505
|
+
*
|
|
2506
|
+
* @example
|
|
2163
2507
|
* ```ts
|
|
2164
2508
|
* const iterator = new SmartAsyncIterator<number[]>([[-2, -1], 0, 1, 2, [3, 4, 5]]);
|
|
2165
2509
|
* const result = iterator.flatMap(async (value) => value);
|
|
@@ -2167,6 +2511,8 @@ class f {
|
|
|
2167
2511
|
* console.log(await result.toArray()); // [-2, -1, 0, 1, 2, 3, 4, 5]
|
|
2168
2512
|
* ```
|
|
2169
2513
|
*
|
|
2514
|
+
* ---
|
|
2515
|
+
*
|
|
2170
2516
|
* @template V The type of the elements after the transformation.
|
|
2171
2517
|
*
|
|
2172
2518
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -2206,6 +2552,9 @@ class f {
|
|
|
2206
2552
|
* Only the dropped elements will be consumed in the process.
|
|
2207
2553
|
* The rest of the iterator will be consumed only once the new one is.
|
|
2208
2554
|
*
|
|
2555
|
+
* ---
|
|
2556
|
+
*
|
|
2557
|
+
* @example
|
|
2209
2558
|
* ```ts
|
|
2210
2559
|
* const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
|
|
2211
2560
|
* const result = iterator.drop(3);
|
|
@@ -2213,6 +2562,8 @@ class f {
|
|
|
2213
2562
|
* console.log(await result.toArray()); // [1, 2]
|
|
2214
2563
|
* ```
|
|
2215
2564
|
*
|
|
2565
|
+
* ---
|
|
2566
|
+
*
|
|
2216
2567
|
* @param count The number of elements to drop.
|
|
2217
2568
|
*
|
|
2218
2569
|
* @returns A new {@link SmartAsyncIterator} containing the remaining elements.
|
|
@@ -2249,6 +2600,9 @@ class f {
|
|
|
2249
2600
|
* Only the taken elements will be consumed from the original iterator.
|
|
2250
2601
|
* The rest of the original iterator will be available for further consumption.
|
|
2251
2602
|
*
|
|
2603
|
+
* ---
|
|
2604
|
+
*
|
|
2605
|
+
* @example
|
|
2252
2606
|
* ```ts
|
|
2253
2607
|
* const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
|
|
2254
2608
|
* const result = iterator.take(3);
|
|
@@ -2257,6 +2611,8 @@ class f {
|
|
|
2257
2611
|
* console.log(await iterator.toArray()); // [1, 2]
|
|
2258
2612
|
* ```
|
|
2259
2613
|
*
|
|
2614
|
+
* ---
|
|
2615
|
+
*
|
|
2260
2616
|
* @param limit The number of elements to take.
|
|
2261
2617
|
*
|
|
2262
2618
|
* @returns A new {@link SmartAsyncIterator} containing the taken elements.
|
|
@@ -2295,6 +2651,9 @@ class f {
|
|
|
2295
2651
|
* This means that the original iterator won't be consumed until the
|
|
2296
2652
|
* new one is and that consuming one of them will consume the other as well.
|
|
2297
2653
|
*
|
|
2654
|
+
* ---
|
|
2655
|
+
*
|
|
2656
|
+
* @example
|
|
2298
2657
|
* ```ts
|
|
2299
2658
|
* const iterator = new SmartAsyncIterator<string>(["A", "M", "N", "Z"]);
|
|
2300
2659
|
* const result = iterator.enumerate();
|
|
@@ -2305,6 +2664,8 @@ class f {
|
|
|
2305
2664
|
* }
|
|
2306
2665
|
* ```
|
|
2307
2666
|
*
|
|
2667
|
+
* ---
|
|
2668
|
+
*
|
|
2308
2669
|
* @returns A new {@link SmartAsyncIterator} containing the enumerated elements.
|
|
2309
2670
|
*/
|
|
2310
2671
|
enumerate() {
|
|
@@ -2321,6 +2682,9 @@ class f {
|
|
|
2321
2682
|
* This means that the original iterator won't be consumed until the
|
|
2322
2683
|
* new one is and that consuming one of them will consume the other as well.
|
|
2323
2684
|
*
|
|
2685
|
+
* ---
|
|
2686
|
+
*
|
|
2687
|
+
* @example
|
|
2324
2688
|
* ```ts
|
|
2325
2689
|
* const iterator = new SmartAsyncIterator<number>([1, 1, 2, 3, 2, 3, 4, 5, 5, 4]);
|
|
2326
2690
|
* const result = iterator.unique();
|
|
@@ -2328,6 +2692,8 @@ class f {
|
|
|
2328
2692
|
* console.log(await result.toArray()); // [1, 2, 3, 4, 5]
|
|
2329
2693
|
* ```
|
|
2330
2694
|
*
|
|
2695
|
+
* ---
|
|
2696
|
+
*
|
|
2331
2697
|
* @returns A new {@link SmartAsyncIterator} containing only the unique elements.
|
|
2332
2698
|
*/
|
|
2333
2699
|
unique() {
|
|
@@ -2348,6 +2714,9 @@ class f {
|
|
|
2348
2714
|
*
|
|
2349
2715
|
* If the iterator is infinite, the method will never return.
|
|
2350
2716
|
*
|
|
2717
|
+
* ---
|
|
2718
|
+
*
|
|
2719
|
+
* @example
|
|
2351
2720
|
* ```ts
|
|
2352
2721
|
* const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5]);
|
|
2353
2722
|
* const result = await iterator.count();
|
|
@@ -2355,6 +2724,8 @@ class f {
|
|
|
2355
2724
|
* console.log(result); // 5
|
|
2356
2725
|
* ```
|
|
2357
2726
|
*
|
|
2727
|
+
* ---
|
|
2728
|
+
*
|
|
2358
2729
|
* @returns A {@link Promise} that will resolve to the number of elements in the iterator.
|
|
2359
2730
|
*/
|
|
2360
2731
|
async count() {
|
|
@@ -2372,6 +2743,9 @@ class f {
|
|
|
2372
2743
|
* This method will consume the entire iterator in the process.
|
|
2373
2744
|
* If the iterator is infinite, the method will never return.
|
|
2374
2745
|
*
|
|
2746
|
+
* ---
|
|
2747
|
+
*
|
|
2748
|
+
* @example
|
|
2375
2749
|
* ```ts
|
|
2376
2750
|
* const iterator = new SmartAsyncIterator<number>(["A", "M", "N", "Z"]);
|
|
2377
2751
|
* await iterator.forEach(async (value, index) =>
|
|
@@ -2380,6 +2754,8 @@ class f {
|
|
|
2380
2754
|
* }
|
|
2381
2755
|
* ```
|
|
2382
2756
|
*
|
|
2757
|
+
* ---
|
|
2758
|
+
*
|
|
2383
2759
|
* @param iteratee The function to apply to each element of the iterator.
|
|
2384
2760
|
*
|
|
2385
2761
|
* @returns A {@link Promise} that will resolve once the iteration is complete.
|
|
@@ -2399,6 +2775,9 @@ class f {
|
|
|
2399
2775
|
*
|
|
2400
2776
|
* Once the iterator is done, the method will return an object with the `done` property set to `true`.
|
|
2401
2777
|
*
|
|
2778
|
+
* ---
|
|
2779
|
+
*
|
|
2780
|
+
* @example
|
|
2402
2781
|
* ```ts
|
|
2403
2782
|
* const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5]);
|
|
2404
2783
|
*
|
|
@@ -2413,6 +2792,8 @@ class f {
|
|
|
2413
2792
|
* console.log(result); // { done: true, value: undefined }
|
|
2414
2793
|
* ```
|
|
2415
2794
|
*
|
|
2795
|
+
* ---
|
|
2796
|
+
*
|
|
2416
2797
|
* @param values The value to pass to the next element, if required.
|
|
2417
2798
|
*
|
|
2418
2799
|
* @returns
|
|
@@ -2426,6 +2807,9 @@ class f {
|
|
|
2426
2807
|
* free the resources and perform any cleanup operation.
|
|
2427
2808
|
* It may also be used to signal the end or to compute a specific final result of the iteration process.
|
|
2428
2809
|
*
|
|
2810
|
+
* ---
|
|
2811
|
+
*
|
|
2812
|
+
* @example
|
|
2429
2813
|
* ```ts
|
|
2430
2814
|
* const iterator = new SmartAsyncIterator<number>({
|
|
2431
2815
|
* _index: 0,
|
|
@@ -2444,6 +2828,8 @@ class f {
|
|
|
2444
2828
|
* }
|
|
2445
2829
|
* ```
|
|
2446
2830
|
*
|
|
2831
|
+
* ---
|
|
2832
|
+
*
|
|
2447
2833
|
* @param value The final value of the iterator.
|
|
2448
2834
|
*
|
|
2449
2835
|
* @returns A {@link Promise} that will resolve to the final result of the iterator.
|
|
@@ -2457,6 +2843,9 @@ class f {
|
|
|
2457
2843
|
* free the resources and perform any cleanup operation.
|
|
2458
2844
|
* It may also be used to signal that an error occurred during the iteration process or to handle it.
|
|
2459
2845
|
*
|
|
2846
|
+
* ---
|
|
2847
|
+
*
|
|
2848
|
+
* @example
|
|
2460
2849
|
* ```ts
|
|
2461
2850
|
* const iterator = new SmartAsyncIterator<number>({
|
|
2462
2851
|
* _index: 0,
|
|
@@ -2484,6 +2873,8 @@ class f {
|
|
|
2484
2873
|
* }
|
|
2485
2874
|
* ```
|
|
2486
2875
|
*
|
|
2876
|
+
* ---
|
|
2877
|
+
*
|
|
2487
2878
|
* @param error The error to throw into the iterator.
|
|
2488
2879
|
*
|
|
2489
2880
|
* @returns A {@link Promise} that will resolve to the final result of the iterator.
|
|
@@ -2505,6 +2896,9 @@ class f {
|
|
|
2505
2896
|
* This means that the original iterator won't be consumed until the
|
|
2506
2897
|
* the new one is and that consuming one of them will consume the other as well.
|
|
2507
2898
|
*
|
|
2899
|
+
* ---
|
|
2900
|
+
*
|
|
2901
|
+
* @example
|
|
2508
2902
|
* ```ts
|
|
2509
2903
|
* const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
2510
2904
|
* const result = iterator.groupBy<string>(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -2512,6 +2906,8 @@ class f {
|
|
|
2512
2906
|
* console.log(await result.toObject()); // { odd: [1, 3, 5, 7, 9], even: [2, 4, 6, 8, 10] }
|
|
2513
2907
|
* ```
|
|
2514
2908
|
*
|
|
2909
|
+
* ---
|
|
2910
|
+
*
|
|
2515
2911
|
* @template K The type of the keys used to group the elements.
|
|
2516
2912
|
*
|
|
2517
2913
|
* @param iteratee The key function to apply to each element of the iterator.
|
|
@@ -2527,6 +2923,9 @@ class f {
|
|
|
2527
2923
|
*
|
|
2528
2924
|
* If the iterator is infinite, the method will never return.
|
|
2529
2925
|
*
|
|
2926
|
+
* ---
|
|
2927
|
+
*
|
|
2928
|
+
* @example
|
|
2530
2929
|
* ```ts
|
|
2531
2930
|
* const iterator = new SmartAsyncIterator(async function* ()
|
|
2532
2931
|
* {
|
|
@@ -2537,6 +2936,8 @@ class f {
|
|
|
2537
2936
|
* console.log(result); // [0, 1, 2, 3, 4]
|
|
2538
2937
|
* ```
|
|
2539
2938
|
*
|
|
2939
|
+
* ---
|
|
2940
|
+
*
|
|
2540
2941
|
* @returns A {@link Promise} that will resolve to an array containing all elements of the iterator.
|
|
2541
2942
|
*/
|
|
2542
2943
|
toArray() {
|
|
@@ -2548,14 +2949,14 @@ class f {
|
|
|
2548
2949
|
}
|
|
2549
2950
|
var _e;
|
|
2550
2951
|
_e = Symbol.toStringTag;
|
|
2551
|
-
const
|
|
2952
|
+
const m = class m {
|
|
2552
2953
|
constructor(t) {
|
|
2553
2954
|
/**
|
|
2554
2955
|
* The internal {@link SmartIterator} object that holds the elements to aggregate.
|
|
2555
2956
|
*/
|
|
2556
2957
|
a(this, "_elements");
|
|
2557
2958
|
a(this, _e, "AggregatedIterator");
|
|
2558
|
-
this._elements = new
|
|
2959
|
+
this._elements = new c(t);
|
|
2559
2960
|
}
|
|
2560
2961
|
/**
|
|
2561
2962
|
* Determines whether all elements of each group of the iterator satisfy a given condition.
|
|
@@ -2570,6 +2971,9 @@ const w = class w {
|
|
|
2570
2971
|
* object that will contain all the boolean results for each group.
|
|
2571
2972
|
* If the iterator is infinite, the method will never return.
|
|
2572
2973
|
*
|
|
2974
|
+
* ---
|
|
2975
|
+
*
|
|
2976
|
+
* @example
|
|
2573
2977
|
* ```ts
|
|
2574
2978
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2575
2979
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2578,6 +2982,8 @@ const w = class w {
|
|
|
2578
2982
|
* console.log(results.toObject()); // { odd: false, even: true }
|
|
2579
2983
|
* ```
|
|
2580
2984
|
*
|
|
2985
|
+
* ---
|
|
2986
|
+
*
|
|
2581
2987
|
* @param predicate The condition to check for each element of the iterator.
|
|
2582
2988
|
*
|
|
2583
2989
|
* @returns A new {@link ReducedIterator} containing the boolean results for each group.
|
|
@@ -2606,6 +3012,9 @@ const w = class w {
|
|
|
2606
3012
|
* object that will contain all the boolean results for each group.
|
|
2607
3013
|
* If the iterator is infinite, the method will never return.
|
|
2608
3014
|
*
|
|
3015
|
+
* ---
|
|
3016
|
+
*
|
|
3017
|
+
* @example
|
|
2609
3018
|
* ```ts
|
|
2610
3019
|
* const results = new SmartIterator<number>([-5, -4, -3, -2, -1, 0])
|
|
2611
3020
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2614,6 +3023,8 @@ const w = class w {
|
|
|
2614
3023
|
* console.log(results.toObject()); // { odd: false, even: true }
|
|
2615
3024
|
* ```
|
|
2616
3025
|
*
|
|
3026
|
+
* ---
|
|
3027
|
+
*
|
|
2617
3028
|
* @param predicate The condition to check for each element of the iterator.
|
|
2618
3029
|
*
|
|
2619
3030
|
* @returns A {@link ReducedIterator} containing the boolean results for each group.
|
|
@@ -2631,7 +3042,7 @@ const w = class w {
|
|
|
2631
3042
|
}
|
|
2632
3043
|
filter(t) {
|
|
2633
3044
|
const e = this._elements;
|
|
2634
|
-
return new
|
|
3045
|
+
return new m(function* () {
|
|
2635
3046
|
const n = /* @__PURE__ */ new Map();
|
|
2636
3047
|
for (const [s, r] of e) {
|
|
2637
3048
|
const o = n.get(s) ?? 0;
|
|
@@ -2652,6 +3063,9 @@ const w = class w {
|
|
|
2652
3063
|
* This means that the original iterator won't be consumed until the
|
|
2653
3064
|
* new one is and that consuming one of them will consume the other as well.
|
|
2654
3065
|
*
|
|
3066
|
+
* ---
|
|
3067
|
+
*
|
|
3068
|
+
* @example
|
|
2655
3069
|
* ```ts
|
|
2656
3070
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2657
3071
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2660,6 +3074,8 @@ const w = class w {
|
|
|
2660
3074
|
* console.log(results.toObject()); // { odd: [3, 1, 3, 5], even: [0, 2, 6, 8] }
|
|
2661
3075
|
* ```
|
|
2662
3076
|
*
|
|
3077
|
+
* ---
|
|
3078
|
+
*
|
|
2663
3079
|
* @template V The type of the elements after the transformation.
|
|
2664
3080
|
*
|
|
2665
3081
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -2668,7 +3084,7 @@ const w = class w {
|
|
|
2668
3084
|
*/
|
|
2669
3085
|
map(t) {
|
|
2670
3086
|
const e = this._elements;
|
|
2671
|
-
return new
|
|
3087
|
+
return new m(function* () {
|
|
2672
3088
|
const n = /* @__PURE__ */ new Map();
|
|
2673
3089
|
for (const [s, r] of e) {
|
|
2674
3090
|
const o = n.get(s) ?? 0;
|
|
@@ -2708,6 +3124,9 @@ const w = class w {
|
|
|
2708
3124
|
* This means that the original iterator won't be consumed until the
|
|
2709
3125
|
* new one is and that consuming one of them will consume the other as well.
|
|
2710
3126
|
*
|
|
3127
|
+
* ---
|
|
3128
|
+
*
|
|
3129
|
+
* @example
|
|
2711
3130
|
* ```ts
|
|
2712
3131
|
* const results = new SmartIterator<number[]>([[-3, -1], 0, 2, 3, 5, [6, 8]])
|
|
2713
3132
|
* .groupBy((values) =>
|
|
@@ -2720,6 +3139,8 @@ const w = class w {
|
|
|
2720
3139
|
* console.log(results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
2721
3140
|
* ```
|
|
2722
3141
|
*
|
|
3142
|
+
* ---
|
|
3143
|
+
*
|
|
2723
3144
|
* @template V The type of the elements after the transformation.
|
|
2724
3145
|
*
|
|
2725
3146
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -2728,7 +3149,7 @@ const w = class w {
|
|
|
2728
3149
|
*/
|
|
2729
3150
|
flatMap(t) {
|
|
2730
3151
|
const e = this._elements;
|
|
2731
|
-
return new
|
|
3152
|
+
return new m(function* () {
|
|
2732
3153
|
const n = /* @__PURE__ */ new Map();
|
|
2733
3154
|
for (const [s, r] of e) {
|
|
2734
3155
|
const o = n.get(s) ?? 0, l = t(s, r, o);
|
|
@@ -2753,6 +3174,9 @@ const w = class w {
|
|
|
2753
3174
|
* This means that the original iterator won't be consumed until the
|
|
2754
3175
|
* new one is and that consuming one of them will consume the other as well.
|
|
2755
3176
|
*
|
|
3177
|
+
* ---
|
|
3178
|
+
*
|
|
3179
|
+
* @example
|
|
2756
3180
|
* ```ts
|
|
2757
3181
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2758
3182
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2761,13 +3185,15 @@ const w = class w {
|
|
|
2761
3185
|
* console.log(results.toObject()); // { odd: [3, 5], even: [6, 8] }
|
|
2762
3186
|
* ```
|
|
2763
3187
|
*
|
|
3188
|
+
* ---
|
|
3189
|
+
*
|
|
2764
3190
|
* @param count The number of elements to drop from the beginning of each group.
|
|
2765
3191
|
*
|
|
2766
3192
|
* @returns A new {@link AggregatedIterator} containing the remaining elements.
|
|
2767
3193
|
*/
|
|
2768
3194
|
drop(t) {
|
|
2769
3195
|
const e = this._elements;
|
|
2770
|
-
return new
|
|
3196
|
+
return new m(function* () {
|
|
2771
3197
|
const n = /* @__PURE__ */ new Map();
|
|
2772
3198
|
for (const [s, r] of e) {
|
|
2773
3199
|
const o = n.get(s) ?? 0;
|
|
@@ -2791,6 +3217,9 @@ const w = class w {
|
|
|
2791
3217
|
* This means that the original iterator won't be consumed until the
|
|
2792
3218
|
* new one is and that consuming one of them will consume the other as well.
|
|
2793
3219
|
*
|
|
3220
|
+
* ---
|
|
3221
|
+
*
|
|
3222
|
+
* @example
|
|
2794
3223
|
* ```ts
|
|
2795
3224
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2796
3225
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2799,13 +3228,15 @@ const w = class w {
|
|
|
2799
3228
|
* console.log(results.toObject()); // { odd: [-3, -1], even: [0, 2] }
|
|
2800
3229
|
* ```
|
|
2801
3230
|
*
|
|
2802
|
-
*
|
|
3231
|
+
* ---
|
|
3232
|
+
*
|
|
3233
|
+
* @param limit The number of elements to take from the beginning of each group.
|
|
2803
3234
|
*
|
|
2804
3235
|
* @returns A new {@link AggregatedIterator} containing the taken elements.
|
|
2805
3236
|
*/
|
|
2806
3237
|
take(t) {
|
|
2807
3238
|
const e = this._elements;
|
|
2808
|
-
return new
|
|
3239
|
+
return new m(function* () {
|
|
2809
3240
|
const n = /* @__PURE__ */ new Map();
|
|
2810
3241
|
for (const [s, r] of e) {
|
|
2811
3242
|
const o = n.get(s) ?? 0;
|
|
@@ -2835,6 +3266,9 @@ const w = class w {
|
|
|
2835
3266
|
* This means that the original iterator won't be consumed until the
|
|
2836
3267
|
* new one is and that consuming one of them will consume the other as well.
|
|
2837
3268
|
*
|
|
3269
|
+
* ---
|
|
3270
|
+
*
|
|
3271
|
+
* @example
|
|
2838
3272
|
* ```ts
|
|
2839
3273
|
* const results = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
2840
3274
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2843,6 +3277,8 @@ const w = class w {
|
|
|
2843
3277
|
* console.log(results.toObject()); // { odd: [[0, -3], [1, -1], [2, 3]], even: [[0, 0], [1, 2]] }
|
|
2844
3278
|
* ```
|
|
2845
3279
|
*
|
|
3280
|
+
* ---
|
|
3281
|
+
*
|
|
2846
3282
|
* @returns A new {@link AggregatedIterator} containing the enumerated elements.
|
|
2847
3283
|
*/
|
|
2848
3284
|
enumerate() {
|
|
@@ -2859,6 +3295,9 @@ const w = class w {
|
|
|
2859
3295
|
* This means that the original iterator won't be consumed until the
|
|
2860
3296
|
* new one is and that consuming one of them will consume the other as well.
|
|
2861
3297
|
*
|
|
3298
|
+
* ---
|
|
3299
|
+
*
|
|
3300
|
+
* @example
|
|
2862
3301
|
* ```ts
|
|
2863
3302
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 0, 5, 6, 8, 0, 2])
|
|
2864
3303
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2867,11 +3306,13 @@ const w = class w {
|
|
|
2867
3306
|
* console.log(results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
2868
3307
|
* ```
|
|
2869
3308
|
*
|
|
3309
|
+
* ---
|
|
3310
|
+
*
|
|
2870
3311
|
* @returns A new {@link AggregatedIterator} containing only the unique elements.
|
|
2871
3312
|
*/
|
|
2872
3313
|
unique() {
|
|
2873
3314
|
const t = this._elements;
|
|
2874
|
-
return new
|
|
3315
|
+
return new m(function* () {
|
|
2875
3316
|
const e = /* @__PURE__ */ new Map();
|
|
2876
3317
|
for (const [n, s] of t) {
|
|
2877
3318
|
const r = e.get(n) ?? /* @__PURE__ */ new Set();
|
|
@@ -2885,6 +3326,9 @@ const w = class w {
|
|
|
2885
3326
|
*
|
|
2886
3327
|
* If the iterator is infinite, the method will never return.
|
|
2887
3328
|
*
|
|
3329
|
+
* ---
|
|
3330
|
+
*
|
|
3331
|
+
* @example
|
|
2888
3332
|
* ```ts
|
|
2889
3333
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2890
3334
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2893,6 +3337,8 @@ const w = class w {
|
|
|
2893
3337
|
* console.log(results.toObject()); // { odd: 4, even: 4 }
|
|
2894
3338
|
* ```
|
|
2895
3339
|
*
|
|
3340
|
+
* ---
|
|
3341
|
+
*
|
|
2896
3342
|
* @returns A new {@link ReducedIterator} containing the number of elements for each group.
|
|
2897
3343
|
*/
|
|
2898
3344
|
count() {
|
|
@@ -2913,6 +3359,9 @@ const w = class w {
|
|
|
2913
3359
|
* This method will consume the entire iterator in the process.
|
|
2914
3360
|
* If the iterator is infinite, the method will never return.
|
|
2915
3361
|
*
|
|
3362
|
+
* ---
|
|
3363
|
+
*
|
|
3364
|
+
* @example
|
|
2916
3365
|
* ```ts
|
|
2917
3366
|
* const aggregator = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
2918
3367
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -2923,6 +3372,8 @@ const w = class w {
|
|
|
2923
3372
|
* };
|
|
2924
3373
|
* ```
|
|
2925
3374
|
*
|
|
3375
|
+
* ---
|
|
3376
|
+
*
|
|
2926
3377
|
* @param iteratee The function to execute for each element of the iterator.
|
|
2927
3378
|
*/
|
|
2928
3379
|
forEach(t) {
|
|
@@ -2943,6 +3394,9 @@ const w = class w {
|
|
|
2943
3394
|
* This means that the original iterator won't be consumed until the
|
|
2944
3395
|
* new one is and that consuming one of them will consume the other as well.
|
|
2945
3396
|
*
|
|
3397
|
+
* ---
|
|
3398
|
+
*
|
|
3399
|
+
* @example
|
|
2946
3400
|
* ```ts
|
|
2947
3401
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2948
3402
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2952,6 +3406,8 @@ const w = class w {
|
|
|
2952
3406
|
* console.log(results.toObject()); // { "+": [1, 0, 3, 6], "-": [-3, -2, -5, -8] }
|
|
2953
3407
|
* ```
|
|
2954
3408
|
*
|
|
3409
|
+
* ---
|
|
3410
|
+
*
|
|
2955
3411
|
* @template J The type of the new key.
|
|
2956
3412
|
*
|
|
2957
3413
|
* @param iteratee The function to determine the new key for each element of the iterator.
|
|
@@ -2960,7 +3416,7 @@ const w = class w {
|
|
|
2960
3416
|
*/
|
|
2961
3417
|
reorganizeBy(t) {
|
|
2962
3418
|
const e = this._elements;
|
|
2963
|
-
return new
|
|
3419
|
+
return new m(function* () {
|
|
2964
3420
|
const n = /* @__PURE__ */ new Map();
|
|
2965
3421
|
for (const [s, r] of e) {
|
|
2966
3422
|
const o = n.get(s) ?? 0;
|
|
@@ -2979,6 +3435,9 @@ const w = class w {
|
|
|
2979
3435
|
* This means that the original iterator won't be consumed until the
|
|
2980
3436
|
* new one is and that consuming one of them will consume the other as well.
|
|
2981
3437
|
*
|
|
3438
|
+
* ---
|
|
3439
|
+
*
|
|
3440
|
+
* @example
|
|
2982
3441
|
* ```ts
|
|
2983
3442
|
* const keys = new SmartIterator([-3, Symbol(), "A", { }, null, [1 , 2, 3], false])
|
|
2984
3443
|
* .groupBy((value) => typeof value)
|
|
@@ -2987,11 +3446,13 @@ const w = class w {
|
|
|
2987
3446
|
* console.log(keys.toArray()); // ["number", "symbol", "string", "object", "boolean"]
|
|
2988
3447
|
* ```
|
|
2989
3448
|
*
|
|
3449
|
+
* ---
|
|
3450
|
+
*
|
|
2990
3451
|
* @returns A new {@link SmartIterator} containing all the keys of the iterator.
|
|
2991
3452
|
*/
|
|
2992
3453
|
keys() {
|
|
2993
3454
|
const t = this._elements;
|
|
2994
|
-
return new
|
|
3455
|
+
return new c(function* () {
|
|
2995
3456
|
const e = /* @__PURE__ */ new Set();
|
|
2996
3457
|
for (const [n] of t)
|
|
2997
3458
|
e.has(n) || (e.add(n), yield n);
|
|
@@ -3009,6 +3470,9 @@ const w = class w {
|
|
|
3009
3470
|
* This means that the original iterator won't be consumed until the
|
|
3010
3471
|
* new one is and that consuming one of them will consume the other as well.
|
|
3011
3472
|
*
|
|
3473
|
+
* ---
|
|
3474
|
+
*
|
|
3475
|
+
* @example
|
|
3012
3476
|
* ```ts
|
|
3013
3477
|
* const entries = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
3014
3478
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -3017,6 +3481,8 @@ const w = class w {
|
|
|
3017
3481
|
* console.log(entries.toArray()); // [["odd", -3], ["even", 0], ["even", 2], ["odd", -1], ["odd", 3]]
|
|
3018
3482
|
* ```
|
|
3019
3483
|
*
|
|
3484
|
+
* ---
|
|
3485
|
+
*
|
|
3020
3486
|
* @returns A new {@link SmartIterator} containing all the entries of the iterator.
|
|
3021
3487
|
*/
|
|
3022
3488
|
entries() {
|
|
@@ -3033,6 +3499,9 @@ const w = class w {
|
|
|
3033
3499
|
* This means that the original iterator won't be consumed until the
|
|
3034
3500
|
* new one is and that consuming one of them will consume the other as well.
|
|
3035
3501
|
*
|
|
3502
|
+
* ---
|
|
3503
|
+
*
|
|
3504
|
+
* @example
|
|
3036
3505
|
* ```ts
|
|
3037
3506
|
* const values = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
3038
3507
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -3041,11 +3510,13 @@ const w = class w {
|
|
|
3041
3510
|
* console.log(values.toArray()); // [-3, -1, 0, 2, 3, 5, 6, 8]
|
|
3042
3511
|
* ```
|
|
3043
3512
|
*
|
|
3513
|
+
* ---
|
|
3514
|
+
*
|
|
3044
3515
|
* @returns A new {@link SmartIterator} containing all the values of the iterator.
|
|
3045
3516
|
*/
|
|
3046
3517
|
values() {
|
|
3047
3518
|
const t = this._elements;
|
|
3048
|
-
return new
|
|
3519
|
+
return new c(function* () {
|
|
3049
3520
|
for (const [e, n] of t)
|
|
3050
3521
|
yield n;
|
|
3051
3522
|
});
|
|
@@ -3056,6 +3527,9 @@ const w = class w {
|
|
|
3056
3527
|
*
|
|
3057
3528
|
* If the iterator is infinite, the method will never return.
|
|
3058
3529
|
*
|
|
3530
|
+
* ---
|
|
3531
|
+
*
|
|
3532
|
+
* @example
|
|
3059
3533
|
* ```ts
|
|
3060
3534
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
3061
3535
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -3063,6 +3537,8 @@ const w = class w {
|
|
|
3063
3537
|
* console.log(aggregator.toArray()); // [[-3, -1, 3, 5], [0, 2, 6, 8]]
|
|
3064
3538
|
* ```
|
|
3065
3539
|
*
|
|
3540
|
+
* ---
|
|
3541
|
+
*
|
|
3066
3542
|
* @returns An {@link Array} of arrays containing the elements of the iterator.
|
|
3067
3543
|
*/
|
|
3068
3544
|
toArray() {
|
|
@@ -3075,6 +3551,9 @@ const w = class w {
|
|
|
3075
3551
|
*
|
|
3076
3552
|
* If the iterator is infinite, the method will never return.
|
|
3077
3553
|
*
|
|
3554
|
+
* ---
|
|
3555
|
+
*
|
|
3556
|
+
* @example
|
|
3078
3557
|
* ```ts
|
|
3079
3558
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
3080
3559
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -3082,6 +3561,8 @@ const w = class w {
|
|
|
3082
3561
|
* console.log(aggregator.toMap()); // Map(2) { "odd" => [-3, -1, 3, 5], "even" => [0, 2, 6, 8] }
|
|
3083
3562
|
* ```
|
|
3084
3563
|
*
|
|
3564
|
+
* ---
|
|
3565
|
+
*
|
|
3085
3566
|
* @returns A {@link Map} containing the elements of the iterator.
|
|
3086
3567
|
*/
|
|
3087
3568
|
toMap() {
|
|
@@ -3098,6 +3579,9 @@ const w = class w {
|
|
|
3098
3579
|
*
|
|
3099
3580
|
* If the iterator is infinite, the method will never return.
|
|
3100
3581
|
*
|
|
3582
|
+
* ---
|
|
3583
|
+
*
|
|
3584
|
+
* @example
|
|
3101
3585
|
* ```ts
|
|
3102
3586
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
3103
3587
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -3105,6 +3589,8 @@ const w = class w {
|
|
|
3105
3589
|
* console.log(aggregator.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
3106
3590
|
* ```
|
|
3107
3591
|
*
|
|
3592
|
+
* ---
|
|
3593
|
+
*
|
|
3108
3594
|
* @returns An {@link Object} containing the elements of the iterator.
|
|
3109
3595
|
*/
|
|
3110
3596
|
toObject() {
|
|
@@ -3116,7 +3602,7 @@ const w = class w {
|
|
|
3116
3602
|
return t;
|
|
3117
3603
|
}
|
|
3118
3604
|
};
|
|
3119
|
-
let g =
|
|
3605
|
+
let g = m;
|
|
3120
3606
|
const Le = Function;
|
|
3121
3607
|
var pe, be;
|
|
3122
3608
|
class Ge extends (be = Le, pe = Symbol.toStringTag, be) {
|
|
@@ -3136,6 +3622,9 @@ class E {
|
|
|
3136
3622
|
/**
|
|
3137
3623
|
* Initializes a new instance of the {@link Publisher} class.
|
|
3138
3624
|
*
|
|
3625
|
+
* ---
|
|
3626
|
+
*
|
|
3627
|
+
* @example
|
|
3139
3628
|
* ```ts
|
|
3140
3629
|
* const publisher = new Publisher();
|
|
3141
3630
|
* ```
|
|
@@ -3154,6 +3643,9 @@ class E {
|
|
|
3154
3643
|
/**
|
|
3155
3644
|
* Unsubscribes all the subscribers from all the events.
|
|
3156
3645
|
*
|
|
3646
|
+
* ---
|
|
3647
|
+
*
|
|
3648
|
+
* @example
|
|
3157
3649
|
* ```ts
|
|
3158
3650
|
* publisher.subscribe("player:spawn", (evt) => { [...] });
|
|
3159
3651
|
* publisher.subscribe("player:move", (coords) => { [...] });
|
|
@@ -3174,6 +3666,9 @@ class E {
|
|
|
3174
3666
|
/**
|
|
3175
3667
|
* Publishes an event to all the subscribers.
|
|
3176
3668
|
*
|
|
3669
|
+
* ---
|
|
3670
|
+
*
|
|
3671
|
+
* @example
|
|
3177
3672
|
* ```ts
|
|
3178
3673
|
* publisher.subscribe("player:move", (coords) => { [...] });
|
|
3179
3674
|
* publisher.subscribe("player:move", ({ x, y }) => { [...] });
|
|
@@ -3182,6 +3677,8 @@ class E {
|
|
|
3182
3677
|
* publisher.publish("player:move", { x: 10, y: 20 });
|
|
3183
3678
|
* ```
|
|
3184
3679
|
*
|
|
3680
|
+
* ---
|
|
3681
|
+
*
|
|
3185
3682
|
* @template K The key of the map containing the callback signature to publish.
|
|
3186
3683
|
*
|
|
3187
3684
|
* @param event The name of the event to publish.
|
|
@@ -3196,6 +3693,9 @@ class E {
|
|
|
3196
3693
|
/**
|
|
3197
3694
|
* Subscribes a new subscriber to an event.
|
|
3198
3695
|
*
|
|
3696
|
+
* ---
|
|
3697
|
+
*
|
|
3698
|
+
* @example
|
|
3199
3699
|
* ```ts
|
|
3200
3700
|
* let unsubscribe: () => void;
|
|
3201
3701
|
* publisher.subscribe("player:death", unsubscribe);
|
|
@@ -3205,6 +3705,8 @@ class E {
|
|
|
3205
3705
|
* });
|
|
3206
3706
|
* ```
|
|
3207
3707
|
*
|
|
3708
|
+
* ---
|
|
3709
|
+
*
|
|
3208
3710
|
* @template K The key of the map containing the callback signature to subscribe.
|
|
3209
3711
|
*
|
|
3210
3712
|
* @param event The name of the event to subscribe to.
|
|
@@ -3225,6 +3727,9 @@ class E {
|
|
|
3225
3727
|
/**
|
|
3226
3728
|
* Unsubscribes a subscriber from an event.
|
|
3227
3729
|
*
|
|
3730
|
+
* ---
|
|
3731
|
+
*
|
|
3732
|
+
* @example
|
|
3228
3733
|
* ```ts
|
|
3229
3734
|
* const onPlayerMove = ({ x, y }: Point) => { [...] };
|
|
3230
3735
|
*
|
|
@@ -3232,6 +3737,8 @@ class E {
|
|
|
3232
3737
|
* publisher.subscribe("player:death", () => publisher.unsubscribe("player:move", onPlayerMove));
|
|
3233
3738
|
* ```
|
|
3234
3739
|
*
|
|
3740
|
+
* ---
|
|
3741
|
+
*
|
|
3235
3742
|
* @template K The key of the map containing the callback signature to unsubscribe.
|
|
3236
3743
|
*
|
|
3237
3744
|
* @param event The name of the event to unsubscribe from.
|
|
@@ -3247,21 +3754,11 @@ class E {
|
|
|
3247
3754
|
n.splice(s, 1);
|
|
3248
3755
|
}
|
|
3249
3756
|
}
|
|
3757
|
+
const Ke = () => {
|
|
3758
|
+
};
|
|
3250
3759
|
var ge, ve;
|
|
3251
|
-
class
|
|
3252
|
-
|
|
3253
|
-
* Initializes a new instance of the {@link SwitchableCallback} class.
|
|
3254
|
-
*
|
|
3255
|
-
* ```ts
|
|
3256
|
-
* const onPointerMove = new SwitchableCallback<(evt: PointerEvent) => void>();
|
|
3257
|
-
* ```
|
|
3258
|
-
*/
|
|
3259
|
-
constructor() {
|
|
3260
|
-
const e = () => {
|
|
3261
|
-
throw new Be(
|
|
3262
|
-
"The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
|
|
3263
|
-
);
|
|
3264
|
-
};
|
|
3760
|
+
class it extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
3761
|
+
constructor(e, n = "default") {
|
|
3265
3762
|
super();
|
|
3266
3763
|
/**
|
|
3267
3764
|
* The currently selected implementation of the callback.
|
|
@@ -3294,7 +3791,11 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3294
3791
|
*/
|
|
3295
3792
|
a(this, "_invoke");
|
|
3296
3793
|
a(this, ge, "SwitchableCallback");
|
|
3297
|
-
this.
|
|
3794
|
+
this._callbacks = /* @__PURE__ */ new Map(), this._isEnabled = !0, e ? this._callbacks.set(n, e) : (n = "", e = () => {
|
|
3795
|
+
throw new Be(
|
|
3796
|
+
"The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
|
|
3797
|
+
);
|
|
3798
|
+
}), this._key = n, this._callback = e, this._invoke = (...s) => this._callback(...s);
|
|
3298
3799
|
}
|
|
3299
3800
|
/**
|
|
3300
3801
|
* A flag indicating whether the callback is enabled or not.
|
|
@@ -3316,27 +3817,44 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3316
3817
|
*
|
|
3317
3818
|
* Also note that:
|
|
3318
3819
|
* - If any implementation has been registered yet, a {@link KeyException} will be thrown.
|
|
3820
|
+
* - If any key is given and it doesn't have any associated
|
|
3821
|
+
* implementation yet, a {@link KeyException} will be thrown.
|
|
3319
3822
|
* - If the callback is already enabled, a {@link RuntimeException} will be thrown.
|
|
3320
3823
|
*
|
|
3824
|
+
* ---
|
|
3825
|
+
*
|
|
3826
|
+
* @example
|
|
3321
3827
|
* ```ts
|
|
3322
3828
|
* window.addEventListener("pointerdown", () => { onPointerMove.enable(); });
|
|
3323
3829
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3324
3830
|
* ```
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3831
|
+
*
|
|
3832
|
+
* @param key
|
|
3833
|
+
* The key that is associated with the implementation to enable. Default is the currently selected implementation.
|
|
3834
|
+
*/
|
|
3835
|
+
enable(e) {
|
|
3836
|
+
if (e === void 0) {
|
|
3837
|
+
if (!this._key)
|
|
3838
|
+
throw new _(
|
|
3839
|
+
"The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
|
|
3840
|
+
);
|
|
3841
|
+
e = this._key;
|
|
3842
|
+
} else if (e) {
|
|
3843
|
+
if (!this._callbacks.has(e))
|
|
3844
|
+
throw new _(`The key '${e}' doesn't yet have any associated callback.`);
|
|
3845
|
+
} else throw new _("The key must be a non-empty string.");
|
|
3331
3846
|
if (this._isEnabled)
|
|
3332
3847
|
throw new y("The `SwitchableCallback` is already enabled.");
|
|
3333
|
-
this._callback = this._callbacks.get(
|
|
3848
|
+
this._callback = this._callbacks.get(e), this._isEnabled = !0;
|
|
3334
3849
|
}
|
|
3335
3850
|
/**
|
|
3336
3851
|
* Disables the callback, allowing it to be invoked without executing any implementation.
|
|
3337
3852
|
*
|
|
3338
3853
|
* If the callback is already disabled, a {@link RuntimeException} will be thrown.
|
|
3339
3854
|
*
|
|
3855
|
+
* ---
|
|
3856
|
+
*
|
|
3857
|
+
* @example
|
|
3340
3858
|
* ```ts
|
|
3341
3859
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3342
3860
|
* window.addEventListener("pointerup", () => { onPointerMove.disable(); });
|
|
@@ -3345,8 +3863,7 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3345
3863
|
disable() {
|
|
3346
3864
|
if (!this._isEnabled)
|
|
3347
3865
|
throw new y("The `SwitchableCallback` is already disabled.");
|
|
3348
|
-
this._callback =
|
|
3349
|
-
}, this._isEnabled = !1;
|
|
3866
|
+
this._callback = Ke, this._isEnabled = !1;
|
|
3350
3867
|
}
|
|
3351
3868
|
/**
|
|
3352
3869
|
* Registers a new implementation for the callback.
|
|
@@ -3355,11 +3872,16 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3355
3872
|
* - If the callback has no other implementation registered yet, this one will be selected as default.
|
|
3356
3873
|
* - If the key has already been used for another implementation, a {@link KeyException} will be thrown.
|
|
3357
3874
|
*
|
|
3875
|
+
* ---
|
|
3876
|
+
*
|
|
3877
|
+
* @example
|
|
3358
3878
|
* ```ts
|
|
3359
3879
|
* onPointerMove.register("pressed", () => { [...] });
|
|
3360
3880
|
* onPointerMove.register("released", () => { [...] });
|
|
3361
3881
|
* ```
|
|
3362
3882
|
*
|
|
3883
|
+
* ---
|
|
3884
|
+
*
|
|
3363
3885
|
* @param key The key that will be associated with the implementation.
|
|
3364
3886
|
* @param callback The implementation to register.
|
|
3365
3887
|
*/
|
|
@@ -3367,7 +3889,7 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3367
3889
|
if (this._callbacks.size === 0)
|
|
3368
3890
|
this._key = e, this._callback = n;
|
|
3369
3891
|
else if (this._callbacks.has(e))
|
|
3370
|
-
throw new
|
|
3892
|
+
throw new _(`The key '${e}' has already been used for another callback.`);
|
|
3371
3893
|
this._callbacks.set(e, n);
|
|
3372
3894
|
}
|
|
3373
3895
|
/**
|
|
@@ -3377,17 +3899,22 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3377
3899
|
* - If the key is the currently selected implementation, a {@link KeyException} will be thrown.
|
|
3378
3900
|
* - If the key has no associated implementation yet, a {@link KeyException} will be thrown.
|
|
3379
3901
|
*
|
|
3902
|
+
* ---
|
|
3903
|
+
*
|
|
3904
|
+
* @example
|
|
3380
3905
|
* ```ts
|
|
3381
3906
|
* onPointerMove.unregister("released");
|
|
3382
3907
|
* ```
|
|
3383
3908
|
*
|
|
3909
|
+
* ---
|
|
3910
|
+
*
|
|
3384
3911
|
* @param key The key that is associated with the implementation to unregister.
|
|
3385
3912
|
*/
|
|
3386
3913
|
unregister(e) {
|
|
3387
3914
|
if (this._key === e)
|
|
3388
|
-
throw new
|
|
3915
|
+
throw new _("Unable to unregister the currently selected callback.");
|
|
3389
3916
|
if (!this._callbacks.has(e))
|
|
3390
|
-
throw new
|
|
3917
|
+
throw new _(`The key '${e}' doesn't yet have any associated callback.`);
|
|
3391
3918
|
this._callbacks.delete(e);
|
|
3392
3919
|
}
|
|
3393
3920
|
/**
|
|
@@ -3395,31 +3922,41 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3395
3922
|
*
|
|
3396
3923
|
* If the key has no associated implementation yet, a {@link KeyException} will be thrown.
|
|
3397
3924
|
*
|
|
3925
|
+
* ---
|
|
3926
|
+
*
|
|
3927
|
+
* @example
|
|
3398
3928
|
* ```ts
|
|
3399
3929
|
* window.addEventListener("pointerdown", () => { onPointerMove.switch("pressed"); });
|
|
3400
3930
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3401
3931
|
* window.addEventListener("pointerup", () => { onPointerMove.switch("released"); });
|
|
3402
3932
|
* ```
|
|
3403
3933
|
*
|
|
3934
|
+
* ---
|
|
3935
|
+
*
|
|
3404
3936
|
* @param key The key that is associated with the implementation to switch to.
|
|
3405
3937
|
*/
|
|
3406
3938
|
switch(e) {
|
|
3407
3939
|
if (!this._callbacks.has(e))
|
|
3408
|
-
throw new
|
|
3940
|
+
throw new _(`The key '${e}' doesn't yet have any associated callback.`);
|
|
3409
3941
|
this._key = e, this._isEnabled && (this._callback = this._callbacks.get(e));
|
|
3410
3942
|
}
|
|
3411
3943
|
}
|
|
3412
3944
|
var ke;
|
|
3413
3945
|
ke = Symbol.toStringTag;
|
|
3414
|
-
class
|
|
3946
|
+
class ot {
|
|
3415
3947
|
/**
|
|
3416
3948
|
* Initializes a new instance of the {@link JSONStorage} class.
|
|
3417
3949
|
* It cannot be instantiated outside of a browser environment or an {@link EnvironmentException} is thrown.
|
|
3418
3950
|
*
|
|
3951
|
+
* ---
|
|
3952
|
+
*
|
|
3953
|
+
* @example
|
|
3419
3954
|
* ```ts
|
|
3420
3955
|
* const jsonStorage = new JSONStorage();
|
|
3421
3956
|
* ```
|
|
3422
3957
|
*
|
|
3958
|
+
* ---
|
|
3959
|
+
*
|
|
3423
3960
|
* @param preferPersistence
|
|
3424
3961
|
* Whether to prefer the {@link localStorage} over the {@link sessionStorage} when calling an ambivalent method.
|
|
3425
3962
|
* If omitted, it defaults to `true` to prefer the persistent storage.
|
|
@@ -3479,6 +4016,9 @@ class it {
|
|
|
3479
4016
|
/**
|
|
3480
4017
|
* Checks whether the value with the specified key exists within the default storage.
|
|
3481
4018
|
*
|
|
4019
|
+
* ---
|
|
4020
|
+
*
|
|
4021
|
+
* @example
|
|
3482
4022
|
* ```ts
|
|
3483
4023
|
* if (jsonStorage.has("key"))
|
|
3484
4024
|
* {
|
|
@@ -3486,6 +4026,8 @@ class it {
|
|
|
3486
4026
|
* }
|
|
3487
4027
|
* ```
|
|
3488
4028
|
*
|
|
4029
|
+
* ---
|
|
4030
|
+
*
|
|
3489
4031
|
* @param key The key of the value to check.
|
|
3490
4032
|
* @param persistent
|
|
3491
4033
|
* Whether to prefer the persistent {@link localStorage} over the volatile {@link sessionStorage}.
|
|
@@ -3499,6 +4041,9 @@ class it {
|
|
|
3499
4041
|
/**
|
|
3500
4042
|
* Checks whether the value with the specified key exists within the volatile {@link sessionStorage}.
|
|
3501
4043
|
*
|
|
4044
|
+
* ---
|
|
4045
|
+
*
|
|
4046
|
+
* @example
|
|
3502
4047
|
* ```ts
|
|
3503
4048
|
* if (jsonStorage.knows("key"))
|
|
3504
4049
|
* {
|
|
@@ -3506,6 +4051,8 @@ class it {
|
|
|
3506
4051
|
* }
|
|
3507
4052
|
* ```
|
|
3508
4053
|
*
|
|
4054
|
+
* ---
|
|
4055
|
+
*
|
|
3509
4056
|
* @param key The key of the value to check.
|
|
3510
4057
|
*
|
|
3511
4058
|
* @returns `true` if the key exists, `false` otherwise.
|
|
@@ -3517,6 +4064,9 @@ class it {
|
|
|
3517
4064
|
* Checks whether the value with the specified key exists looking first in the
|
|
3518
4065
|
* volatile {@link sessionStorage} and then, if not found, in the persistent {@link localStorage}.
|
|
3519
4066
|
*
|
|
4067
|
+
* ---
|
|
4068
|
+
*
|
|
4069
|
+
* @example
|
|
3520
4070
|
* ```ts
|
|
3521
4071
|
* if (jsonStorage.find("key"))
|
|
3522
4072
|
* {
|
|
@@ -3524,6 +4074,8 @@ class it {
|
|
|
3524
4074
|
* }
|
|
3525
4075
|
* ```
|
|
3526
4076
|
*
|
|
4077
|
+
* ---
|
|
4078
|
+
*
|
|
3527
4079
|
* @param key The key of the value to check.
|
|
3528
4080
|
*
|
|
3529
4081
|
* @returns `true` if the key exists, `false` otherwise.
|
|
@@ -3534,6 +4086,9 @@ class it {
|
|
|
3534
4086
|
/**
|
|
3535
4087
|
* Checks whether the value with the specified key exists within the persistent {@link localStorage}.
|
|
3536
4088
|
*
|
|
4089
|
+
* ---
|
|
4090
|
+
*
|
|
4091
|
+
* @example
|
|
3537
4092
|
* ```ts
|
|
3538
4093
|
* if (jsonStorage.exists("key"))
|
|
3539
4094
|
* {
|
|
@@ -3541,6 +4096,8 @@ class it {
|
|
|
3541
4096
|
* }
|
|
3542
4097
|
* ```
|
|
3543
4098
|
*
|
|
4099
|
+
* ---
|
|
4100
|
+
*
|
|
3544
4101
|
* @param key The key of the value to check.
|
|
3545
4102
|
*
|
|
3546
4103
|
* @returns `true` if the key exists, `false` otherwise.
|
|
@@ -3552,12 +4109,17 @@ class it {
|
|
|
3552
4109
|
* Sets the value with the specified key in the default storage.
|
|
3553
4110
|
* If the value is `undefined` or omitted, the key is removed from the storage.
|
|
3554
4111
|
*
|
|
4112
|
+
* ---
|
|
4113
|
+
*
|
|
4114
|
+
* @example
|
|
3555
4115
|
* ```ts
|
|
3556
4116
|
* jsonStorage.set("key");
|
|
3557
4117
|
* jsonStorage.set("key", value);
|
|
3558
4118
|
* jsonStorage.set("key", obj?.value);
|
|
3559
4119
|
* ```
|
|
3560
4120
|
*
|
|
4121
|
+
* ---
|
|
4122
|
+
*
|
|
3561
4123
|
* @template T The type of the value to set.
|
|
3562
4124
|
*
|
|
3563
4125
|
* @param key The key of the value to set.
|
|
@@ -3574,12 +4136,17 @@ class it {
|
|
|
3574
4136
|
* Sets the value with the specified key in the volatile {@link sessionStorage}.
|
|
3575
4137
|
* If the value is `undefined` or omitted, the key is removed from the storage.
|
|
3576
4138
|
*
|
|
4139
|
+
* ---
|
|
4140
|
+
*
|
|
4141
|
+
* @example
|
|
3577
4142
|
* ```ts
|
|
3578
4143
|
* jsonStorage.remember("key");
|
|
3579
4144
|
* jsonStorage.remember("key", value);
|
|
3580
4145
|
* jsonStorage.remember("key", obj?.value);
|
|
3581
4146
|
* ```
|
|
3582
4147
|
*
|
|
4148
|
+
* ---
|
|
4149
|
+
*
|
|
3583
4150
|
* @template T The type of the value to set.
|
|
3584
4151
|
*
|
|
3585
4152
|
* @param key The key of the value to set.
|
|
@@ -3592,12 +4159,17 @@ class it {
|
|
|
3592
4159
|
* Sets the value with the specified key in the persistent {@link localStorage}.
|
|
3593
4160
|
* If the value is `undefined` or omitted, the key is removed from the storage.
|
|
3594
4161
|
*
|
|
4162
|
+
* ---
|
|
4163
|
+
*
|
|
4164
|
+
* @example
|
|
3595
4165
|
* ```ts
|
|
3596
4166
|
* jsonStorage.write("key");
|
|
3597
4167
|
* jsonStorage.write("key", value);
|
|
3598
4168
|
* jsonStorage.write("key", obj?.value);
|
|
3599
4169
|
* ```
|
|
3600
4170
|
*
|
|
4171
|
+
* ---
|
|
4172
|
+
*
|
|
3601
4173
|
* @template T The type of the value to set.
|
|
3602
4174
|
*
|
|
3603
4175
|
* @param key The key of the value to set.
|
|
@@ -3609,10 +4181,15 @@ class it {
|
|
|
3609
4181
|
/**
|
|
3610
4182
|
* Removes the value with the specified key from the default storage.
|
|
3611
4183
|
*
|
|
4184
|
+
* ---
|
|
4185
|
+
*
|
|
4186
|
+
* @example
|
|
3612
4187
|
* ```ts
|
|
3613
4188
|
* jsonStorage.delete("key");
|
|
3614
4189
|
* ```
|
|
3615
4190
|
*
|
|
4191
|
+
* ---
|
|
4192
|
+
*
|
|
3616
4193
|
* @param key The key of the value to remove.
|
|
3617
4194
|
* @param persistent
|
|
3618
4195
|
* Whether to prefer the persistent {@link localStorage} over the volatile {@link sessionStorage}.
|
|
@@ -3624,10 +4201,15 @@ class it {
|
|
|
3624
4201
|
/**
|
|
3625
4202
|
* Removes the value with the specified key from the volatile {@link sessionStorage}.
|
|
3626
4203
|
*
|
|
4204
|
+
* ---
|
|
4205
|
+
*
|
|
4206
|
+
* @example
|
|
3627
4207
|
* ```ts
|
|
3628
4208
|
* jsonStorage.forget("key");
|
|
3629
4209
|
* ```
|
|
3630
4210
|
*
|
|
4211
|
+
* ---
|
|
4212
|
+
*
|
|
3631
4213
|
* @param key The key of the value to remove.
|
|
3632
4214
|
*/
|
|
3633
4215
|
forget(t) {
|
|
@@ -3636,10 +4218,15 @@ class it {
|
|
|
3636
4218
|
/**
|
|
3637
4219
|
* Removes the value with the specified key from the persistent {@link localStorage}.
|
|
3638
4220
|
*
|
|
4221
|
+
* ---
|
|
4222
|
+
*
|
|
4223
|
+
* @example
|
|
3639
4224
|
* ```ts
|
|
3640
4225
|
* jsonStorage.erase("key");
|
|
3641
4226
|
* ```
|
|
3642
4227
|
*
|
|
4228
|
+
* ---
|
|
4229
|
+
*
|
|
3643
4230
|
* @param key The key of the value to remove.
|
|
3644
4231
|
*/
|
|
3645
4232
|
erase(t) {
|
|
@@ -3649,10 +4236,15 @@ class it {
|
|
|
3649
4236
|
* Removes the value with the specified key from both the
|
|
3650
4237
|
* volatile {@link sessionStorage} and the persistent {@link localStorage}.
|
|
3651
4238
|
*
|
|
4239
|
+
* ---
|
|
4240
|
+
*
|
|
4241
|
+
* @example
|
|
3652
4242
|
* ```ts
|
|
3653
4243
|
* jsonStorage.clear("key");
|
|
3654
4244
|
* ```
|
|
3655
4245
|
*
|
|
4246
|
+
* ---
|
|
4247
|
+
*
|
|
3656
4248
|
* @param key The key of the value to remove.
|
|
3657
4249
|
*/
|
|
3658
4250
|
clear(t) {
|
|
@@ -3665,6 +4257,9 @@ const R = class R {
|
|
|
3665
4257
|
/**
|
|
3666
4258
|
* Initializes a new instance of the {@link SmartPromise} class.
|
|
3667
4259
|
*
|
|
4260
|
+
* ---
|
|
4261
|
+
*
|
|
4262
|
+
* @example
|
|
3668
4263
|
* ```ts
|
|
3669
4264
|
* const promise = new SmartPromise<string>((resolve, reject) =>
|
|
3670
4265
|
* {
|
|
@@ -3672,6 +4267,8 @@ const R = class R {
|
|
|
3672
4267
|
* });
|
|
3673
4268
|
* ```
|
|
3674
4269
|
*
|
|
4270
|
+
* ---
|
|
4271
|
+
*
|
|
3675
4272
|
* @param executor
|
|
3676
4273
|
* The function responsible for eventually resolving or rejecting the promise.
|
|
3677
4274
|
* Similarly to the native {@link Promise} object, it's immediately executed after the promise is created.
|
|
@@ -3712,6 +4309,9 @@ const R = class R {
|
|
|
3712
4309
|
/**
|
|
3713
4310
|
* Wraps a new {@link SmartPromise} object around an existing native {@link Promise} object.
|
|
3714
4311
|
*
|
|
4312
|
+
* ---
|
|
4313
|
+
*
|
|
4314
|
+
* @example
|
|
3715
4315
|
* ```ts
|
|
3716
4316
|
* const request = fetch("https://api.example.com/data");
|
|
3717
4317
|
* const smartRequest = SmartPromise.FromPromise(request);
|
|
@@ -3723,6 +4323,8 @@ const R = class R {
|
|
|
3723
4323
|
* console.log(smartRequest.isFulfilled); // true
|
|
3724
4324
|
* ```
|
|
3725
4325
|
*
|
|
4326
|
+
* ---
|
|
4327
|
+
*
|
|
3726
4328
|
* @param promise The promise to wrap.
|
|
3727
4329
|
*
|
|
3728
4330
|
* @returns A new {@link SmartPromise} object that wraps the provided promise.
|
|
@@ -3757,6 +4359,9 @@ const R = class R {
|
|
|
3757
4359
|
/**
|
|
3758
4360
|
* Attaches a callback that executes right after the promise is settled, regardless of the outcome.
|
|
3759
4361
|
*
|
|
4362
|
+
* ---
|
|
4363
|
+
*
|
|
4364
|
+
* @example
|
|
3760
4365
|
* ```ts
|
|
3761
4366
|
* const promise = new SmartPromise((resolve, reject) =>
|
|
3762
4367
|
* {
|
|
@@ -3771,6 +4376,8 @@ const R = class R {
|
|
|
3771
4376
|
* .finally(() => console.log("Done!")); // Always logs "Done!".
|
|
3772
4377
|
* ```
|
|
3773
4378
|
*
|
|
4379
|
+
* ---
|
|
4380
|
+
*
|
|
3774
4381
|
* @param onFinally The callback to execute when once promise is settled.
|
|
3775
4382
|
*
|
|
3776
4383
|
* @returns A new {@link Promise} that executes the callback once the promise is settled.
|
|
@@ -3781,14 +4388,19 @@ const R = class R {
|
|
|
3781
4388
|
};
|
|
3782
4389
|
let k = R;
|
|
3783
4390
|
var Te, Ee;
|
|
3784
|
-
class
|
|
4391
|
+
class He extends (Ee = k, Te = Symbol.toStringTag, Ee) {
|
|
3785
4392
|
/**
|
|
3786
4393
|
* Initializes a new instance of the {@link DeferredPromise} class.
|
|
3787
4394
|
*
|
|
4395
|
+
* ---
|
|
4396
|
+
*
|
|
4397
|
+
* @example
|
|
3788
4398
|
* ```ts
|
|
3789
4399
|
* const promise = new DeferredPromise<string, string[]>((value: string) => value.split(" "));
|
|
3790
4400
|
* ```
|
|
3791
4401
|
*
|
|
4402
|
+
* ---
|
|
4403
|
+
*
|
|
3792
4404
|
* @param onFulfilled The callback to execute once the promise is fulfilled.
|
|
3793
4405
|
* @param onRejected The callback to execute once the promise is rejected.
|
|
3794
4406
|
*/
|
|
@@ -3829,6 +4441,9 @@ class Ke extends (Ee = k, Te = Symbol.toStringTag, Ee) {
|
|
|
3829
4441
|
/**
|
|
3830
4442
|
* Watches another promise and resolves or rejects this promise when the other one is settled.
|
|
3831
4443
|
*
|
|
4444
|
+
* ---
|
|
4445
|
+
*
|
|
4446
|
+
* @example
|
|
3832
4447
|
* ```ts
|
|
3833
4448
|
* const promise = new Promise<string>((resolve) => setTimeout(() => resolve("Hello, World!"), 1_000));
|
|
3834
4449
|
* const deferred = new DeferredPromise<string, string[]>((value: string) => value.split(" "));
|
|
@@ -3837,6 +4452,8 @@ class Ke extends (Ee = k, Te = Symbol.toStringTag, Ee) {
|
|
|
3837
4452
|
* deferred.watch(promise);
|
|
3838
4453
|
* ```
|
|
3839
4454
|
*
|
|
4455
|
+
* ---
|
|
4456
|
+
*
|
|
3840
4457
|
* @param otherPromise The promise to watch.
|
|
3841
4458
|
*
|
|
3842
4459
|
* @returns The current instance of the {@link DeferredPromise} class.
|
|
@@ -3846,10 +4463,13 @@ class Ke extends (Ee = k, Te = Symbol.toStringTag, Ee) {
|
|
|
3846
4463
|
}
|
|
3847
4464
|
}
|
|
3848
4465
|
var Me, Re;
|
|
3849
|
-
class
|
|
4466
|
+
class at extends (Re = k, Me = Symbol.toStringTag, Re) {
|
|
3850
4467
|
/**
|
|
3851
4468
|
* Initializes a new instance of the {@link TimedPromise} class.
|
|
3852
4469
|
*
|
|
4470
|
+
* ---
|
|
4471
|
+
*
|
|
4472
|
+
* @example
|
|
3853
4473
|
* ```ts
|
|
3854
4474
|
* const promise = new TimedPromise<string>((resolve, reject) =>
|
|
3855
4475
|
* {
|
|
@@ -3858,6 +4478,8 @@ class ot extends (Re = k, Me = Symbol.toStringTag, Re) {
|
|
|
3858
4478
|
* }, 5_000);
|
|
3859
4479
|
* ```
|
|
3860
4480
|
*
|
|
4481
|
+
* ---
|
|
4482
|
+
*
|
|
3861
4483
|
* @param executor
|
|
3862
4484
|
* The function responsible for eventually resolving or rejecting the promise.
|
|
3863
4485
|
* Similarly to the native {@link Promise} object, it's immediately executed after the promise is created.
|
|
@@ -3876,28 +4498,28 @@ class ot extends (Re = k, Me = Symbol.toStringTag, Re) {
|
|
|
3876
4498
|
a(this, Me, "TimedPromise");
|
|
3877
4499
|
}
|
|
3878
4500
|
}
|
|
3879
|
-
var M = /* @__PURE__ */ ((i) => (i[i.Millisecond = 1] = "Millisecond", i[i.Second = 1e3] = "Second", i[i.Minute = 6e4] = "Minute", i[i.Hour = 36e5] = "Hour", i[i.Day = 864e5] = "Day", i[i.Week = 6048e5] = "Week", i[i.Month = 2592e6] = "Month", i[i.Year = 31536e6] = "Year", i))(M || {}),
|
|
3880
|
-
function
|
|
4501
|
+
var M = /* @__PURE__ */ ((i) => (i[i.Millisecond = 1] = "Millisecond", i[i.Second = 1e3] = "Second", i[i.Minute = 6e4] = "Minute", i[i.Hour = 36e5] = "Hour", i[i.Day = 864e5] = "Day", i[i.Week = 6048e5] = "Week", i[i.Month = 2592e6] = "Month", i[i.Year = 31536e6] = "Year", i))(M || {}), Qe = /* @__PURE__ */ ((i) => (i[i.Sunday = 0] = "Sunday", i[i.Monday = 1] = "Monday", i[i.Tuesday = 2] = "Tuesday", i[i.Wednesday = 3] = "Wednesday", i[i.Thursday = 4] = "Thursday", i[i.Friday = 5] = "Friday", i[i.Saturday = 6] = "Saturday", i))(Qe || {});
|
|
4502
|
+
function lt(i, t, e = 864e5) {
|
|
3881
4503
|
let n;
|
|
3882
4504
|
return i = new Date(i), t = new Date(t), i < t ? n = Math.floor : n = Math.ceil, n((t.getTime() - i.getTime()) / e);
|
|
3883
4505
|
}
|
|
3884
|
-
function
|
|
4506
|
+
function ct(i, t, e = 864e5) {
|
|
3885
4507
|
if (i >= t)
|
|
3886
|
-
throw new
|
|
3887
|
-
return new
|
|
4508
|
+
throw new b("The end date must be greater than the start date.");
|
|
4509
|
+
return new c(function* () {
|
|
3888
4510
|
const n = new Date(t).getTime();
|
|
3889
4511
|
let s = new Date(i).getTime();
|
|
3890
4512
|
for (; s < n; )
|
|
3891
4513
|
yield new Date(s), s += e;
|
|
3892
4514
|
});
|
|
3893
4515
|
}
|
|
3894
|
-
function
|
|
4516
|
+
function Ve(i, t = 864e5) {
|
|
3895
4517
|
if (t <= 1)
|
|
3896
|
-
throw new
|
|
4518
|
+
throw new b(
|
|
3897
4519
|
"Rounding a timestamp by milliseconds or less makes no sense.Use the timestamp value directly instead."
|
|
3898
4520
|
);
|
|
3899
4521
|
if (t > 864e5)
|
|
3900
|
-
throw new
|
|
4522
|
+
throw new b(
|
|
3901
4523
|
"Rounding by more than a day leads to unexpected results. Consider using other methods to round dates by weeks, months or years."
|
|
3902
4524
|
);
|
|
3903
4525
|
return i = new Date(i), new Date(Math.floor(i.getTime() / t) * t);
|
|
@@ -3905,7 +4527,7 @@ function Qe(i, t = 864e5) {
|
|
|
3905
4527
|
function ut(i, t = 0) {
|
|
3906
4528
|
i = new Date(i);
|
|
3907
4529
|
const e = 7 - t, n = (i.getUTCDay() + e) % 7, s = i.getTime() - 864e5 * n;
|
|
3908
|
-
return
|
|
4530
|
+
return Ve(new Date(s));
|
|
3909
4531
|
}
|
|
3910
4532
|
var Fe;
|
|
3911
4533
|
Fe = Symbol.toStringTag;
|
|
@@ -3913,10 +4535,15 @@ class qe {
|
|
|
3913
4535
|
/**
|
|
3914
4536
|
* Initializes a new instance of the {@link GameLoop} class.
|
|
3915
4537
|
*
|
|
4538
|
+
* ---
|
|
4539
|
+
*
|
|
4540
|
+
* @example
|
|
3916
4541
|
* ```ts
|
|
3917
4542
|
* const loop = new GameLoop((elapsedTime: number) => { [...] });
|
|
3918
4543
|
* ```
|
|
3919
4544
|
*
|
|
4545
|
+
* ---
|
|
4546
|
+
*
|
|
3920
4547
|
* @param callback The function that will be executed at each iteration of the game loop.
|
|
3921
4548
|
* @param msIfNotBrowser
|
|
3922
4549
|
* The interval in milliseconds that will be used if the current environment isn't a browser. Default is `40`.
|
|
@@ -3996,11 +4623,16 @@ class qe {
|
|
|
3996
4623
|
*
|
|
3997
4624
|
* If the game loop is already running, a {@link RuntimeException} will be thrown.
|
|
3998
4625
|
*
|
|
4626
|
+
* ---
|
|
4627
|
+
*
|
|
4628
|
+
* @example
|
|
3999
4629
|
* ```ts
|
|
4000
4630
|
* loop.onStart(() => { [...] }); // This callback will be executed.
|
|
4001
4631
|
* loop.start();
|
|
4002
4632
|
* ```
|
|
4003
4633
|
*
|
|
4634
|
+
* ---
|
|
4635
|
+
*
|
|
4004
4636
|
* @param elapsedTime The elapsed time to set as default when the game loop starts. Default is `0`.
|
|
4005
4637
|
*/
|
|
4006
4638
|
start(t = 0) {
|
|
@@ -4013,6 +4645,9 @@ class qe {
|
|
|
4013
4645
|
*
|
|
4014
4646
|
* If the game loop hasn't yet started, a {@link RuntimeException} will be thrown.
|
|
4015
4647
|
*
|
|
4648
|
+
* ---
|
|
4649
|
+
*
|
|
4650
|
+
* @example
|
|
4016
4651
|
* ```ts
|
|
4017
4652
|
* loop.onStop(() => { [...] }); // This callback will be executed.
|
|
4018
4653
|
* loop.stop();
|
|
@@ -4028,10 +4663,15 @@ class qe {
|
|
|
4028
4663
|
/**
|
|
4029
4664
|
* Subscribes to the `start` event of the game loop.
|
|
4030
4665
|
*
|
|
4666
|
+
* ---
|
|
4667
|
+
*
|
|
4668
|
+
* @example
|
|
4031
4669
|
* ```ts
|
|
4032
4670
|
* loop.onStart(() => { console.log("The game loop has started."); });
|
|
4033
4671
|
* ```
|
|
4034
4672
|
*
|
|
4673
|
+
* ---
|
|
4674
|
+
*
|
|
4035
4675
|
* @param callback The function that will be executed when the game loop starts.
|
|
4036
4676
|
*
|
|
4037
4677
|
* @returns A function that can be used to unsubscribe from the event.
|
|
@@ -4042,10 +4682,15 @@ class qe {
|
|
|
4042
4682
|
/**
|
|
4043
4683
|
* Subscribes to the `stop` event of the game loop.
|
|
4044
4684
|
*
|
|
4685
|
+
* ---
|
|
4686
|
+
*
|
|
4687
|
+
* @example
|
|
4045
4688
|
* ```ts
|
|
4046
4689
|
* loop.onStop(() => { console.log("The game loop has stopped."); });
|
|
4047
4690
|
* ```
|
|
4048
4691
|
*
|
|
4692
|
+
* ---
|
|
4693
|
+
*
|
|
4049
4694
|
* @param callback The function that will be executed when the game loop stops.
|
|
4050
4695
|
*
|
|
4051
4696
|
* @returns A function that can be used to unsubscribe from the event.
|
|
@@ -4055,14 +4700,19 @@ class qe {
|
|
|
4055
4700
|
}
|
|
4056
4701
|
}
|
|
4057
4702
|
var Pe, Ce;
|
|
4058
|
-
class
|
|
4703
|
+
class ht extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
4059
4704
|
/**
|
|
4060
4705
|
* Initializes a new instance of the {@link Clock} class.
|
|
4061
4706
|
*
|
|
4707
|
+
* ---
|
|
4708
|
+
*
|
|
4709
|
+
* @example
|
|
4062
4710
|
* ```ts
|
|
4063
4711
|
* const clock = new Clock();
|
|
4064
4712
|
* ```
|
|
4065
4713
|
*
|
|
4714
|
+
* ---
|
|
4715
|
+
*
|
|
4066
4716
|
* @param msIfNotBrowser
|
|
4067
4717
|
* The interval in milliseconds at which the clock will tick if the environment is not a browser.
|
|
4068
4718
|
* `TimeUnit.Second` by default.
|
|
@@ -4081,11 +4731,16 @@ class ct extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
|
4081
4731
|
*
|
|
4082
4732
|
* If the clock is already running, a {@link RuntimeException} will be thrown.
|
|
4083
4733
|
*
|
|
4734
|
+
* ---
|
|
4735
|
+
*
|
|
4736
|
+
* @example
|
|
4084
4737
|
* ```ts
|
|
4085
4738
|
* clock.onStart(() => { [...] }); // This callback will be executed.
|
|
4086
4739
|
* clock.start();
|
|
4087
4740
|
* ```
|
|
4088
4741
|
*
|
|
4742
|
+
* ---
|
|
4743
|
+
*
|
|
4089
4744
|
* @param elapsedTime The elapsed time to set as default when the clock starts. Default is `0`.
|
|
4090
4745
|
*/
|
|
4091
4746
|
start(e = 0) {
|
|
@@ -4098,6 +4753,9 @@ class ct extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
|
4098
4753
|
*
|
|
4099
4754
|
* If the clock hasn't yet started, a {@link RuntimeException} will be thrown.
|
|
4100
4755
|
*
|
|
4756
|
+
* ---
|
|
4757
|
+
*
|
|
4758
|
+
* @example
|
|
4101
4759
|
* ```ts
|
|
4102
4760
|
* clock.onStop(() => { [...] }); // This callback will be executed.
|
|
4103
4761
|
* clock.stop();
|
|
@@ -4113,11 +4771,16 @@ class ct extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
|
4113
4771
|
/**
|
|
4114
4772
|
* Subscribes to the `tick` event of the clock.
|
|
4115
4773
|
*
|
|
4774
|
+
* ---
|
|
4775
|
+
*
|
|
4776
|
+
* @example
|
|
4116
4777
|
* ```ts
|
|
4117
4778
|
* clock.onTick((elapsedTime) => { [...] }); // This callback will be executed.
|
|
4118
4779
|
* clock.start();
|
|
4119
4780
|
* ```
|
|
4120
4781
|
*
|
|
4782
|
+
* ---
|
|
4783
|
+
*
|
|
4121
4784
|
* @param callback The callback that will be executed when the clock ticks.
|
|
4122
4785
|
* @param tickStep
|
|
4123
4786
|
* The minimum time in milliseconds that must pass from the previous execution of the callback to the next one.
|
|
@@ -4131,7 +4794,7 @@ class ct extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
|
4131
4794
|
*/
|
|
4132
4795
|
onTick(e, n = 0) {
|
|
4133
4796
|
if (n < 0)
|
|
4134
|
-
throw new
|
|
4797
|
+
throw new b("The tick step must be a non-negative number.");
|
|
4135
4798
|
if (n === 0)
|
|
4136
4799
|
return this._publisher.subscribe("tick", e);
|
|
4137
4800
|
let s = 0;
|
|
@@ -4141,14 +4804,19 @@ class ct extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
|
4141
4804
|
}
|
|
4142
4805
|
}
|
|
4143
4806
|
var je, Ie;
|
|
4144
|
-
class
|
|
4807
|
+
class ft extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
4145
4808
|
/**
|
|
4146
4809
|
* Initializes a new instance of the {@link Countdown} class.
|
|
4147
4810
|
*
|
|
4811
|
+
* ---
|
|
4812
|
+
*
|
|
4813
|
+
* @example
|
|
4148
4814
|
* ```ts
|
|
4149
4815
|
* const countdown = new Countdown(10_000);
|
|
4150
4816
|
* ```
|
|
4151
4817
|
*
|
|
4818
|
+
* ---
|
|
4819
|
+
*
|
|
4152
4820
|
* @param duration
|
|
4153
4821
|
* The total duration of the countdown in milliseconds.
|
|
4154
4822
|
*
|
|
@@ -4214,11 +4882,16 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4214
4882
|
*
|
|
4215
4883
|
* If the countdown is already running, a {@link RuntimeException} will be thrown.
|
|
4216
4884
|
*
|
|
4885
|
+
* ---
|
|
4886
|
+
*
|
|
4887
|
+
* @example
|
|
4217
4888
|
* ```ts
|
|
4218
4889
|
* countdown.onStart(() => { [...] }); // This callback will be executed.
|
|
4219
4890
|
* countdown.start();
|
|
4220
4891
|
* ```
|
|
4221
4892
|
*
|
|
4893
|
+
* ---
|
|
4894
|
+
*
|
|
4222
4895
|
* @param remainingTime
|
|
4223
4896
|
* The remaining time to set as default when the countdown starts.
|
|
4224
4897
|
* Default is the {@link Countdown.duration} itself.
|
|
@@ -4230,18 +4903,23 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4230
4903
|
throw new y("The countdown had already stopped or hadn't yet started.");
|
|
4231
4904
|
if (this._deferrer)
|
|
4232
4905
|
throw new x();
|
|
4233
|
-
return this._deferrer = new
|
|
4906
|
+
return this._deferrer = new He(), super.start(this.duration - e), this._publisher.publish("start"), this._deferrer;
|
|
4234
4907
|
}
|
|
4235
4908
|
/**
|
|
4236
4909
|
* Stops the execution of the countdown.
|
|
4237
4910
|
*
|
|
4238
4911
|
* If the countdown hasn't yet started, a {@link RuntimeException} will be thrown.
|
|
4239
4912
|
*
|
|
4913
|
+
* ---
|
|
4914
|
+
*
|
|
4915
|
+
* @example
|
|
4240
4916
|
* ```ts
|
|
4241
4917
|
* countdown.onStop(() => { [...] }); // This callback will be executed.
|
|
4242
4918
|
* countdown.stop();
|
|
4243
4919
|
* ```
|
|
4244
4920
|
*
|
|
4921
|
+
* ---
|
|
4922
|
+
*
|
|
4245
4923
|
* @param reason
|
|
4246
4924
|
* The reason why the countdown has stopped.
|
|
4247
4925
|
*
|
|
@@ -4254,11 +4932,16 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4254
4932
|
/**
|
|
4255
4933
|
* Subscribes to the `expire` event of the countdown.
|
|
4256
4934
|
*
|
|
4935
|
+
* ---
|
|
4936
|
+
*
|
|
4937
|
+
* @example
|
|
4257
4938
|
* ```ts
|
|
4258
4939
|
* countdown.onExpire(() => { [...] }); // This callback will be executed once the countdown has expired.
|
|
4259
4940
|
* countdown.start();
|
|
4260
4941
|
* ```
|
|
4261
4942
|
*
|
|
4943
|
+
* ---
|
|
4944
|
+
*
|
|
4262
4945
|
* @param callback The callback that will be executed when the countdown expires.
|
|
4263
4946
|
*
|
|
4264
4947
|
* @returns A function that can be used to unsubscribe from the event.
|
|
@@ -4269,11 +4952,16 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4269
4952
|
/**
|
|
4270
4953
|
* Subscribes to the `tick` event of the countdown.
|
|
4271
4954
|
*
|
|
4955
|
+
* ---
|
|
4956
|
+
*
|
|
4957
|
+
* @example
|
|
4272
4958
|
* ```ts
|
|
4273
4959
|
* countdown.onTick((remainingTime) => { [...] }); // This callback will be executed.
|
|
4274
4960
|
* countdown.start();
|
|
4275
4961
|
* ```
|
|
4276
4962
|
*
|
|
4963
|
+
* ---
|
|
4964
|
+
*
|
|
4277
4965
|
* @param callback The callback that will be executed when the countdown ticks.
|
|
4278
4966
|
* @param tickStep
|
|
4279
4967
|
* The minimum time in milliseconds that must pass from the previous execution of the callback to the next one.
|
|
@@ -4287,7 +4975,7 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4287
4975
|
*/
|
|
4288
4976
|
onTick(e, n = 0) {
|
|
4289
4977
|
if (n < 0)
|
|
4290
|
-
throw new
|
|
4978
|
+
throw new b("The tick step must be a non-negative number.");
|
|
4291
4979
|
if (n === 0)
|
|
4292
4980
|
return this._publisher.subscribe("tick", e);
|
|
4293
4981
|
let s = this.remainingTime;
|
|
@@ -4298,7 +4986,7 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4298
4986
|
}
|
|
4299
4987
|
var Ae;
|
|
4300
4988
|
Ae = Symbol.toStringTag;
|
|
4301
|
-
class
|
|
4989
|
+
class dt {
|
|
4302
4990
|
constructor() {
|
|
4303
4991
|
a(this, Ae, "Curve");
|
|
4304
4992
|
}
|
|
@@ -4306,6 +4994,9 @@ class ft {
|
|
|
4306
4994
|
* Generates a given number of values following a linear curve.
|
|
4307
4995
|
* The values are equally spaced and normalized between 0 and 1.
|
|
4308
4996
|
*
|
|
4997
|
+
* ---
|
|
4998
|
+
*
|
|
4999
|
+
* @example
|
|
4309
5000
|
* ```ts
|
|
4310
5001
|
* for (const value of Curve.Linear(5))
|
|
4311
5002
|
* {
|
|
@@ -4313,13 +5004,15 @@ class ft {
|
|
|
4313
5004
|
* }
|
|
4314
5005
|
* ```
|
|
4315
5006
|
*
|
|
5007
|
+
* ---
|
|
5008
|
+
*
|
|
4316
5009
|
* @param values The number of values to generate.
|
|
4317
5010
|
*
|
|
4318
5011
|
* @returns A {@link SmartIterator} object that generates the values following a linear curve.
|
|
4319
5012
|
*/
|
|
4320
5013
|
static Linear(t) {
|
|
4321
5014
|
const e = t - 1;
|
|
4322
|
-
return new
|
|
5015
|
+
return new c(function* () {
|
|
4323
5016
|
for (let n = 0; n < t; n += 1)
|
|
4324
5017
|
yield n / e;
|
|
4325
5018
|
});
|
|
@@ -4328,6 +5021,9 @@ class ft {
|
|
|
4328
5021
|
* Generates a given number of values following an exponential curve.
|
|
4329
5022
|
* The values are equally spaced and normalized between 0 and 1.
|
|
4330
5023
|
*
|
|
5024
|
+
* ---
|
|
5025
|
+
*
|
|
5026
|
+
* @example
|
|
4331
5027
|
* ```ts
|
|
4332
5028
|
* for (const value of Curve.Exponential(6))
|
|
4333
5029
|
* {
|
|
@@ -4335,6 +5031,8 @@ class ft {
|
|
|
4335
5031
|
* }
|
|
4336
5032
|
* ```
|
|
4337
5033
|
*
|
|
5034
|
+
* ---
|
|
5035
|
+
*
|
|
4338
5036
|
* @param values The number of values to generate.
|
|
4339
5037
|
* @param base
|
|
4340
5038
|
* The base of the exponential curve. Default is `2`.
|
|
@@ -4351,7 +5049,7 @@ class ft {
|
|
|
4351
5049
|
if (e < 0)
|
|
4352
5050
|
throw new d("The base of the exponential curve cannot be negative.");
|
|
4353
5051
|
const n = t - 1;
|
|
4354
|
-
return new
|
|
5052
|
+
return new c(function* () {
|
|
4355
5053
|
for (let s = 0; s < t; s += 1)
|
|
4356
5054
|
yield Math.pow(s / n, e);
|
|
4357
5055
|
});
|
|
@@ -4366,6 +5064,9 @@ const F = class F {
|
|
|
4366
5064
|
/**
|
|
4367
5065
|
* Generates a random boolean value.
|
|
4368
5066
|
*
|
|
5067
|
+
* ---
|
|
5068
|
+
*
|
|
5069
|
+
* @example
|
|
4369
5070
|
* ```ts
|
|
4370
5071
|
* if (Random.Boolean())
|
|
4371
5072
|
* {
|
|
@@ -4373,6 +5074,8 @@ const F = class F {
|
|
|
4373
5074
|
* }
|
|
4374
5075
|
* ```
|
|
4375
5076
|
*
|
|
5077
|
+
* ---
|
|
5078
|
+
*
|
|
4376
5079
|
* @param ratio
|
|
4377
5080
|
* The probability of generating `true`.
|
|
4378
5081
|
*
|
|
@@ -4423,29 +5126,29 @@ const F = class F {
|
|
|
4423
5126
|
}
|
|
4424
5127
|
};
|
|
4425
5128
|
let j = F;
|
|
4426
|
-
function
|
|
5129
|
+
function wt(i) {
|
|
4427
5130
|
return new Promise((t) => setTimeout(t, i));
|
|
4428
5131
|
}
|
|
4429
5132
|
function mt() {
|
|
4430
5133
|
return new Promise((i) => requestAnimationFrame(() => i()));
|
|
4431
5134
|
}
|
|
4432
|
-
function
|
|
5135
|
+
function yt() {
|
|
4433
5136
|
return new Promise((i) => setTimeout(i));
|
|
4434
5137
|
}
|
|
4435
|
-
function
|
|
5138
|
+
function _t(i, t = "text/javascript") {
|
|
4436
5139
|
return new Promise((e, n) => {
|
|
4437
5140
|
const s = document.createElement("script");
|
|
4438
5141
|
s.async = !0, s.defer = !0, s.src = i, s.type = t, s.onload = (r) => e(), s.onerror = (r) => n(r), document.body.appendChild(s);
|
|
4439
5142
|
});
|
|
4440
5143
|
}
|
|
4441
|
-
function
|
|
4442
|
-
return new
|
|
5144
|
+
function pt(...i) {
|
|
5145
|
+
return new c(function* () {
|
|
4443
5146
|
for (const t of i)
|
|
4444
5147
|
for (const e of t)
|
|
4445
5148
|
yield e;
|
|
4446
5149
|
});
|
|
4447
5150
|
}
|
|
4448
|
-
function
|
|
5151
|
+
function bt(i) {
|
|
4449
5152
|
if (i instanceof Array)
|
|
4450
5153
|
return i.length;
|
|
4451
5154
|
let t = 0;
|
|
@@ -4453,27 +5156,27 @@ function pt(i) {
|
|
|
4453
5156
|
t += 1;
|
|
4454
5157
|
return t;
|
|
4455
5158
|
}
|
|
4456
|
-
function
|
|
4457
|
-
return new
|
|
5159
|
+
function xt(i) {
|
|
5160
|
+
return new c(function* () {
|
|
4458
5161
|
let t = 0;
|
|
4459
5162
|
for (const e of i)
|
|
4460
5163
|
yield [t, e], t += 1;
|
|
4461
5164
|
});
|
|
4462
5165
|
}
|
|
4463
|
-
function
|
|
5166
|
+
function gt(i, t, e = 1) {
|
|
4464
5167
|
if (e <= 0)
|
|
4465
|
-
throw new
|
|
5168
|
+
throw new b(
|
|
4466
5169
|
"Step must be always a positive number, even when generating numbers in reverse order."
|
|
4467
5170
|
);
|
|
4468
|
-
return t === void 0 && (t = i, i = 0), i > t ? new
|
|
5171
|
+
return t === void 0 && (t = i, i = 0), i > t ? new c(function* () {
|
|
4469
5172
|
for (let n = i; n > t; n -= e)
|
|
4470
5173
|
yield n;
|
|
4471
|
-
}) : new
|
|
5174
|
+
}) : new c(function* () {
|
|
4472
5175
|
for (let n = i; n < t; n += e)
|
|
4473
5176
|
yield n;
|
|
4474
5177
|
});
|
|
4475
5178
|
}
|
|
4476
|
-
function
|
|
5179
|
+
function vt(i) {
|
|
4477
5180
|
const t = Array.from(i);
|
|
4478
5181
|
for (let e = t.length - 1; e > 0; e -= 1) {
|
|
4479
5182
|
const n = Math.floor(Math.random() * (e + 1));
|
|
@@ -4481,16 +5184,16 @@ function gt(i) {
|
|
|
4481
5184
|
}
|
|
4482
5185
|
return t;
|
|
4483
5186
|
}
|
|
4484
|
-
function
|
|
4485
|
-
return new
|
|
5187
|
+
function kt(i) {
|
|
5188
|
+
return new c(function* () {
|
|
4486
5189
|
const t = /* @__PURE__ */ new Set();
|
|
4487
5190
|
for (const e of i)
|
|
4488
5191
|
t.has(e) || (t.add(e), yield e);
|
|
4489
5192
|
});
|
|
4490
5193
|
}
|
|
4491
|
-
function
|
|
5194
|
+
function Xe(i, t) {
|
|
4492
5195
|
const e = i[Symbol.iterator](), n = t[Symbol.iterator]();
|
|
4493
|
-
return new
|
|
5196
|
+
return new c(function* () {
|
|
4494
5197
|
for (; ; ) {
|
|
4495
5198
|
const s = e.next(), r = n.next();
|
|
4496
5199
|
if (s.done || r.done)
|
|
@@ -4499,7 +5202,7 @@ function Ve(i, t) {
|
|
|
4499
5202
|
}
|
|
4500
5203
|
});
|
|
4501
5204
|
}
|
|
4502
|
-
function
|
|
5205
|
+
function St(i, t) {
|
|
4503
5206
|
if (t === void 0) {
|
|
4504
5207
|
let r = 0, o = 0;
|
|
4505
5208
|
for (const l of i)
|
|
@@ -4509,7 +5212,7 @@ function kt(i, t) {
|
|
|
4509
5212
|
return r / o;
|
|
4510
5213
|
}
|
|
4511
5214
|
let e = 0, n = 0, s = 0;
|
|
4512
|
-
for (const [r, o] of
|
|
5215
|
+
for (const [r, o] of Xe(i, t)) {
|
|
4513
5216
|
if (o <= 0)
|
|
4514
5217
|
throw new d(`The weight for the value #${s} must be greater than zero.`);
|
|
4515
5218
|
e += r * o, n += o, s += 1;
|
|
@@ -4520,7 +5223,7 @@ function kt(i, t) {
|
|
|
4520
5223
|
throw new d("The sum of weights must be greater than zero.");
|
|
4521
5224
|
return e / n;
|
|
4522
5225
|
}
|
|
4523
|
-
function
|
|
5226
|
+
function Tt(i) {
|
|
4524
5227
|
let t = 0;
|
|
4525
5228
|
for (let e = 0; e < i.length; e += 1) {
|
|
4526
5229
|
const n = i.charCodeAt(e);
|
|
@@ -4528,74 +5231,74 @@ function St(i) {
|
|
|
4528
5231
|
}
|
|
4529
5232
|
return t;
|
|
4530
5233
|
}
|
|
4531
|
-
function
|
|
5234
|
+
function Et(i) {
|
|
4532
5235
|
let t = 0;
|
|
4533
5236
|
for (const e of i)
|
|
4534
5237
|
t += e;
|
|
4535
5238
|
return t;
|
|
4536
5239
|
}
|
|
4537
|
-
function
|
|
5240
|
+
function Mt(i) {
|
|
4538
5241
|
return `${i.charAt(0).toUpperCase()}${i.slice(1)}`;
|
|
4539
5242
|
}
|
|
4540
|
-
const
|
|
5243
|
+
const Rt = "2.0.1";
|
|
4541
5244
|
export {
|
|
4542
5245
|
T as AggregatedAsyncIterator,
|
|
4543
5246
|
g as AggregatedIterator,
|
|
4544
5247
|
Ge as CallableObject,
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
5248
|
+
ht as Clock,
|
|
5249
|
+
ft as Countdown,
|
|
5250
|
+
dt as Curve,
|
|
5251
|
+
He as DeferredPromise,
|
|
4549
5252
|
Je as EnvironmentException,
|
|
4550
|
-
|
|
5253
|
+
u as Exception,
|
|
4551
5254
|
x as FatalErrorException,
|
|
4552
5255
|
$e as FileException,
|
|
4553
|
-
|
|
4554
|
-
|
|
5256
|
+
et as FileExistsException,
|
|
5257
|
+
tt as FileNotFoundException,
|
|
4555
5258
|
qe as GameLoop,
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
5259
|
+
ot as JSONStorage,
|
|
5260
|
+
_ as KeyException,
|
|
5261
|
+
nt as NetworkException,
|
|
4559
5262
|
Be as NotImplementedException,
|
|
4560
|
-
|
|
5263
|
+
st as PermissionException,
|
|
4561
5264
|
E as Publisher,
|
|
4562
5265
|
j as Random,
|
|
4563
|
-
|
|
5266
|
+
b as RangeException,
|
|
4564
5267
|
h as ReducedIterator,
|
|
4565
5268
|
C as ReferenceException,
|
|
4566
5269
|
y as RuntimeException,
|
|
4567
5270
|
f as SmartAsyncIterator,
|
|
4568
|
-
|
|
5271
|
+
c as SmartIterator,
|
|
4569
5272
|
k as SmartPromise,
|
|
4570
|
-
|
|
5273
|
+
it as SwitchableCallback,
|
|
4571
5274
|
M as TimeUnit,
|
|
4572
|
-
|
|
5275
|
+
at as TimedPromise,
|
|
4573
5276
|
Ye as TimeoutException,
|
|
4574
|
-
|
|
4575
|
-
|
|
5277
|
+
rt as TypeException,
|
|
5278
|
+
Rt as VERSION,
|
|
4576
5279
|
d as ValueException,
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
5280
|
+
Qe as WeekDay,
|
|
5281
|
+
St as average,
|
|
5282
|
+
Mt as capitalize,
|
|
5283
|
+
pt as chain,
|
|
5284
|
+
bt as count,
|
|
5285
|
+
lt as dateDifference,
|
|
5286
|
+
ct as dateRange,
|
|
5287
|
+
Ve as dateRound,
|
|
5288
|
+
wt as delay,
|
|
5289
|
+
xt as enumerate,
|
|
4587
5290
|
ut as getWeek,
|
|
4588
|
-
|
|
5291
|
+
Tt as hash,
|
|
4589
5292
|
Oe as isBrowser,
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
5293
|
+
We as isNode,
|
|
5294
|
+
Ue as isWorker,
|
|
5295
|
+
_t as loadScript,
|
|
4593
5296
|
mt as nextAnimationFrame,
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
5297
|
+
gt as range,
|
|
5298
|
+
vt as shuffle,
|
|
5299
|
+
Et as sum,
|
|
5300
|
+
kt as unique,
|
|
5301
|
+
yt as yieldToEventLoop,
|
|
5302
|
+
Xe as zip
|
|
4600
5303
|
};
|
|
4601
5304
|
//# sourceMappingURL=core.js.map
|