@byloth/core 2.0.0 → 2.0.2
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/README.md +1 -0
- package/dist/core.js +900 -187
- 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 +13 -10
- package/src/core/types.ts +43 -10
- package/src/index.ts +3 -2
- package/src/models/aggregators/aggregated-async-iterator.ts +161 -1
- package/src/models/aggregators/aggregated-iterator.ts +146 -1
- package/src/models/aggregators/reduced-iterator.ts +148 -8
- package/src/models/aggregators/types.ts +35 -0
- package/src/models/callbacks/callable-object.ts +7 -0
- package/src/models/callbacks/publisher.ts +33 -8
- package/src/models/callbacks/switchable-callback.ts +102 -21
- package/src/models/callbacks/types.ts +32 -0
- package/src/models/exceptions/core.ts +29 -0
- package/src/models/exceptions/index.ts +105 -1
- package/src/models/iterators/smart-async-iterator.ts +145 -0
- package/src/models/iterators/smart-iterator.ts +130 -0
- package/src/models/iterators/types.ts +79 -1
- package/src/models/json/json-storage.ts +123 -0
- package/src/models/json/types.ts +1 -1
- package/src/models/promises/deferred-promise.ts +15 -0
- package/src/models/promises/smart-promise.ts +45 -0
- package/src/models/promises/timed-promise.ts +10 -0
- package/src/models/promises/types.ts +30 -0
- package/src/models/timers/clock.ts +21 -0
- package/src/models/timers/countdown.ts +30 -0
- package/src/models/timers/game-loop.ts +26 -0
- package/src/models/types.ts +1 -1
- package/src/utils/async.ts +15 -0
- package/src/utils/curve.ts +11 -1
- package/src/utils/date.ts +36 -6
- package/src/utils/dom.ts +5 -0
- package/src/utils/iterator.ts +40 -0
- package/src/utils/math.ts +15 -0
- package/src/utils/random.ts +34 -0
- package/src/utils/string.ts +5 -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")
|
|
@@ -1057,14 +1240,16 @@ const _ = class _ {
|
|
|
1057
1240
|
*
|
|
1058
1241
|
* console.log(results.toObject()); // { even: [0, 2, 6, 8] }
|
|
1059
1242
|
* ```
|
|
1060
|
-
*
|
|
1243
|
+
*
|
|
1244
|
+
* ---
|
|
1245
|
+
*
|
|
1061
1246
|
* @param count The number of elements to drop.
|
|
1062
1247
|
*
|
|
1063
1248
|
* @returns A new {@link ReducedIterator} containing the remaining elements.
|
|
1064
1249
|
*/
|
|
1065
1250
|
drop(t) {
|
|
1066
1251
|
const e = this._elements.enumerate();
|
|
1067
|
-
return new
|
|
1252
|
+
return new p(function* () {
|
|
1068
1253
|
for (const [n, [s, r]] of e)
|
|
1069
1254
|
n >= t && (yield [s, r]);
|
|
1070
1255
|
});
|
|
@@ -1084,6 +1269,9 @@ const _ = class _ {
|
|
|
1084
1269
|
* Only the taken elements will be consumed from the original reduced iterator.
|
|
1085
1270
|
* The rest of the original reduced iterator will be available for further consumption.
|
|
1086
1271
|
*
|
|
1272
|
+
* ---
|
|
1273
|
+
*
|
|
1274
|
+
* @example
|
|
1087
1275
|
* ```ts
|
|
1088
1276
|
* const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1089
1277
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1095,13 +1283,15 @@ const _ = class _ {
|
|
|
1095
1283
|
* console.log(reduced.toObject()); // { even: [0, 2, 6, 8] }
|
|
1096
1284
|
* ```
|
|
1097
1285
|
*
|
|
1098
|
-
*
|
|
1286
|
+
* ---
|
|
1287
|
+
*
|
|
1288
|
+
* @param limit The number of elements to take.
|
|
1099
1289
|
*
|
|
1100
1290
|
* @returns A new {@link ReducedIterator} containing the taken elements.
|
|
1101
1291
|
*/
|
|
1102
1292
|
take(t) {
|
|
1103
1293
|
const e = this._elements.enumerate();
|
|
1104
|
-
return new
|
|
1294
|
+
return new p(function* () {
|
|
1105
1295
|
for (const [n, [s, r]] of e) {
|
|
1106
1296
|
if (n >= t)
|
|
1107
1297
|
break;
|
|
@@ -1125,6 +1315,9 @@ const _ = class _ {
|
|
|
1125
1315
|
* This means that the original iterator won't be consumed until the
|
|
1126
1316
|
* new one is and that consuming one of them will consume the other as well.
|
|
1127
1317
|
*
|
|
1318
|
+
* ---
|
|
1319
|
+
*
|
|
1320
|
+
* @example
|
|
1128
1321
|
* ```ts
|
|
1129
1322
|
* const results = new ReducedIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1130
1323
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1134,6 +1327,8 @@ const _ = class _ {
|
|
|
1134
1327
|
* console.log(results.toObject()); // [[0, 4], [1, 16]]
|
|
1135
1328
|
* ```
|
|
1136
1329
|
*
|
|
1330
|
+
* ---
|
|
1331
|
+
*
|
|
1137
1332
|
* @returns A new {@link ReducedIterator} object containing the enumerated elements.
|
|
1138
1333
|
*/
|
|
1139
1334
|
enumerate() {
|
|
@@ -1150,6 +1345,9 @@ const _ = class _ {
|
|
|
1150
1345
|
* This means that the original iterator won't be consumed until the
|
|
1151
1346
|
* new one is and that consuming one of them will consume the other as well.
|
|
1152
1347
|
*
|
|
1348
|
+
* ---
|
|
1349
|
+
*
|
|
1350
|
+
* @example
|
|
1153
1351
|
* ```ts
|
|
1154
1352
|
* const results = new ReducedIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 1, 5, 6, 8, 7, 2])
|
|
1155
1353
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1163,7 +1361,7 @@ const _ = class _ {
|
|
|
1163
1361
|
*/
|
|
1164
1362
|
unique() {
|
|
1165
1363
|
const t = this._elements;
|
|
1166
|
-
return new
|
|
1364
|
+
return new p(function* () {
|
|
1167
1365
|
const e = /* @__PURE__ */ new Set();
|
|
1168
1366
|
for (const [n, s] of t)
|
|
1169
1367
|
e.has(s) || (e.add(s), yield [n, s]);
|
|
@@ -1175,6 +1373,9 @@ const _ = class _ {
|
|
|
1175
1373
|
*
|
|
1176
1374
|
* If the iterator is infinite, the method will never return.
|
|
1177
1375
|
*
|
|
1376
|
+
* ---
|
|
1377
|
+
*
|
|
1378
|
+
* @example
|
|
1178
1379
|
* ```ts
|
|
1179
1380
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1180
1381
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1184,6 +1385,8 @@ const _ = class _ {
|
|
|
1184
1385
|
* console.log(results); // 2
|
|
1185
1386
|
* ```
|
|
1186
1387
|
*
|
|
1388
|
+
* ---
|
|
1389
|
+
*
|
|
1187
1390
|
* @returns The number of elements in the iterator.
|
|
1188
1391
|
*/
|
|
1189
1392
|
count() {
|
|
@@ -1199,17 +1402,22 @@ const _ = class _ {
|
|
|
1199
1402
|
* This method will consume the entire iterator in the process.
|
|
1200
1403
|
* If the iterator is infinite, the method will never return.
|
|
1201
1404
|
*
|
|
1405
|
+
* ---
|
|
1406
|
+
*
|
|
1407
|
+
* @example
|
|
1202
1408
|
* ```ts
|
|
1203
1409
|
* const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1204
1410
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
1205
1411
|
* .reduce((key, accumulator, value) => accumulator + value);
|
|
1206
|
-
*
|
|
1412
|
+
*
|
|
1207
1413
|
* reduced.forEach((key, value, index) =>
|
|
1208
1414
|
* {
|
|
1209
1415
|
* console.log(`#${index} - ${key}: ${value}`); // "#0 - odd: 4", "#1 - even: 16"
|
|
1210
1416
|
* });
|
|
1211
1417
|
* ```
|
|
1212
1418
|
*
|
|
1419
|
+
* ---
|
|
1420
|
+
*
|
|
1213
1421
|
* @param iteratee The function to apply to each element of the reduced iterator.
|
|
1214
1422
|
*/
|
|
1215
1423
|
forEach(t) {
|
|
@@ -1227,6 +1435,9 @@ const _ = class _ {
|
|
|
1227
1435
|
* This means that the original iterator won't be consumed until the
|
|
1228
1436
|
* new one is and that consuming one of them will consume the other as well.
|
|
1229
1437
|
*
|
|
1438
|
+
* ---
|
|
1439
|
+
*
|
|
1440
|
+
* @example
|
|
1230
1441
|
* ```ts
|
|
1231
1442
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, -6, -8])
|
|
1232
1443
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1236,6 +1447,8 @@ const _ = class _ {
|
|
|
1236
1447
|
* console.log(results.toObject()); // { positive: 4, negative: -12 }
|
|
1237
1448
|
* ```
|
|
1238
1449
|
*
|
|
1450
|
+
* ---
|
|
1451
|
+
*
|
|
1239
1452
|
* @template J The type of the new keys used to group the elements.
|
|
1240
1453
|
*
|
|
1241
1454
|
* @param iteratee The function to determine the new key of each element of the iterator.
|
|
@@ -1260,6 +1473,9 @@ const _ = class _ {
|
|
|
1260
1473
|
* This means that the original iterator won't be consumed until the
|
|
1261
1474
|
* new one is and that consuming one of them will consume the other as well.
|
|
1262
1475
|
*
|
|
1476
|
+
* ---
|
|
1477
|
+
*
|
|
1478
|
+
* @example
|
|
1263
1479
|
* ```ts
|
|
1264
1480
|
* const keys = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1265
1481
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1269,11 +1485,13 @@ const _ = class _ {
|
|
|
1269
1485
|
* console.log(keys.toArray()); // ["odd", "even"]
|
|
1270
1486
|
* ```
|
|
1271
1487
|
*
|
|
1488
|
+
* ---
|
|
1489
|
+
*
|
|
1272
1490
|
* @returns A new {@link SmartIterator} containing all the keys of the iterator.
|
|
1273
1491
|
*/
|
|
1274
1492
|
keys() {
|
|
1275
1493
|
const t = this._elements;
|
|
1276
|
-
return new
|
|
1494
|
+
return new c(function* () {
|
|
1277
1495
|
for (const [e] of t)
|
|
1278
1496
|
yield e;
|
|
1279
1497
|
});
|
|
@@ -1290,6 +1508,9 @@ const _ = class _ {
|
|
|
1290
1508
|
* This means that the original iterator won't be consumed until the
|
|
1291
1509
|
* new one is and that consuming one of them will consume the other as well.
|
|
1292
1510
|
*
|
|
1511
|
+
* ---
|
|
1512
|
+
*
|
|
1513
|
+
* @example
|
|
1293
1514
|
* ```ts
|
|
1294
1515
|
* const entries = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1295
1516
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1299,6 +1520,8 @@ const _ = class _ {
|
|
|
1299
1520
|
* console.log(entries.toArray()); // [["odd", 4], ["even", 16]]
|
|
1300
1521
|
* ```
|
|
1301
1522
|
*
|
|
1523
|
+
* ---
|
|
1524
|
+
*
|
|
1302
1525
|
* @returns A new {@link SmartIterator} containing all the entries of the iterator.
|
|
1303
1526
|
*/
|
|
1304
1527
|
entries() {
|
|
@@ -1315,6 +1538,9 @@ const _ = class _ {
|
|
|
1315
1538
|
* This means that the original iterator won't be consumed until the
|
|
1316
1539
|
* new one is and that consuming one of them will consume the other as well.
|
|
1317
1540
|
*
|
|
1541
|
+
* ---
|
|
1542
|
+
*
|
|
1543
|
+
* @example
|
|
1318
1544
|
* ```ts
|
|
1319
1545
|
* const values = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1320
1546
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1324,11 +1550,13 @@ const _ = class _ {
|
|
|
1324
1550
|
* console.log(values.toArray()); // [4, 16]
|
|
1325
1551
|
* ```
|
|
1326
1552
|
*
|
|
1553
|
+
* ---
|
|
1554
|
+
*
|
|
1327
1555
|
* @returns A new {@link SmartIterator} containing all the values of the iterator.
|
|
1328
1556
|
*/
|
|
1329
1557
|
values() {
|
|
1330
1558
|
const t = this._elements;
|
|
1331
|
-
return new
|
|
1559
|
+
return new c(function* () {
|
|
1332
1560
|
for (const [e, n] of t)
|
|
1333
1561
|
yield n;
|
|
1334
1562
|
});
|
|
@@ -1339,6 +1567,9 @@ const _ = class _ {
|
|
|
1339
1567
|
*
|
|
1340
1568
|
* If the iterator is infinite, the method will never return.
|
|
1341
1569
|
*
|
|
1570
|
+
* ---
|
|
1571
|
+
*
|
|
1572
|
+
* @example
|
|
1342
1573
|
* ```ts
|
|
1343
1574
|
* const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1344
1575
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1347,6 +1578,8 @@ const _ = class _ {
|
|
|
1347
1578
|
* console.log(reduced.toArray()); // [4, 16]
|
|
1348
1579
|
* ```
|
|
1349
1580
|
*
|
|
1581
|
+
* ---
|
|
1582
|
+
*
|
|
1350
1583
|
* @returns The {@link Array} containing all elements of the iterator.
|
|
1351
1584
|
*/
|
|
1352
1585
|
toArray() {
|
|
@@ -1358,6 +1591,9 @@ const _ = class _ {
|
|
|
1358
1591
|
*
|
|
1359
1592
|
* If the iterator is infinite, the method will never return.
|
|
1360
1593
|
*
|
|
1594
|
+
* ---
|
|
1595
|
+
*
|
|
1596
|
+
* @example
|
|
1361
1597
|
* ```ts
|
|
1362
1598
|
* const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1363
1599
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1366,6 +1602,8 @@ const _ = class _ {
|
|
|
1366
1602
|
* console.log(reduced.toMap()); // Map(2) { "odd" => 4, "even" => 16 }
|
|
1367
1603
|
* ```
|
|
1368
1604
|
*
|
|
1605
|
+
* ---
|
|
1606
|
+
*
|
|
1369
1607
|
* @returns The {@link Map} containing all elements of the iterator.
|
|
1370
1608
|
*/
|
|
1371
1609
|
toMap() {
|
|
@@ -1377,6 +1615,9 @@ const _ = class _ {
|
|
|
1377
1615
|
*
|
|
1378
1616
|
* If the iterator is infinite, the method will never return.
|
|
1379
1617
|
*
|
|
1618
|
+
* ---
|
|
1619
|
+
*
|
|
1620
|
+
* @example
|
|
1380
1621
|
* ```ts
|
|
1381
1622
|
* const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1382
1623
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1385,22 +1626,24 @@ const _ = class _ {
|
|
|
1385
1626
|
* console.log(reduced.toObject()); // { odd: 4, even: 16 }
|
|
1386
1627
|
* ```
|
|
1387
1628
|
*
|
|
1629
|
+
* ---
|
|
1630
|
+
*
|
|
1388
1631
|
* @returns The {@link Object} containing all elements of the iterator.
|
|
1389
1632
|
*/
|
|
1390
1633
|
toObject() {
|
|
1391
1634
|
return Object.fromEntries(this.entries());
|
|
1392
1635
|
}
|
|
1393
1636
|
};
|
|
1394
|
-
let h =
|
|
1395
|
-
var
|
|
1396
|
-
|
|
1397
|
-
const
|
|
1637
|
+
let h = p;
|
|
1638
|
+
var me;
|
|
1639
|
+
me = Symbol.toStringTag;
|
|
1640
|
+
const w = class w {
|
|
1398
1641
|
constructor(t) {
|
|
1399
1642
|
/**
|
|
1400
1643
|
* The internal {@link SmartAsyncIterator} object that holds the elements to aggregate.
|
|
1401
1644
|
*/
|
|
1402
1645
|
a(this, "_elements");
|
|
1403
|
-
a(this,
|
|
1646
|
+
a(this, me, "AggregatedAsyncIterator");
|
|
1404
1647
|
this._elements = new f(t);
|
|
1405
1648
|
}
|
|
1406
1649
|
/**
|
|
@@ -1416,6 +1659,9 @@ const m = class m {
|
|
|
1416
1659
|
* object that will contain all the boolean results for each group.
|
|
1417
1660
|
* If the iterator is infinite, the method will never return.
|
|
1418
1661
|
*
|
|
1662
|
+
* ---
|
|
1663
|
+
*
|
|
1664
|
+
* @example
|
|
1419
1665
|
* ```ts
|
|
1420
1666
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1421
1667
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1424,6 +1670,8 @@ const m = class m {
|
|
|
1424
1670
|
* console.log(await results.toObject()); // { odd: false, even: true }
|
|
1425
1671
|
* ```
|
|
1426
1672
|
*
|
|
1673
|
+
* ---
|
|
1674
|
+
*
|
|
1427
1675
|
* @param predicate The condition to check for each element of the iterator.
|
|
1428
1676
|
*
|
|
1429
1677
|
* @returns
|
|
@@ -1453,6 +1701,9 @@ const m = class m {
|
|
|
1453
1701
|
* object that will contain all the boolean results for each group.
|
|
1454
1702
|
* If the iterator is infinite, the method will never return.
|
|
1455
1703
|
*
|
|
1704
|
+
* ---
|
|
1705
|
+
*
|
|
1706
|
+
* @example
|
|
1456
1707
|
* ```ts
|
|
1457
1708
|
* const results = new SmartAsyncIterator<number>([-5, -4, -3, -2, -1, 0])
|
|
1458
1709
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1461,6 +1712,8 @@ const m = class m {
|
|
|
1461
1712
|
* console.log(await results.toObject()); // { odd: false, even: true }
|
|
1462
1713
|
* ```
|
|
1463
1714
|
*
|
|
1715
|
+
* ---
|
|
1716
|
+
*
|
|
1464
1717
|
* @param predicate The condition to check for each element of the iterator.
|
|
1465
1718
|
*
|
|
1466
1719
|
* @returns
|
|
@@ -1479,7 +1732,7 @@ const m = class m {
|
|
|
1479
1732
|
}
|
|
1480
1733
|
filter(t) {
|
|
1481
1734
|
const e = this._elements;
|
|
1482
|
-
return new
|
|
1735
|
+
return new w(async function* () {
|
|
1483
1736
|
const n = /* @__PURE__ */ new Map();
|
|
1484
1737
|
for await (const [s, r] of e) {
|
|
1485
1738
|
const o = n.get(s) ?? 0;
|
|
@@ -1500,6 +1753,9 @@ const m = class m {
|
|
|
1500
1753
|
* This means that the original iterator won't be consumed until the
|
|
1501
1754
|
* new one is and that consuming one of them will consume the other as well.
|
|
1502
1755
|
*
|
|
1756
|
+
* ---
|
|
1757
|
+
*
|
|
1758
|
+
* @example
|
|
1503
1759
|
* ```ts
|
|
1504
1760
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1505
1761
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1508,6 +1764,8 @@ const m = class m {
|
|
|
1508
1764
|
* console.log(await results.toObject()); // { odd: [3, 1, 3, 5], even: [0, 2, 6, 8] }
|
|
1509
1765
|
* ```
|
|
1510
1766
|
*
|
|
1767
|
+
* ---
|
|
1768
|
+
*
|
|
1511
1769
|
* @template V The type of the elements after the transformation.
|
|
1512
1770
|
*
|
|
1513
1771
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -1516,7 +1774,7 @@ const m = class m {
|
|
|
1516
1774
|
*/
|
|
1517
1775
|
map(t) {
|
|
1518
1776
|
const e = this._elements;
|
|
1519
|
-
return new
|
|
1777
|
+
return new w(async function* () {
|
|
1520
1778
|
const n = /* @__PURE__ */ new Map();
|
|
1521
1779
|
for await (const [s, r] of e) {
|
|
1522
1780
|
const o = n.get(s) ?? 0;
|
|
@@ -1556,6 +1814,9 @@ const m = class m {
|
|
|
1556
1814
|
* This means that the original iterator won't be consumed until the
|
|
1557
1815
|
* new one is and that consuming one of them will consume the other as well.
|
|
1558
1816
|
*
|
|
1817
|
+
* ---
|
|
1818
|
+
*
|
|
1819
|
+
* @example
|
|
1559
1820
|
* ```ts
|
|
1560
1821
|
* const results = new SmartAsyncIterator<number>([[-3, -1], 0, 2, 3, 5, [6, 8]])
|
|
1561
1822
|
* .groupBy(async (values) =>
|
|
@@ -1568,6 +1829,8 @@ const m = class m {
|
|
|
1568
1829
|
* console.log(await results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
1569
1830
|
* ```
|
|
1570
1831
|
*
|
|
1832
|
+
* ---
|
|
1833
|
+
*
|
|
1571
1834
|
* @template V The type of the elements after the transformation.
|
|
1572
1835
|
*
|
|
1573
1836
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -1576,7 +1839,7 @@ const m = class m {
|
|
|
1576
1839
|
*/
|
|
1577
1840
|
flatMap(t) {
|
|
1578
1841
|
const e = this._elements;
|
|
1579
|
-
return new
|
|
1842
|
+
return new w(async function* () {
|
|
1580
1843
|
const n = /* @__PURE__ */ new Map();
|
|
1581
1844
|
for await (const [s, r] of e) {
|
|
1582
1845
|
const o = n.get(s) ?? 0, l = await t(s, r, o);
|
|
@@ -1601,6 +1864,9 @@ const m = class m {
|
|
|
1601
1864
|
* This means that the original iterator won't be consumed until the
|
|
1602
1865
|
* new one is and that consuming one of them will consume the other as well.
|
|
1603
1866
|
*
|
|
1867
|
+
* ---
|
|
1868
|
+
*
|
|
1869
|
+
* @example
|
|
1604
1870
|
* ```ts
|
|
1605
1871
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1606
1872
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1609,13 +1875,15 @@ const m = class m {
|
|
|
1609
1875
|
* console.log(await results.toObject()); // { odd: [3, 5], even: [6, 8] }
|
|
1610
1876
|
* ```
|
|
1611
1877
|
*
|
|
1878
|
+
* ---
|
|
1879
|
+
*
|
|
1612
1880
|
* @param count The number of elements to drop from the beginning of each group.
|
|
1613
1881
|
*
|
|
1614
1882
|
* @returns A new {@link AggregatedAsyncIterator} containing the remaining elements.
|
|
1615
1883
|
*/
|
|
1616
1884
|
drop(t) {
|
|
1617
1885
|
const e = this._elements;
|
|
1618
|
-
return new
|
|
1886
|
+
return new w(async function* () {
|
|
1619
1887
|
const n = /* @__PURE__ */ new Map();
|
|
1620
1888
|
for await (const [s, r] of e) {
|
|
1621
1889
|
const o = n.get(s) ?? 0;
|
|
@@ -1639,6 +1907,9 @@ const m = class m {
|
|
|
1639
1907
|
* This means that the original iterator won't be consumed until the
|
|
1640
1908
|
* new one is and that consuming one of them will consume the other as well.
|
|
1641
1909
|
*
|
|
1910
|
+
* ---
|
|
1911
|
+
*
|
|
1912
|
+
* @example
|
|
1642
1913
|
* ```ts
|
|
1643
1914
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1644
1915
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1647,13 +1918,15 @@ const m = class m {
|
|
|
1647
1918
|
* console.log(await results.toObject()); // { odd: [-3, -1], even: [0, 2] }
|
|
1648
1919
|
* ```
|
|
1649
1920
|
*
|
|
1650
|
-
*
|
|
1921
|
+
* ---
|
|
1922
|
+
*
|
|
1923
|
+
* @param limit The number of elements to take from the beginning of each group.
|
|
1651
1924
|
*
|
|
1652
1925
|
* @returns A new {@link AggregatedAsyncIterator} containing the taken elements.
|
|
1653
1926
|
*/
|
|
1654
1927
|
take(t) {
|
|
1655
1928
|
const e = this._elements;
|
|
1656
|
-
return new
|
|
1929
|
+
return new w(async function* () {
|
|
1657
1930
|
const n = /* @__PURE__ */ new Map();
|
|
1658
1931
|
for await (const [s, r] of e) {
|
|
1659
1932
|
const o = n.get(s) ?? 0;
|
|
@@ -1683,6 +1956,9 @@ const m = class m {
|
|
|
1683
1956
|
* This means that the original iterator won't be consumed until the
|
|
1684
1957
|
* new one is and that consuming one of them will consume the other as well.
|
|
1685
1958
|
*
|
|
1959
|
+
* ---
|
|
1960
|
+
*
|
|
1961
|
+
* @example
|
|
1686
1962
|
* ```ts
|
|
1687
1963
|
* const results = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
|
|
1688
1964
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1691,6 +1967,8 @@ const m = class m {
|
|
|
1691
1967
|
* console.log(results.toObject()); // { odd: [[0, -3], [1, -1], [2, 3]], even: [[0, 0], [1, 2]] }
|
|
1692
1968
|
* ```
|
|
1693
1969
|
*
|
|
1970
|
+
* ---
|
|
1971
|
+
*
|
|
1694
1972
|
* @returns A new {@link AggregatedAsyncIterator} containing the enumerated elements.
|
|
1695
1973
|
*/
|
|
1696
1974
|
enumerate() {
|
|
@@ -1707,6 +1985,9 @@ const m = class m {
|
|
|
1707
1985
|
* This means that the original iterator won't be consumed until the
|
|
1708
1986
|
* new one is and that consuming one of them will consume the other as well.
|
|
1709
1987
|
*
|
|
1988
|
+
* ---
|
|
1989
|
+
*
|
|
1990
|
+
* @example
|
|
1710
1991
|
* ```ts
|
|
1711
1992
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 0, 5, 6, 8, 0, 2])
|
|
1712
1993
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1715,11 +1996,13 @@ const m = class m {
|
|
|
1715
1996
|
* console.log(await results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
1716
1997
|
* ```
|
|
1717
1998
|
*
|
|
1999
|
+
* ---
|
|
2000
|
+
*
|
|
1718
2001
|
* @returns A new {@link AggregatedAsyncIterator} containing only the unique elements.
|
|
1719
2002
|
*/
|
|
1720
2003
|
unique() {
|
|
1721
2004
|
const t = this._elements;
|
|
1722
|
-
return new
|
|
2005
|
+
return new w(async function* () {
|
|
1723
2006
|
const e = /* @__PURE__ */ new Map();
|
|
1724
2007
|
for await (const [n, s] of t) {
|
|
1725
2008
|
const r = e.get(n) ?? /* @__PURE__ */ new Set();
|
|
@@ -1733,6 +2016,9 @@ const m = class m {
|
|
|
1733
2016
|
*
|
|
1734
2017
|
* If the iterator is infinite, the method will never return.
|
|
1735
2018
|
*
|
|
2019
|
+
* ---
|
|
2020
|
+
*
|
|
2021
|
+
* @example
|
|
1736
2022
|
* ```ts
|
|
1737
2023
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1738
2024
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1741,6 +2027,8 @@ const m = class m {
|
|
|
1741
2027
|
* console.log(await results.toObject()); // { odd: 4, even: 4 }
|
|
1742
2028
|
* ```
|
|
1743
2029
|
*
|
|
2030
|
+
* ---
|
|
2031
|
+
*
|
|
1744
2032
|
* @returns
|
|
1745
2033
|
* A {@link Promise} resolving to a new {@link ReducedIterator} containing the number of elements for each group.
|
|
1746
2034
|
*/
|
|
@@ -1762,6 +2050,9 @@ const m = class m {
|
|
|
1762
2050
|
* This method will consume the entire iterator in the process.
|
|
1763
2051
|
* If the iterator is infinite, the method will never return.
|
|
1764
2052
|
*
|
|
2053
|
+
* ---
|
|
2054
|
+
*
|
|
2055
|
+
* @example
|
|
1765
2056
|
* ```ts
|
|
1766
2057
|
* const aggregator = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
|
|
1767
2058
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1772,6 +2063,8 @@ const m = class m {
|
|
|
1772
2063
|
* };
|
|
1773
2064
|
* ```
|
|
1774
2065
|
*
|
|
2066
|
+
* ---
|
|
2067
|
+
*
|
|
1775
2068
|
* @param iteratee The function to execute for each element of the iterator.
|
|
1776
2069
|
*
|
|
1777
2070
|
* @returns A {@link Promise} that will resolve once the iteration is complete.
|
|
@@ -1794,6 +2087,9 @@ const m = class m {
|
|
|
1794
2087
|
* This means that the original iterator won't be consumed until the
|
|
1795
2088
|
* new one is and that consuming one of them will consume the other as well.
|
|
1796
2089
|
*
|
|
2090
|
+
* ---
|
|
2091
|
+
*
|
|
2092
|
+
* @example
|
|
1797
2093
|
* ```ts
|
|
1798
2094
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1799
2095
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1803,6 +2099,8 @@ const m = class m {
|
|
|
1803
2099
|
* console.log(await results.toObject()); // { "+": [1, 0, 3, 6], "-": [-3, -2, -5, -8] }
|
|
1804
2100
|
* ```
|
|
1805
2101
|
*
|
|
2102
|
+
* ---
|
|
2103
|
+
*
|
|
1806
2104
|
* @template J The type of the new key.
|
|
1807
2105
|
*
|
|
1808
2106
|
* @param iteratee The function to determine the new key for each element of the iterator.
|
|
@@ -1811,7 +2109,7 @@ const m = class m {
|
|
|
1811
2109
|
*/
|
|
1812
2110
|
reorganizeBy(t) {
|
|
1813
2111
|
const e = this._elements;
|
|
1814
|
-
return new
|
|
2112
|
+
return new w(async function* () {
|
|
1815
2113
|
const n = /* @__PURE__ */ new Map();
|
|
1816
2114
|
for await (const [s, r] of e) {
|
|
1817
2115
|
const o = n.get(s) ?? 0;
|
|
@@ -1830,6 +2128,9 @@ const m = class m {
|
|
|
1830
2128
|
* This means that the original iterator won't be consumed until the
|
|
1831
2129
|
* new one is and that consuming one of them will consume the other as well.
|
|
1832
2130
|
*
|
|
2131
|
+
* ---
|
|
2132
|
+
*
|
|
2133
|
+
* @example
|
|
1833
2134
|
* ```ts
|
|
1834
2135
|
* const keys = new SmartAsyncIterator([-3, Symbol(), "A", { }, null, [1 , 2, 3], false])
|
|
1835
2136
|
* .groupBy(async (value) => typeof value)
|
|
@@ -1838,6 +2139,8 @@ const m = class m {
|
|
|
1838
2139
|
* console.log(await keys.toArray()); // ["number", "symbol", "string", "object", "boolean"]
|
|
1839
2140
|
* ```
|
|
1840
2141
|
*
|
|
2142
|
+
* ---
|
|
2143
|
+
*
|
|
1841
2144
|
* @returns A new {@link SmartAsyncIterator} containing all the keys of the iterator.
|
|
1842
2145
|
*/
|
|
1843
2146
|
keys() {
|
|
@@ -1860,6 +2163,9 @@ const m = class m {
|
|
|
1860
2163
|
* This means that the original iterator won't be consumed until the
|
|
1861
2164
|
* new one is and that consuming one of them will consume the other as well.
|
|
1862
2165
|
*
|
|
2166
|
+
* ---
|
|
2167
|
+
*
|
|
2168
|
+
* @example
|
|
1863
2169
|
* ```ts
|
|
1864
2170
|
* const entries = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
|
|
1865
2171
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1868,6 +2174,8 @@ const m = class m {
|
|
|
1868
2174
|
* console.log(await entries.toArray()); // [["odd", -3], ["even", 0], ["even", 2], ["odd", -1], ["odd", 3]]
|
|
1869
2175
|
* ```
|
|
1870
2176
|
*
|
|
2177
|
+
* ---
|
|
2178
|
+
*
|
|
1871
2179
|
* @returns A new {@link SmartAsyncIterator} containing all the entries of the iterator.
|
|
1872
2180
|
*/
|
|
1873
2181
|
entries() {
|
|
@@ -1884,6 +2192,9 @@ const m = class m {
|
|
|
1884
2192
|
* This means that the original iterator won't be consumed until the
|
|
1885
2193
|
* new one is and that consuming one of them will consume the other as well.
|
|
1886
2194
|
*
|
|
2195
|
+
* ---
|
|
2196
|
+
*
|
|
2197
|
+
* @example
|
|
1887
2198
|
* ```ts
|
|
1888
2199
|
* const values = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1889
2200
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -1892,6 +2203,8 @@ const m = class m {
|
|
|
1892
2203
|
* console.log(await values.toArray()); // [-3, -1, 0, 2, 3, 5, 6, 8]
|
|
1893
2204
|
* ```
|
|
1894
2205
|
*
|
|
2206
|
+
* ---
|
|
2207
|
+
*
|
|
1895
2208
|
* @returns A new {@link SmartAsyncIterator} containing all the values of the iterator.
|
|
1896
2209
|
*/
|
|
1897
2210
|
values() {
|
|
@@ -1907,6 +2220,9 @@ const m = class m {
|
|
|
1907
2220
|
*
|
|
1908
2221
|
* If the iterator is infinite, the method will never return.
|
|
1909
2222
|
*
|
|
2223
|
+
* ---
|
|
2224
|
+
*
|
|
2225
|
+
* @example
|
|
1910
2226
|
* ```ts
|
|
1911
2227
|
* const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1912
2228
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1914,6 +2230,8 @@ const m = class m {
|
|
|
1914
2230
|
* console.log(await aggregator.toArray()); // [[-3, -1, 3, 5], [0, 2, 6, 8]]
|
|
1915
2231
|
* ```
|
|
1916
2232
|
*
|
|
2233
|
+
* ---
|
|
2234
|
+
*
|
|
1917
2235
|
* @returns A {@link Promise} resolving to an {@link Array} containing all the values of the iterator.
|
|
1918
2236
|
*/
|
|
1919
2237
|
async toArray() {
|
|
@@ -1926,6 +2244,9 @@ const m = class m {
|
|
|
1926
2244
|
*
|
|
1927
2245
|
* If the iterator is infinite, the method will never return.
|
|
1928
2246
|
*
|
|
2247
|
+
* ---
|
|
2248
|
+
*
|
|
2249
|
+
* @example
|
|
1929
2250
|
* ```ts
|
|
1930
2251
|
* const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1931
2252
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1933,6 +2254,8 @@ const m = class m {
|
|
|
1933
2254
|
* console.log(await aggregator.toMap()); // Map(2) { "odd" => [-3, -1, 3, 5], "even" => [0, 2, 6, 8] }
|
|
1934
2255
|
* ```
|
|
1935
2256
|
*
|
|
2257
|
+
* ---
|
|
2258
|
+
*
|
|
1936
2259
|
* @returns A {@link Promise} resolving to a {@link Map} containing all the entries of the iterator.
|
|
1937
2260
|
*/
|
|
1938
2261
|
async toMap() {
|
|
@@ -1949,6 +2272,9 @@ const m = class m {
|
|
|
1949
2272
|
*
|
|
1950
2273
|
* If the iterator is infinite, the method will never return.
|
|
1951
2274
|
*
|
|
2275
|
+
* ---
|
|
2276
|
+
*
|
|
2277
|
+
* @example
|
|
1952
2278
|
* ```ts
|
|
1953
2279
|
* const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1954
2280
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1956,6 +2282,8 @@ const m = class m {
|
|
|
1956
2282
|
* console.log(await aggregator.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
1957
2283
|
* ```
|
|
1958
2284
|
*
|
|
2285
|
+
* ---
|
|
2286
|
+
*
|
|
1959
2287
|
* @returns A {@link Promise} resolving to an object containing all the entries of the iterator.
|
|
1960
2288
|
*/
|
|
1961
2289
|
async toObject() {
|
|
@@ -1967,7 +2295,7 @@ const m = class m {
|
|
|
1967
2295
|
return t;
|
|
1968
2296
|
}
|
|
1969
2297
|
};
|
|
1970
|
-
let T =
|
|
2298
|
+
let T = w;
|
|
1971
2299
|
var ye;
|
|
1972
2300
|
class f {
|
|
1973
2301
|
constructor(t) {
|
|
@@ -2023,6 +2351,9 @@ class f {
|
|
|
2023
2351
|
*
|
|
2024
2352
|
* If the iterator is infinite and every element satisfies the condition, the method will never return.
|
|
2025
2353
|
*
|
|
2354
|
+
* ---
|
|
2355
|
+
*
|
|
2356
|
+
* @example
|
|
2026
2357
|
* ```ts
|
|
2027
2358
|
* const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
|
|
2028
2359
|
* const result = await iterator.every(async (value) => value < 0);
|
|
@@ -2030,6 +2361,8 @@ class f {
|
|
|
2030
2361
|
* console.log(result); // false
|
|
2031
2362
|
* ```
|
|
2032
2363
|
*
|
|
2364
|
+
* ---
|
|
2365
|
+
*
|
|
2033
2366
|
* @param predicate The condition to check for each element of the iterator.
|
|
2034
2367
|
*
|
|
2035
2368
|
* @returns
|
|
@@ -2059,6 +2392,9 @@ class f {
|
|
|
2059
2392
|
*
|
|
2060
2393
|
* If the iterator is infinite and no element satisfies the condition, the method will never return.
|
|
2061
2394
|
*
|
|
2395
|
+
* ---
|
|
2396
|
+
*
|
|
2397
|
+
* @example
|
|
2062
2398
|
* ```ts
|
|
2063
2399
|
* const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
|
|
2064
2400
|
* const result = await iterator.some(async (value) => value > 0);
|
|
@@ -2066,6 +2402,8 @@ class f {
|
|
|
2066
2402
|
* console.log(result); // true
|
|
2067
2403
|
* ```
|
|
2068
2404
|
*
|
|
2405
|
+
* ---
|
|
2406
|
+
*
|
|
2069
2407
|
* @param predicate The condition to check for each element of the iterator.
|
|
2070
2408
|
*
|
|
2071
2409
|
* @returns
|
|
@@ -2107,6 +2445,9 @@ class f {
|
|
|
2107
2445
|
* This means that the original iterator won't be consumed until the
|
|
2108
2446
|
* new one is and that consuming one of them will consume the other as well.
|
|
2109
2447
|
*
|
|
2448
|
+
* ---
|
|
2449
|
+
*
|
|
2450
|
+
* @example
|
|
2110
2451
|
* ```ts
|
|
2111
2452
|
* const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
|
|
2112
2453
|
* const result = iterator.map(async (value) => Math.abs(value));
|
|
@@ -2114,6 +2455,8 @@ class f {
|
|
|
2114
2455
|
* console.log(await result.toArray()); // [2, 1, 0, 1, 2]
|
|
2115
2456
|
* ```
|
|
2116
2457
|
*
|
|
2458
|
+
* ---
|
|
2459
|
+
*
|
|
2117
2460
|
* @template V The type of the elements after the transformation.
|
|
2118
2461
|
*
|
|
2119
2462
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -2160,6 +2503,9 @@ class f {
|
|
|
2160
2503
|
* This means that the original iterator won't be consumed until the
|
|
2161
2504
|
* new one is and that consuming one of them will consume the other as well.
|
|
2162
2505
|
*
|
|
2506
|
+
* ---
|
|
2507
|
+
*
|
|
2508
|
+
* @example
|
|
2163
2509
|
* ```ts
|
|
2164
2510
|
* const iterator = new SmartAsyncIterator<number[]>([[-2, -1], 0, 1, 2, [3, 4, 5]]);
|
|
2165
2511
|
* const result = iterator.flatMap(async (value) => value);
|
|
@@ -2167,6 +2513,8 @@ class f {
|
|
|
2167
2513
|
* console.log(await result.toArray()); // [-2, -1, 0, 1, 2, 3, 4, 5]
|
|
2168
2514
|
* ```
|
|
2169
2515
|
*
|
|
2516
|
+
* ---
|
|
2517
|
+
*
|
|
2170
2518
|
* @template V The type of the elements after the transformation.
|
|
2171
2519
|
*
|
|
2172
2520
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -2206,6 +2554,9 @@ class f {
|
|
|
2206
2554
|
* Only the dropped elements will be consumed in the process.
|
|
2207
2555
|
* The rest of the iterator will be consumed only once the new one is.
|
|
2208
2556
|
*
|
|
2557
|
+
* ---
|
|
2558
|
+
*
|
|
2559
|
+
* @example
|
|
2209
2560
|
* ```ts
|
|
2210
2561
|
* const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
|
|
2211
2562
|
* const result = iterator.drop(3);
|
|
@@ -2213,6 +2564,8 @@ class f {
|
|
|
2213
2564
|
* console.log(await result.toArray()); // [1, 2]
|
|
2214
2565
|
* ```
|
|
2215
2566
|
*
|
|
2567
|
+
* ---
|
|
2568
|
+
*
|
|
2216
2569
|
* @param count The number of elements to drop.
|
|
2217
2570
|
*
|
|
2218
2571
|
* @returns A new {@link SmartAsyncIterator} containing the remaining elements.
|
|
@@ -2249,6 +2602,9 @@ class f {
|
|
|
2249
2602
|
* Only the taken elements will be consumed from the original iterator.
|
|
2250
2603
|
* The rest of the original iterator will be available for further consumption.
|
|
2251
2604
|
*
|
|
2605
|
+
* ---
|
|
2606
|
+
*
|
|
2607
|
+
* @example
|
|
2252
2608
|
* ```ts
|
|
2253
2609
|
* const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
|
|
2254
2610
|
* const result = iterator.take(3);
|
|
@@ -2257,6 +2613,8 @@ class f {
|
|
|
2257
2613
|
* console.log(await iterator.toArray()); // [1, 2]
|
|
2258
2614
|
* ```
|
|
2259
2615
|
*
|
|
2616
|
+
* ---
|
|
2617
|
+
*
|
|
2260
2618
|
* @param limit The number of elements to take.
|
|
2261
2619
|
*
|
|
2262
2620
|
* @returns A new {@link SmartAsyncIterator} containing the taken elements.
|
|
@@ -2295,6 +2653,9 @@ class f {
|
|
|
2295
2653
|
* This means that the original iterator won't be consumed until the
|
|
2296
2654
|
* new one is and that consuming one of them will consume the other as well.
|
|
2297
2655
|
*
|
|
2656
|
+
* ---
|
|
2657
|
+
*
|
|
2658
|
+
* @example
|
|
2298
2659
|
* ```ts
|
|
2299
2660
|
* const iterator = new SmartAsyncIterator<string>(["A", "M", "N", "Z"]);
|
|
2300
2661
|
* const result = iterator.enumerate();
|
|
@@ -2305,6 +2666,8 @@ class f {
|
|
|
2305
2666
|
* }
|
|
2306
2667
|
* ```
|
|
2307
2668
|
*
|
|
2669
|
+
* ---
|
|
2670
|
+
*
|
|
2308
2671
|
* @returns A new {@link SmartAsyncIterator} containing the enumerated elements.
|
|
2309
2672
|
*/
|
|
2310
2673
|
enumerate() {
|
|
@@ -2321,6 +2684,9 @@ class f {
|
|
|
2321
2684
|
* This means that the original iterator won't be consumed until the
|
|
2322
2685
|
* new one is and that consuming one of them will consume the other as well.
|
|
2323
2686
|
*
|
|
2687
|
+
* ---
|
|
2688
|
+
*
|
|
2689
|
+
* @example
|
|
2324
2690
|
* ```ts
|
|
2325
2691
|
* const iterator = new SmartAsyncIterator<number>([1, 1, 2, 3, 2, 3, 4, 5, 5, 4]);
|
|
2326
2692
|
* const result = iterator.unique();
|
|
@@ -2328,6 +2694,8 @@ class f {
|
|
|
2328
2694
|
* console.log(await result.toArray()); // [1, 2, 3, 4, 5]
|
|
2329
2695
|
* ```
|
|
2330
2696
|
*
|
|
2697
|
+
* ---
|
|
2698
|
+
*
|
|
2331
2699
|
* @returns A new {@link SmartAsyncIterator} containing only the unique elements.
|
|
2332
2700
|
*/
|
|
2333
2701
|
unique() {
|
|
@@ -2348,6 +2716,9 @@ class f {
|
|
|
2348
2716
|
*
|
|
2349
2717
|
* If the iterator is infinite, the method will never return.
|
|
2350
2718
|
*
|
|
2719
|
+
* ---
|
|
2720
|
+
*
|
|
2721
|
+
* @example
|
|
2351
2722
|
* ```ts
|
|
2352
2723
|
* const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5]);
|
|
2353
2724
|
* const result = await iterator.count();
|
|
@@ -2355,6 +2726,8 @@ class f {
|
|
|
2355
2726
|
* console.log(result); // 5
|
|
2356
2727
|
* ```
|
|
2357
2728
|
*
|
|
2729
|
+
* ---
|
|
2730
|
+
*
|
|
2358
2731
|
* @returns A {@link Promise} that will resolve to the number of elements in the iterator.
|
|
2359
2732
|
*/
|
|
2360
2733
|
async count() {
|
|
@@ -2372,6 +2745,9 @@ class f {
|
|
|
2372
2745
|
* This method will consume the entire iterator in the process.
|
|
2373
2746
|
* If the iterator is infinite, the method will never return.
|
|
2374
2747
|
*
|
|
2748
|
+
* ---
|
|
2749
|
+
*
|
|
2750
|
+
* @example
|
|
2375
2751
|
* ```ts
|
|
2376
2752
|
* const iterator = new SmartAsyncIterator<number>(["A", "M", "N", "Z"]);
|
|
2377
2753
|
* await iterator.forEach(async (value, index) =>
|
|
@@ -2380,6 +2756,8 @@ class f {
|
|
|
2380
2756
|
* }
|
|
2381
2757
|
* ```
|
|
2382
2758
|
*
|
|
2759
|
+
* ---
|
|
2760
|
+
*
|
|
2383
2761
|
* @param iteratee The function to apply to each element of the iterator.
|
|
2384
2762
|
*
|
|
2385
2763
|
* @returns A {@link Promise} that will resolve once the iteration is complete.
|
|
@@ -2399,6 +2777,9 @@ class f {
|
|
|
2399
2777
|
*
|
|
2400
2778
|
* Once the iterator is done, the method will return an object with the `done` property set to `true`.
|
|
2401
2779
|
*
|
|
2780
|
+
* ---
|
|
2781
|
+
*
|
|
2782
|
+
* @example
|
|
2402
2783
|
* ```ts
|
|
2403
2784
|
* const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5]);
|
|
2404
2785
|
*
|
|
@@ -2413,6 +2794,8 @@ class f {
|
|
|
2413
2794
|
* console.log(result); // { done: true, value: undefined }
|
|
2414
2795
|
* ```
|
|
2415
2796
|
*
|
|
2797
|
+
* ---
|
|
2798
|
+
*
|
|
2416
2799
|
* @param values The value to pass to the next element, if required.
|
|
2417
2800
|
*
|
|
2418
2801
|
* @returns
|
|
@@ -2426,6 +2809,9 @@ class f {
|
|
|
2426
2809
|
* free the resources and perform any cleanup operation.
|
|
2427
2810
|
* It may also be used to signal the end or to compute a specific final result of the iteration process.
|
|
2428
2811
|
*
|
|
2812
|
+
* ---
|
|
2813
|
+
*
|
|
2814
|
+
* @example
|
|
2429
2815
|
* ```ts
|
|
2430
2816
|
* const iterator = new SmartAsyncIterator<number>({
|
|
2431
2817
|
* _index: 0,
|
|
@@ -2444,6 +2830,8 @@ class f {
|
|
|
2444
2830
|
* }
|
|
2445
2831
|
* ```
|
|
2446
2832
|
*
|
|
2833
|
+
* ---
|
|
2834
|
+
*
|
|
2447
2835
|
* @param value The final value of the iterator.
|
|
2448
2836
|
*
|
|
2449
2837
|
* @returns A {@link Promise} that will resolve to the final result of the iterator.
|
|
@@ -2457,6 +2845,9 @@ class f {
|
|
|
2457
2845
|
* free the resources and perform any cleanup operation.
|
|
2458
2846
|
* It may also be used to signal that an error occurred during the iteration process or to handle it.
|
|
2459
2847
|
*
|
|
2848
|
+
* ---
|
|
2849
|
+
*
|
|
2850
|
+
* @example
|
|
2460
2851
|
* ```ts
|
|
2461
2852
|
* const iterator = new SmartAsyncIterator<number>({
|
|
2462
2853
|
* _index: 0,
|
|
@@ -2484,6 +2875,8 @@ class f {
|
|
|
2484
2875
|
* }
|
|
2485
2876
|
* ```
|
|
2486
2877
|
*
|
|
2878
|
+
* ---
|
|
2879
|
+
*
|
|
2487
2880
|
* @param error The error to throw into the iterator.
|
|
2488
2881
|
*
|
|
2489
2882
|
* @returns A {@link Promise} that will resolve to the final result of the iterator.
|
|
@@ -2505,6 +2898,9 @@ class f {
|
|
|
2505
2898
|
* This means that the original iterator won't be consumed until the
|
|
2506
2899
|
* the new one is and that consuming one of them will consume the other as well.
|
|
2507
2900
|
*
|
|
2901
|
+
* ---
|
|
2902
|
+
*
|
|
2903
|
+
* @example
|
|
2508
2904
|
* ```ts
|
|
2509
2905
|
* const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
2510
2906
|
* const result = iterator.groupBy<string>(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -2512,6 +2908,8 @@ class f {
|
|
|
2512
2908
|
* console.log(await result.toObject()); // { odd: [1, 3, 5, 7, 9], even: [2, 4, 6, 8, 10] }
|
|
2513
2909
|
* ```
|
|
2514
2910
|
*
|
|
2911
|
+
* ---
|
|
2912
|
+
*
|
|
2515
2913
|
* @template K The type of the keys used to group the elements.
|
|
2516
2914
|
*
|
|
2517
2915
|
* @param iteratee The key function to apply to each element of the iterator.
|
|
@@ -2527,6 +2925,9 @@ class f {
|
|
|
2527
2925
|
*
|
|
2528
2926
|
* If the iterator is infinite, the method will never return.
|
|
2529
2927
|
*
|
|
2928
|
+
* ---
|
|
2929
|
+
*
|
|
2930
|
+
* @example
|
|
2530
2931
|
* ```ts
|
|
2531
2932
|
* const iterator = new SmartAsyncIterator(async function* ()
|
|
2532
2933
|
* {
|
|
@@ -2537,6 +2938,8 @@ class f {
|
|
|
2537
2938
|
* console.log(result); // [0, 1, 2, 3, 4]
|
|
2538
2939
|
* ```
|
|
2539
2940
|
*
|
|
2941
|
+
* ---
|
|
2942
|
+
*
|
|
2540
2943
|
* @returns A {@link Promise} that will resolve to an array containing all elements of the iterator.
|
|
2541
2944
|
*/
|
|
2542
2945
|
toArray() {
|
|
@@ -2548,14 +2951,14 @@ class f {
|
|
|
2548
2951
|
}
|
|
2549
2952
|
var _e;
|
|
2550
2953
|
_e = Symbol.toStringTag;
|
|
2551
|
-
const
|
|
2954
|
+
const m = class m {
|
|
2552
2955
|
constructor(t) {
|
|
2553
2956
|
/**
|
|
2554
2957
|
* The internal {@link SmartIterator} object that holds the elements to aggregate.
|
|
2555
2958
|
*/
|
|
2556
2959
|
a(this, "_elements");
|
|
2557
2960
|
a(this, _e, "AggregatedIterator");
|
|
2558
|
-
this._elements = new
|
|
2961
|
+
this._elements = new c(t);
|
|
2559
2962
|
}
|
|
2560
2963
|
/**
|
|
2561
2964
|
* Determines whether all elements of each group of the iterator satisfy a given condition.
|
|
@@ -2570,6 +2973,9 @@ const w = class w {
|
|
|
2570
2973
|
* object that will contain all the boolean results for each group.
|
|
2571
2974
|
* If the iterator is infinite, the method will never return.
|
|
2572
2975
|
*
|
|
2976
|
+
* ---
|
|
2977
|
+
*
|
|
2978
|
+
* @example
|
|
2573
2979
|
* ```ts
|
|
2574
2980
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2575
2981
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2578,6 +2984,8 @@ const w = class w {
|
|
|
2578
2984
|
* console.log(results.toObject()); // { odd: false, even: true }
|
|
2579
2985
|
* ```
|
|
2580
2986
|
*
|
|
2987
|
+
* ---
|
|
2988
|
+
*
|
|
2581
2989
|
* @param predicate The condition to check for each element of the iterator.
|
|
2582
2990
|
*
|
|
2583
2991
|
* @returns A new {@link ReducedIterator} containing the boolean results for each group.
|
|
@@ -2606,6 +3014,9 @@ const w = class w {
|
|
|
2606
3014
|
* object that will contain all the boolean results for each group.
|
|
2607
3015
|
* If the iterator is infinite, the method will never return.
|
|
2608
3016
|
*
|
|
3017
|
+
* ---
|
|
3018
|
+
*
|
|
3019
|
+
* @example
|
|
2609
3020
|
* ```ts
|
|
2610
3021
|
* const results = new SmartIterator<number>([-5, -4, -3, -2, -1, 0])
|
|
2611
3022
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2614,6 +3025,8 @@ const w = class w {
|
|
|
2614
3025
|
* console.log(results.toObject()); // { odd: false, even: true }
|
|
2615
3026
|
* ```
|
|
2616
3027
|
*
|
|
3028
|
+
* ---
|
|
3029
|
+
*
|
|
2617
3030
|
* @param predicate The condition to check for each element of the iterator.
|
|
2618
3031
|
*
|
|
2619
3032
|
* @returns A {@link ReducedIterator} containing the boolean results for each group.
|
|
@@ -2631,7 +3044,7 @@ const w = class w {
|
|
|
2631
3044
|
}
|
|
2632
3045
|
filter(t) {
|
|
2633
3046
|
const e = this._elements;
|
|
2634
|
-
return new
|
|
3047
|
+
return new m(function* () {
|
|
2635
3048
|
const n = /* @__PURE__ */ new Map();
|
|
2636
3049
|
for (const [s, r] of e) {
|
|
2637
3050
|
const o = n.get(s) ?? 0;
|
|
@@ -2652,6 +3065,9 @@ const w = class w {
|
|
|
2652
3065
|
* This means that the original iterator won't be consumed until the
|
|
2653
3066
|
* new one is and that consuming one of them will consume the other as well.
|
|
2654
3067
|
*
|
|
3068
|
+
* ---
|
|
3069
|
+
*
|
|
3070
|
+
* @example
|
|
2655
3071
|
* ```ts
|
|
2656
3072
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2657
3073
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2660,6 +3076,8 @@ const w = class w {
|
|
|
2660
3076
|
* console.log(results.toObject()); // { odd: [3, 1, 3, 5], even: [0, 2, 6, 8] }
|
|
2661
3077
|
* ```
|
|
2662
3078
|
*
|
|
3079
|
+
* ---
|
|
3080
|
+
*
|
|
2663
3081
|
* @template V The type of the elements after the transformation.
|
|
2664
3082
|
*
|
|
2665
3083
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -2668,7 +3086,7 @@ const w = class w {
|
|
|
2668
3086
|
*/
|
|
2669
3087
|
map(t) {
|
|
2670
3088
|
const e = this._elements;
|
|
2671
|
-
return new
|
|
3089
|
+
return new m(function* () {
|
|
2672
3090
|
const n = /* @__PURE__ */ new Map();
|
|
2673
3091
|
for (const [s, r] of e) {
|
|
2674
3092
|
const o = n.get(s) ?? 0;
|
|
@@ -2708,6 +3126,9 @@ const w = class w {
|
|
|
2708
3126
|
* This means that the original iterator won't be consumed until the
|
|
2709
3127
|
* new one is and that consuming one of them will consume the other as well.
|
|
2710
3128
|
*
|
|
3129
|
+
* ---
|
|
3130
|
+
*
|
|
3131
|
+
* @example
|
|
2711
3132
|
* ```ts
|
|
2712
3133
|
* const results = new SmartIterator<number[]>([[-3, -1], 0, 2, 3, 5, [6, 8]])
|
|
2713
3134
|
* .groupBy((values) =>
|
|
@@ -2720,6 +3141,8 @@ const w = class w {
|
|
|
2720
3141
|
* console.log(results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
2721
3142
|
* ```
|
|
2722
3143
|
*
|
|
3144
|
+
* ---
|
|
3145
|
+
*
|
|
2723
3146
|
* @template V The type of the elements after the transformation.
|
|
2724
3147
|
*
|
|
2725
3148
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -2728,7 +3151,7 @@ const w = class w {
|
|
|
2728
3151
|
*/
|
|
2729
3152
|
flatMap(t) {
|
|
2730
3153
|
const e = this._elements;
|
|
2731
|
-
return new
|
|
3154
|
+
return new m(function* () {
|
|
2732
3155
|
const n = /* @__PURE__ */ new Map();
|
|
2733
3156
|
for (const [s, r] of e) {
|
|
2734
3157
|
const o = n.get(s) ?? 0, l = t(s, r, o);
|
|
@@ -2753,6 +3176,9 @@ const w = class w {
|
|
|
2753
3176
|
* This means that the original iterator won't be consumed until the
|
|
2754
3177
|
* new one is and that consuming one of them will consume the other as well.
|
|
2755
3178
|
*
|
|
3179
|
+
* ---
|
|
3180
|
+
*
|
|
3181
|
+
* @example
|
|
2756
3182
|
* ```ts
|
|
2757
3183
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2758
3184
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2761,13 +3187,15 @@ const w = class w {
|
|
|
2761
3187
|
* console.log(results.toObject()); // { odd: [3, 5], even: [6, 8] }
|
|
2762
3188
|
* ```
|
|
2763
3189
|
*
|
|
3190
|
+
* ---
|
|
3191
|
+
*
|
|
2764
3192
|
* @param count The number of elements to drop from the beginning of each group.
|
|
2765
3193
|
*
|
|
2766
3194
|
* @returns A new {@link AggregatedIterator} containing the remaining elements.
|
|
2767
3195
|
*/
|
|
2768
3196
|
drop(t) {
|
|
2769
3197
|
const e = this._elements;
|
|
2770
|
-
return new
|
|
3198
|
+
return new m(function* () {
|
|
2771
3199
|
const n = /* @__PURE__ */ new Map();
|
|
2772
3200
|
for (const [s, r] of e) {
|
|
2773
3201
|
const o = n.get(s) ?? 0;
|
|
@@ -2791,6 +3219,9 @@ const w = class w {
|
|
|
2791
3219
|
* This means that the original iterator won't be consumed until the
|
|
2792
3220
|
* new one is and that consuming one of them will consume the other as well.
|
|
2793
3221
|
*
|
|
3222
|
+
* ---
|
|
3223
|
+
*
|
|
3224
|
+
* @example
|
|
2794
3225
|
* ```ts
|
|
2795
3226
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2796
3227
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2799,13 +3230,15 @@ const w = class w {
|
|
|
2799
3230
|
* console.log(results.toObject()); // { odd: [-3, -1], even: [0, 2] }
|
|
2800
3231
|
* ```
|
|
2801
3232
|
*
|
|
2802
|
-
*
|
|
3233
|
+
* ---
|
|
3234
|
+
*
|
|
3235
|
+
* @param limit The number of elements to take from the beginning of each group.
|
|
2803
3236
|
*
|
|
2804
3237
|
* @returns A new {@link AggregatedIterator} containing the taken elements.
|
|
2805
3238
|
*/
|
|
2806
3239
|
take(t) {
|
|
2807
3240
|
const e = this._elements;
|
|
2808
|
-
return new
|
|
3241
|
+
return new m(function* () {
|
|
2809
3242
|
const n = /* @__PURE__ */ new Map();
|
|
2810
3243
|
for (const [s, r] of e) {
|
|
2811
3244
|
const o = n.get(s) ?? 0;
|
|
@@ -2835,6 +3268,9 @@ const w = class w {
|
|
|
2835
3268
|
* This means that the original iterator won't be consumed until the
|
|
2836
3269
|
* new one is and that consuming one of them will consume the other as well.
|
|
2837
3270
|
*
|
|
3271
|
+
* ---
|
|
3272
|
+
*
|
|
3273
|
+
* @example
|
|
2838
3274
|
* ```ts
|
|
2839
3275
|
* const results = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
2840
3276
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2843,6 +3279,8 @@ const w = class w {
|
|
|
2843
3279
|
* console.log(results.toObject()); // { odd: [[0, -3], [1, -1], [2, 3]], even: [[0, 0], [1, 2]] }
|
|
2844
3280
|
* ```
|
|
2845
3281
|
*
|
|
3282
|
+
* ---
|
|
3283
|
+
*
|
|
2846
3284
|
* @returns A new {@link AggregatedIterator} containing the enumerated elements.
|
|
2847
3285
|
*/
|
|
2848
3286
|
enumerate() {
|
|
@@ -2859,6 +3297,9 @@ const w = class w {
|
|
|
2859
3297
|
* This means that the original iterator won't be consumed until the
|
|
2860
3298
|
* new one is and that consuming one of them will consume the other as well.
|
|
2861
3299
|
*
|
|
3300
|
+
* ---
|
|
3301
|
+
*
|
|
3302
|
+
* @example
|
|
2862
3303
|
* ```ts
|
|
2863
3304
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 0, 5, 6, 8, 0, 2])
|
|
2864
3305
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2867,11 +3308,13 @@ const w = class w {
|
|
|
2867
3308
|
* console.log(results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
2868
3309
|
* ```
|
|
2869
3310
|
*
|
|
3311
|
+
* ---
|
|
3312
|
+
*
|
|
2870
3313
|
* @returns A new {@link AggregatedIterator} containing only the unique elements.
|
|
2871
3314
|
*/
|
|
2872
3315
|
unique() {
|
|
2873
3316
|
const t = this._elements;
|
|
2874
|
-
return new
|
|
3317
|
+
return new m(function* () {
|
|
2875
3318
|
const e = /* @__PURE__ */ new Map();
|
|
2876
3319
|
for (const [n, s] of t) {
|
|
2877
3320
|
const r = e.get(n) ?? /* @__PURE__ */ new Set();
|
|
@@ -2885,6 +3328,9 @@ const w = class w {
|
|
|
2885
3328
|
*
|
|
2886
3329
|
* If the iterator is infinite, the method will never return.
|
|
2887
3330
|
*
|
|
3331
|
+
* ---
|
|
3332
|
+
*
|
|
3333
|
+
* @example
|
|
2888
3334
|
* ```ts
|
|
2889
3335
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2890
3336
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2893,6 +3339,8 @@ const w = class w {
|
|
|
2893
3339
|
* console.log(results.toObject()); // { odd: 4, even: 4 }
|
|
2894
3340
|
* ```
|
|
2895
3341
|
*
|
|
3342
|
+
* ---
|
|
3343
|
+
*
|
|
2896
3344
|
* @returns A new {@link ReducedIterator} containing the number of elements for each group.
|
|
2897
3345
|
*/
|
|
2898
3346
|
count() {
|
|
@@ -2913,6 +3361,9 @@ const w = class w {
|
|
|
2913
3361
|
* This method will consume the entire iterator in the process.
|
|
2914
3362
|
* If the iterator is infinite, the method will never return.
|
|
2915
3363
|
*
|
|
3364
|
+
* ---
|
|
3365
|
+
*
|
|
3366
|
+
* @example
|
|
2916
3367
|
* ```ts
|
|
2917
3368
|
* const aggregator = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
2918
3369
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -2923,6 +3374,8 @@ const w = class w {
|
|
|
2923
3374
|
* };
|
|
2924
3375
|
* ```
|
|
2925
3376
|
*
|
|
3377
|
+
* ---
|
|
3378
|
+
*
|
|
2926
3379
|
* @param iteratee The function to execute for each element of the iterator.
|
|
2927
3380
|
*/
|
|
2928
3381
|
forEach(t) {
|
|
@@ -2943,6 +3396,9 @@ const w = class w {
|
|
|
2943
3396
|
* This means that the original iterator won't be consumed until the
|
|
2944
3397
|
* new one is and that consuming one of them will consume the other as well.
|
|
2945
3398
|
*
|
|
3399
|
+
* ---
|
|
3400
|
+
*
|
|
3401
|
+
* @example
|
|
2946
3402
|
* ```ts
|
|
2947
3403
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
2948
3404
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -2952,6 +3408,8 @@ const w = class w {
|
|
|
2952
3408
|
* console.log(results.toObject()); // { "+": [1, 0, 3, 6], "-": [-3, -2, -5, -8] }
|
|
2953
3409
|
* ```
|
|
2954
3410
|
*
|
|
3411
|
+
* ---
|
|
3412
|
+
*
|
|
2955
3413
|
* @template J The type of the new key.
|
|
2956
3414
|
*
|
|
2957
3415
|
* @param iteratee The function to determine the new key for each element of the iterator.
|
|
@@ -2960,7 +3418,7 @@ const w = class w {
|
|
|
2960
3418
|
*/
|
|
2961
3419
|
reorganizeBy(t) {
|
|
2962
3420
|
const e = this._elements;
|
|
2963
|
-
return new
|
|
3421
|
+
return new m(function* () {
|
|
2964
3422
|
const n = /* @__PURE__ */ new Map();
|
|
2965
3423
|
for (const [s, r] of e) {
|
|
2966
3424
|
const o = n.get(s) ?? 0;
|
|
@@ -2979,6 +3437,9 @@ const w = class w {
|
|
|
2979
3437
|
* This means that the original iterator won't be consumed until the
|
|
2980
3438
|
* new one is and that consuming one of them will consume the other as well.
|
|
2981
3439
|
*
|
|
3440
|
+
* ---
|
|
3441
|
+
*
|
|
3442
|
+
* @example
|
|
2982
3443
|
* ```ts
|
|
2983
3444
|
* const keys = new SmartIterator([-3, Symbol(), "A", { }, null, [1 , 2, 3], false])
|
|
2984
3445
|
* .groupBy((value) => typeof value)
|
|
@@ -2987,11 +3448,13 @@ const w = class w {
|
|
|
2987
3448
|
* console.log(keys.toArray()); // ["number", "symbol", "string", "object", "boolean"]
|
|
2988
3449
|
* ```
|
|
2989
3450
|
*
|
|
3451
|
+
* ---
|
|
3452
|
+
*
|
|
2990
3453
|
* @returns A new {@link SmartIterator} containing all the keys of the iterator.
|
|
2991
3454
|
*/
|
|
2992
3455
|
keys() {
|
|
2993
3456
|
const t = this._elements;
|
|
2994
|
-
return new
|
|
3457
|
+
return new c(function* () {
|
|
2995
3458
|
const e = /* @__PURE__ */ new Set();
|
|
2996
3459
|
for (const [n] of t)
|
|
2997
3460
|
e.has(n) || (e.add(n), yield n);
|
|
@@ -3009,6 +3472,9 @@ const w = class w {
|
|
|
3009
3472
|
* This means that the original iterator won't be consumed until the
|
|
3010
3473
|
* new one is and that consuming one of them will consume the other as well.
|
|
3011
3474
|
*
|
|
3475
|
+
* ---
|
|
3476
|
+
*
|
|
3477
|
+
* @example
|
|
3012
3478
|
* ```ts
|
|
3013
3479
|
* const entries = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
3014
3480
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -3017,6 +3483,8 @@ const w = class w {
|
|
|
3017
3483
|
* console.log(entries.toArray()); // [["odd", -3], ["even", 0], ["even", 2], ["odd", -1], ["odd", 3]]
|
|
3018
3484
|
* ```
|
|
3019
3485
|
*
|
|
3486
|
+
* ---
|
|
3487
|
+
*
|
|
3020
3488
|
* @returns A new {@link SmartIterator} containing all the entries of the iterator.
|
|
3021
3489
|
*/
|
|
3022
3490
|
entries() {
|
|
@@ -3033,6 +3501,9 @@ const w = class w {
|
|
|
3033
3501
|
* This means that the original iterator won't be consumed until the
|
|
3034
3502
|
* new one is and that consuming one of them will consume the other as well.
|
|
3035
3503
|
*
|
|
3504
|
+
* ---
|
|
3505
|
+
*
|
|
3506
|
+
* @example
|
|
3036
3507
|
* ```ts
|
|
3037
3508
|
* const values = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
3038
3509
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -3041,11 +3512,13 @@ const w = class w {
|
|
|
3041
3512
|
* console.log(values.toArray()); // [-3, -1, 0, 2, 3, 5, 6, 8]
|
|
3042
3513
|
* ```
|
|
3043
3514
|
*
|
|
3515
|
+
* ---
|
|
3516
|
+
*
|
|
3044
3517
|
* @returns A new {@link SmartIterator} containing all the values of the iterator.
|
|
3045
3518
|
*/
|
|
3046
3519
|
values() {
|
|
3047
3520
|
const t = this._elements;
|
|
3048
|
-
return new
|
|
3521
|
+
return new c(function* () {
|
|
3049
3522
|
for (const [e, n] of t)
|
|
3050
3523
|
yield n;
|
|
3051
3524
|
});
|
|
@@ -3056,6 +3529,9 @@ const w = class w {
|
|
|
3056
3529
|
*
|
|
3057
3530
|
* If the iterator is infinite, the method will never return.
|
|
3058
3531
|
*
|
|
3532
|
+
* ---
|
|
3533
|
+
*
|
|
3534
|
+
* @example
|
|
3059
3535
|
* ```ts
|
|
3060
3536
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
3061
3537
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -3063,6 +3539,8 @@ const w = class w {
|
|
|
3063
3539
|
* console.log(aggregator.toArray()); // [[-3, -1, 3, 5], [0, 2, 6, 8]]
|
|
3064
3540
|
* ```
|
|
3065
3541
|
*
|
|
3542
|
+
* ---
|
|
3543
|
+
*
|
|
3066
3544
|
* @returns An {@link Array} of arrays containing the elements of the iterator.
|
|
3067
3545
|
*/
|
|
3068
3546
|
toArray() {
|
|
@@ -3075,6 +3553,9 @@ const w = class w {
|
|
|
3075
3553
|
*
|
|
3076
3554
|
* If the iterator is infinite, the method will never return.
|
|
3077
3555
|
*
|
|
3556
|
+
* ---
|
|
3557
|
+
*
|
|
3558
|
+
* @example
|
|
3078
3559
|
* ```ts
|
|
3079
3560
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
3080
3561
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -3082,6 +3563,8 @@ const w = class w {
|
|
|
3082
3563
|
* console.log(aggregator.toMap()); // Map(2) { "odd" => [-3, -1, 3, 5], "even" => [0, 2, 6, 8] }
|
|
3083
3564
|
* ```
|
|
3084
3565
|
*
|
|
3566
|
+
* ---
|
|
3567
|
+
*
|
|
3085
3568
|
* @returns A {@link Map} containing the elements of the iterator.
|
|
3086
3569
|
*/
|
|
3087
3570
|
toMap() {
|
|
@@ -3098,6 +3581,9 @@ const w = class w {
|
|
|
3098
3581
|
*
|
|
3099
3582
|
* If the iterator is infinite, the method will never return.
|
|
3100
3583
|
*
|
|
3584
|
+
* ---
|
|
3585
|
+
*
|
|
3586
|
+
* @example
|
|
3101
3587
|
* ```ts
|
|
3102
3588
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
3103
3589
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -3105,6 +3591,8 @@ const w = class w {
|
|
|
3105
3591
|
* console.log(aggregator.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
3106
3592
|
* ```
|
|
3107
3593
|
*
|
|
3594
|
+
* ---
|
|
3595
|
+
*
|
|
3108
3596
|
* @returns An {@link Object} containing the elements of the iterator.
|
|
3109
3597
|
*/
|
|
3110
3598
|
toObject() {
|
|
@@ -3116,7 +3604,7 @@ const w = class w {
|
|
|
3116
3604
|
return t;
|
|
3117
3605
|
}
|
|
3118
3606
|
};
|
|
3119
|
-
let g =
|
|
3607
|
+
let g = m;
|
|
3120
3608
|
const Le = Function;
|
|
3121
3609
|
var pe, be;
|
|
3122
3610
|
class Ge extends (be = Le, pe = Symbol.toStringTag, be) {
|
|
@@ -3136,6 +3624,9 @@ class E {
|
|
|
3136
3624
|
/**
|
|
3137
3625
|
* Initializes a new instance of the {@link Publisher} class.
|
|
3138
3626
|
*
|
|
3627
|
+
* ---
|
|
3628
|
+
*
|
|
3629
|
+
* @example
|
|
3139
3630
|
* ```ts
|
|
3140
3631
|
* const publisher = new Publisher();
|
|
3141
3632
|
* ```
|
|
@@ -3154,6 +3645,9 @@ class E {
|
|
|
3154
3645
|
/**
|
|
3155
3646
|
* Unsubscribes all the subscribers from all the events.
|
|
3156
3647
|
*
|
|
3648
|
+
* ---
|
|
3649
|
+
*
|
|
3650
|
+
* @example
|
|
3157
3651
|
* ```ts
|
|
3158
3652
|
* publisher.subscribe("player:spawn", (evt) => { [...] });
|
|
3159
3653
|
* publisher.subscribe("player:move", (coords) => { [...] });
|
|
@@ -3174,6 +3668,9 @@ class E {
|
|
|
3174
3668
|
/**
|
|
3175
3669
|
* Publishes an event to all the subscribers.
|
|
3176
3670
|
*
|
|
3671
|
+
* ---
|
|
3672
|
+
*
|
|
3673
|
+
* @example
|
|
3177
3674
|
* ```ts
|
|
3178
3675
|
* publisher.subscribe("player:move", (coords) => { [...] });
|
|
3179
3676
|
* publisher.subscribe("player:move", ({ x, y }) => { [...] });
|
|
@@ -3182,6 +3679,8 @@ class E {
|
|
|
3182
3679
|
* publisher.publish("player:move", { x: 10, y: 20 });
|
|
3183
3680
|
* ```
|
|
3184
3681
|
*
|
|
3682
|
+
* ---
|
|
3683
|
+
*
|
|
3185
3684
|
* @template K The key of the map containing the callback signature to publish.
|
|
3186
3685
|
*
|
|
3187
3686
|
* @param event The name of the event to publish.
|
|
@@ -3196,6 +3695,9 @@ class E {
|
|
|
3196
3695
|
/**
|
|
3197
3696
|
* Subscribes a new subscriber to an event.
|
|
3198
3697
|
*
|
|
3698
|
+
* ---
|
|
3699
|
+
*
|
|
3700
|
+
* @example
|
|
3199
3701
|
* ```ts
|
|
3200
3702
|
* let unsubscribe: () => void;
|
|
3201
3703
|
* publisher.subscribe("player:death", unsubscribe);
|
|
@@ -3205,6 +3707,8 @@ class E {
|
|
|
3205
3707
|
* });
|
|
3206
3708
|
* ```
|
|
3207
3709
|
*
|
|
3710
|
+
* ---
|
|
3711
|
+
*
|
|
3208
3712
|
* @template K The key of the map containing the callback signature to subscribe.
|
|
3209
3713
|
*
|
|
3210
3714
|
* @param event The name of the event to subscribe to.
|
|
@@ -3225,6 +3729,9 @@ class E {
|
|
|
3225
3729
|
/**
|
|
3226
3730
|
* Unsubscribes a subscriber from an event.
|
|
3227
3731
|
*
|
|
3732
|
+
* ---
|
|
3733
|
+
*
|
|
3734
|
+
* @example
|
|
3228
3735
|
* ```ts
|
|
3229
3736
|
* const onPlayerMove = ({ x, y }: Point) => { [...] };
|
|
3230
3737
|
*
|
|
@@ -3232,6 +3739,8 @@ class E {
|
|
|
3232
3739
|
* publisher.subscribe("player:death", () => publisher.unsubscribe("player:move", onPlayerMove));
|
|
3233
3740
|
* ```
|
|
3234
3741
|
*
|
|
3742
|
+
* ---
|
|
3743
|
+
*
|
|
3235
3744
|
* @template K The key of the map containing the callback signature to unsubscribe.
|
|
3236
3745
|
*
|
|
3237
3746
|
* @param event The name of the event to unsubscribe from.
|
|
@@ -3247,21 +3756,11 @@ class E {
|
|
|
3247
3756
|
n.splice(s, 1);
|
|
3248
3757
|
}
|
|
3249
3758
|
}
|
|
3759
|
+
const Ke = () => {
|
|
3760
|
+
};
|
|
3250
3761
|
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
|
-
};
|
|
3762
|
+
class it extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
3763
|
+
constructor(e, n = "default") {
|
|
3265
3764
|
super();
|
|
3266
3765
|
/**
|
|
3267
3766
|
* The currently selected implementation of the callback.
|
|
@@ -3294,7 +3793,11 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3294
3793
|
*/
|
|
3295
3794
|
a(this, "_invoke");
|
|
3296
3795
|
a(this, ge, "SwitchableCallback");
|
|
3297
|
-
this.
|
|
3796
|
+
this._callbacks = /* @__PURE__ */ new Map(), this._isEnabled = !0, e ? this._callbacks.set(n, e) : (n = "", e = () => {
|
|
3797
|
+
throw new Be(
|
|
3798
|
+
"The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
|
|
3799
|
+
);
|
|
3800
|
+
}), this._key = n, this._callback = e, this._invoke = (...s) => this._callback(...s);
|
|
3298
3801
|
}
|
|
3299
3802
|
/**
|
|
3300
3803
|
* A flag indicating whether the callback is enabled or not.
|
|
@@ -3316,27 +3819,46 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3316
3819
|
*
|
|
3317
3820
|
* Also note that:
|
|
3318
3821
|
* - If any implementation has been registered yet, a {@link KeyException} will be thrown.
|
|
3822
|
+
* - If any key is given and it doesn't have any associated
|
|
3823
|
+
* implementation yet, a {@link KeyException} will be thrown.
|
|
3319
3824
|
* - If the callback is already enabled, a {@link RuntimeException} will be thrown.
|
|
3320
3825
|
*
|
|
3826
|
+
* ---
|
|
3827
|
+
*
|
|
3828
|
+
* @example
|
|
3321
3829
|
* ```ts
|
|
3322
3830
|
* window.addEventListener("pointerdown", () => { onPointerMove.enable(); });
|
|
3323
3831
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3324
3832
|
* ```
|
|
3833
|
+
*
|
|
3834
|
+
* ---
|
|
3835
|
+
*
|
|
3836
|
+
* @param key
|
|
3837
|
+
* The key that is associated with the implementation to enable. Default is the currently selected implementation.
|
|
3325
3838
|
*/
|
|
3326
|
-
enable() {
|
|
3327
|
-
if (
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3839
|
+
enable(e) {
|
|
3840
|
+
if (e === void 0) {
|
|
3841
|
+
if (!this._key)
|
|
3842
|
+
throw new _(
|
|
3843
|
+
"The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
|
|
3844
|
+
);
|
|
3845
|
+
e = this._key;
|
|
3846
|
+
} else if (e) {
|
|
3847
|
+
if (!this._callbacks.has(e))
|
|
3848
|
+
throw new _(`The key '${e}' doesn't yet have any associated callback.`);
|
|
3849
|
+
} else throw new _("The key must be a non-empty string.");
|
|
3331
3850
|
if (this._isEnabled)
|
|
3332
3851
|
throw new y("The `SwitchableCallback` is already enabled.");
|
|
3333
|
-
this._callback = this._callbacks.get(
|
|
3852
|
+
this._callback = this._callbacks.get(e), this._isEnabled = !0;
|
|
3334
3853
|
}
|
|
3335
3854
|
/**
|
|
3336
3855
|
* Disables the callback, allowing it to be invoked without executing any implementation.
|
|
3337
3856
|
*
|
|
3338
3857
|
* If the callback is already disabled, a {@link RuntimeException} will be thrown.
|
|
3339
3858
|
*
|
|
3859
|
+
* ---
|
|
3860
|
+
*
|
|
3861
|
+
* @example
|
|
3340
3862
|
* ```ts
|
|
3341
3863
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3342
3864
|
* window.addEventListener("pointerup", () => { onPointerMove.disable(); });
|
|
@@ -3345,8 +3867,7 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3345
3867
|
disable() {
|
|
3346
3868
|
if (!this._isEnabled)
|
|
3347
3869
|
throw new y("The `SwitchableCallback` is already disabled.");
|
|
3348
|
-
this._callback =
|
|
3349
|
-
}, this._isEnabled = !1;
|
|
3870
|
+
this._callback = Ke, this._isEnabled = !1;
|
|
3350
3871
|
}
|
|
3351
3872
|
/**
|
|
3352
3873
|
* Registers a new implementation for the callback.
|
|
@@ -3355,11 +3876,16 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3355
3876
|
* - If the callback has no other implementation registered yet, this one will be selected as default.
|
|
3356
3877
|
* - If the key has already been used for another implementation, a {@link KeyException} will be thrown.
|
|
3357
3878
|
*
|
|
3879
|
+
* ---
|
|
3880
|
+
*
|
|
3881
|
+
* @example
|
|
3358
3882
|
* ```ts
|
|
3359
3883
|
* onPointerMove.register("pressed", () => { [...] });
|
|
3360
3884
|
* onPointerMove.register("released", () => { [...] });
|
|
3361
3885
|
* ```
|
|
3362
3886
|
*
|
|
3887
|
+
* ---
|
|
3888
|
+
*
|
|
3363
3889
|
* @param key The key that will be associated with the implementation.
|
|
3364
3890
|
* @param callback The implementation to register.
|
|
3365
3891
|
*/
|
|
@@ -3367,7 +3893,7 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3367
3893
|
if (this._callbacks.size === 0)
|
|
3368
3894
|
this._key = e, this._callback = n;
|
|
3369
3895
|
else if (this._callbacks.has(e))
|
|
3370
|
-
throw new
|
|
3896
|
+
throw new _(`The key '${e}' has already been used for another callback.`);
|
|
3371
3897
|
this._callbacks.set(e, n);
|
|
3372
3898
|
}
|
|
3373
3899
|
/**
|
|
@@ -3377,17 +3903,22 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3377
3903
|
* - If the key is the currently selected implementation, a {@link KeyException} will be thrown.
|
|
3378
3904
|
* - If the key has no associated implementation yet, a {@link KeyException} will be thrown.
|
|
3379
3905
|
*
|
|
3906
|
+
* ---
|
|
3907
|
+
*
|
|
3908
|
+
* @example
|
|
3380
3909
|
* ```ts
|
|
3381
3910
|
* onPointerMove.unregister("released");
|
|
3382
3911
|
* ```
|
|
3383
3912
|
*
|
|
3913
|
+
* ---
|
|
3914
|
+
*
|
|
3384
3915
|
* @param key The key that is associated with the implementation to unregister.
|
|
3385
3916
|
*/
|
|
3386
3917
|
unregister(e) {
|
|
3387
3918
|
if (this._key === e)
|
|
3388
|
-
throw new
|
|
3919
|
+
throw new _("Unable to unregister the currently selected callback.");
|
|
3389
3920
|
if (!this._callbacks.has(e))
|
|
3390
|
-
throw new
|
|
3921
|
+
throw new _(`The key '${e}' doesn't yet have any associated callback.`);
|
|
3391
3922
|
this._callbacks.delete(e);
|
|
3392
3923
|
}
|
|
3393
3924
|
/**
|
|
@@ -3395,31 +3926,41 @@ class rt extends (ve = Ge, ge = Symbol.toStringTag, ve) {
|
|
|
3395
3926
|
*
|
|
3396
3927
|
* If the key has no associated implementation yet, a {@link KeyException} will be thrown.
|
|
3397
3928
|
*
|
|
3929
|
+
* ---
|
|
3930
|
+
*
|
|
3931
|
+
* @example
|
|
3398
3932
|
* ```ts
|
|
3399
3933
|
* window.addEventListener("pointerdown", () => { onPointerMove.switch("pressed"); });
|
|
3400
3934
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3401
3935
|
* window.addEventListener("pointerup", () => { onPointerMove.switch("released"); });
|
|
3402
3936
|
* ```
|
|
3403
3937
|
*
|
|
3938
|
+
* ---
|
|
3939
|
+
*
|
|
3404
3940
|
* @param key The key that is associated with the implementation to switch to.
|
|
3405
3941
|
*/
|
|
3406
3942
|
switch(e) {
|
|
3407
3943
|
if (!this._callbacks.has(e))
|
|
3408
|
-
throw new
|
|
3409
|
-
this._key = e, this._isEnabled && (this._callback = this._callbacks.get(e));
|
|
3944
|
+
throw new _(`The key '${e}' doesn't yet have any associated callback.`);
|
|
3945
|
+
this._key !== e && (this._key = e, this._isEnabled && (this._callback = this._callbacks.get(e)));
|
|
3410
3946
|
}
|
|
3411
3947
|
}
|
|
3412
3948
|
var ke;
|
|
3413
3949
|
ke = Symbol.toStringTag;
|
|
3414
|
-
class
|
|
3950
|
+
class ot {
|
|
3415
3951
|
/**
|
|
3416
3952
|
* Initializes a new instance of the {@link JSONStorage} class.
|
|
3417
3953
|
* It cannot be instantiated outside of a browser environment or an {@link EnvironmentException} is thrown.
|
|
3418
3954
|
*
|
|
3955
|
+
* ---
|
|
3956
|
+
*
|
|
3957
|
+
* @example
|
|
3419
3958
|
* ```ts
|
|
3420
3959
|
* const jsonStorage = new JSONStorage();
|
|
3421
3960
|
* ```
|
|
3422
3961
|
*
|
|
3962
|
+
* ---
|
|
3963
|
+
*
|
|
3423
3964
|
* @param preferPersistence
|
|
3424
3965
|
* Whether to prefer the {@link localStorage} over the {@link sessionStorage} when calling an ambivalent method.
|
|
3425
3966
|
* If omitted, it defaults to `true` to prefer the persistent storage.
|
|
@@ -3479,6 +4020,9 @@ class it {
|
|
|
3479
4020
|
/**
|
|
3480
4021
|
* Checks whether the value with the specified key exists within the default storage.
|
|
3481
4022
|
*
|
|
4023
|
+
* ---
|
|
4024
|
+
*
|
|
4025
|
+
* @example
|
|
3482
4026
|
* ```ts
|
|
3483
4027
|
* if (jsonStorage.has("key"))
|
|
3484
4028
|
* {
|
|
@@ -3486,6 +4030,8 @@ class it {
|
|
|
3486
4030
|
* }
|
|
3487
4031
|
* ```
|
|
3488
4032
|
*
|
|
4033
|
+
* ---
|
|
4034
|
+
*
|
|
3489
4035
|
* @param key The key of the value to check.
|
|
3490
4036
|
* @param persistent
|
|
3491
4037
|
* Whether to prefer the persistent {@link localStorage} over the volatile {@link sessionStorage}.
|
|
@@ -3499,6 +4045,9 @@ class it {
|
|
|
3499
4045
|
/**
|
|
3500
4046
|
* Checks whether the value with the specified key exists within the volatile {@link sessionStorage}.
|
|
3501
4047
|
*
|
|
4048
|
+
* ---
|
|
4049
|
+
*
|
|
4050
|
+
* @example
|
|
3502
4051
|
* ```ts
|
|
3503
4052
|
* if (jsonStorage.knows("key"))
|
|
3504
4053
|
* {
|
|
@@ -3506,6 +4055,8 @@ class it {
|
|
|
3506
4055
|
* }
|
|
3507
4056
|
* ```
|
|
3508
4057
|
*
|
|
4058
|
+
* ---
|
|
4059
|
+
*
|
|
3509
4060
|
* @param key The key of the value to check.
|
|
3510
4061
|
*
|
|
3511
4062
|
* @returns `true` if the key exists, `false` otherwise.
|
|
@@ -3517,6 +4068,9 @@ class it {
|
|
|
3517
4068
|
* Checks whether the value with the specified key exists looking first in the
|
|
3518
4069
|
* volatile {@link sessionStorage} and then, if not found, in the persistent {@link localStorage}.
|
|
3519
4070
|
*
|
|
4071
|
+
* ---
|
|
4072
|
+
*
|
|
4073
|
+
* @example
|
|
3520
4074
|
* ```ts
|
|
3521
4075
|
* if (jsonStorage.find("key"))
|
|
3522
4076
|
* {
|
|
@@ -3524,6 +4078,8 @@ class it {
|
|
|
3524
4078
|
* }
|
|
3525
4079
|
* ```
|
|
3526
4080
|
*
|
|
4081
|
+
* ---
|
|
4082
|
+
*
|
|
3527
4083
|
* @param key The key of the value to check.
|
|
3528
4084
|
*
|
|
3529
4085
|
* @returns `true` if the key exists, `false` otherwise.
|
|
@@ -3534,6 +4090,9 @@ class it {
|
|
|
3534
4090
|
/**
|
|
3535
4091
|
* Checks whether the value with the specified key exists within the persistent {@link localStorage}.
|
|
3536
4092
|
*
|
|
4093
|
+
* ---
|
|
4094
|
+
*
|
|
4095
|
+
* @example
|
|
3537
4096
|
* ```ts
|
|
3538
4097
|
* if (jsonStorage.exists("key"))
|
|
3539
4098
|
* {
|
|
@@ -3541,6 +4100,8 @@ class it {
|
|
|
3541
4100
|
* }
|
|
3542
4101
|
* ```
|
|
3543
4102
|
*
|
|
4103
|
+
* ---
|
|
4104
|
+
*
|
|
3544
4105
|
* @param key The key of the value to check.
|
|
3545
4106
|
*
|
|
3546
4107
|
* @returns `true` if the key exists, `false` otherwise.
|
|
@@ -3552,12 +4113,17 @@ class it {
|
|
|
3552
4113
|
* Sets the value with the specified key in the default storage.
|
|
3553
4114
|
* If the value is `undefined` or omitted, the key is removed from the storage.
|
|
3554
4115
|
*
|
|
4116
|
+
* ---
|
|
4117
|
+
*
|
|
4118
|
+
* @example
|
|
3555
4119
|
* ```ts
|
|
3556
4120
|
* jsonStorage.set("key");
|
|
3557
4121
|
* jsonStorage.set("key", value);
|
|
3558
4122
|
* jsonStorage.set("key", obj?.value);
|
|
3559
4123
|
* ```
|
|
3560
4124
|
*
|
|
4125
|
+
* ---
|
|
4126
|
+
*
|
|
3561
4127
|
* @template T The type of the value to set.
|
|
3562
4128
|
*
|
|
3563
4129
|
* @param key The key of the value to set.
|
|
@@ -3574,12 +4140,17 @@ class it {
|
|
|
3574
4140
|
* Sets the value with the specified key in the volatile {@link sessionStorage}.
|
|
3575
4141
|
* If the value is `undefined` or omitted, the key is removed from the storage.
|
|
3576
4142
|
*
|
|
4143
|
+
* ---
|
|
4144
|
+
*
|
|
4145
|
+
* @example
|
|
3577
4146
|
* ```ts
|
|
3578
4147
|
* jsonStorage.remember("key");
|
|
3579
4148
|
* jsonStorage.remember("key", value);
|
|
3580
4149
|
* jsonStorage.remember("key", obj?.value);
|
|
3581
4150
|
* ```
|
|
3582
4151
|
*
|
|
4152
|
+
* ---
|
|
4153
|
+
*
|
|
3583
4154
|
* @template T The type of the value to set.
|
|
3584
4155
|
*
|
|
3585
4156
|
* @param key The key of the value to set.
|
|
@@ -3592,12 +4163,17 @@ class it {
|
|
|
3592
4163
|
* Sets the value with the specified key in the persistent {@link localStorage}.
|
|
3593
4164
|
* If the value is `undefined` or omitted, the key is removed from the storage.
|
|
3594
4165
|
*
|
|
4166
|
+
* ---
|
|
4167
|
+
*
|
|
4168
|
+
* @example
|
|
3595
4169
|
* ```ts
|
|
3596
4170
|
* jsonStorage.write("key");
|
|
3597
4171
|
* jsonStorage.write("key", value);
|
|
3598
4172
|
* jsonStorage.write("key", obj?.value);
|
|
3599
4173
|
* ```
|
|
3600
4174
|
*
|
|
4175
|
+
* ---
|
|
4176
|
+
*
|
|
3601
4177
|
* @template T The type of the value to set.
|
|
3602
4178
|
*
|
|
3603
4179
|
* @param key The key of the value to set.
|
|
@@ -3609,10 +4185,15 @@ class it {
|
|
|
3609
4185
|
/**
|
|
3610
4186
|
* Removes the value with the specified key from the default storage.
|
|
3611
4187
|
*
|
|
4188
|
+
* ---
|
|
4189
|
+
*
|
|
4190
|
+
* @example
|
|
3612
4191
|
* ```ts
|
|
3613
4192
|
* jsonStorage.delete("key");
|
|
3614
4193
|
* ```
|
|
3615
4194
|
*
|
|
4195
|
+
* ---
|
|
4196
|
+
*
|
|
3616
4197
|
* @param key The key of the value to remove.
|
|
3617
4198
|
* @param persistent
|
|
3618
4199
|
* Whether to prefer the persistent {@link localStorage} over the volatile {@link sessionStorage}.
|
|
@@ -3624,10 +4205,15 @@ class it {
|
|
|
3624
4205
|
/**
|
|
3625
4206
|
* Removes the value with the specified key from the volatile {@link sessionStorage}.
|
|
3626
4207
|
*
|
|
4208
|
+
* ---
|
|
4209
|
+
*
|
|
4210
|
+
* @example
|
|
3627
4211
|
* ```ts
|
|
3628
4212
|
* jsonStorage.forget("key");
|
|
3629
4213
|
* ```
|
|
3630
4214
|
*
|
|
4215
|
+
* ---
|
|
4216
|
+
*
|
|
3631
4217
|
* @param key The key of the value to remove.
|
|
3632
4218
|
*/
|
|
3633
4219
|
forget(t) {
|
|
@@ -3636,10 +4222,15 @@ class it {
|
|
|
3636
4222
|
/**
|
|
3637
4223
|
* Removes the value with the specified key from the persistent {@link localStorage}.
|
|
3638
4224
|
*
|
|
4225
|
+
* ---
|
|
4226
|
+
*
|
|
4227
|
+
* @example
|
|
3639
4228
|
* ```ts
|
|
3640
4229
|
* jsonStorage.erase("key");
|
|
3641
4230
|
* ```
|
|
3642
4231
|
*
|
|
4232
|
+
* ---
|
|
4233
|
+
*
|
|
3643
4234
|
* @param key The key of the value to remove.
|
|
3644
4235
|
*/
|
|
3645
4236
|
erase(t) {
|
|
@@ -3649,10 +4240,15 @@ class it {
|
|
|
3649
4240
|
* Removes the value with the specified key from both the
|
|
3650
4241
|
* volatile {@link sessionStorage} and the persistent {@link localStorage}.
|
|
3651
4242
|
*
|
|
4243
|
+
* ---
|
|
4244
|
+
*
|
|
4245
|
+
* @example
|
|
3652
4246
|
* ```ts
|
|
3653
4247
|
* jsonStorage.clear("key");
|
|
3654
4248
|
* ```
|
|
3655
4249
|
*
|
|
4250
|
+
* ---
|
|
4251
|
+
*
|
|
3656
4252
|
* @param key The key of the value to remove.
|
|
3657
4253
|
*/
|
|
3658
4254
|
clear(t) {
|
|
@@ -3665,6 +4261,9 @@ const R = class R {
|
|
|
3665
4261
|
/**
|
|
3666
4262
|
* Initializes a new instance of the {@link SmartPromise} class.
|
|
3667
4263
|
*
|
|
4264
|
+
* ---
|
|
4265
|
+
*
|
|
4266
|
+
* @example
|
|
3668
4267
|
* ```ts
|
|
3669
4268
|
* const promise = new SmartPromise<string>((resolve, reject) =>
|
|
3670
4269
|
* {
|
|
@@ -3672,6 +4271,8 @@ const R = class R {
|
|
|
3672
4271
|
* });
|
|
3673
4272
|
* ```
|
|
3674
4273
|
*
|
|
4274
|
+
* ---
|
|
4275
|
+
*
|
|
3675
4276
|
* @param executor
|
|
3676
4277
|
* The function responsible for eventually resolving or rejecting the promise.
|
|
3677
4278
|
* Similarly to the native {@link Promise} object, it's immediately executed after the promise is created.
|
|
@@ -3712,6 +4313,9 @@ const R = class R {
|
|
|
3712
4313
|
/**
|
|
3713
4314
|
* Wraps a new {@link SmartPromise} object around an existing native {@link Promise} object.
|
|
3714
4315
|
*
|
|
4316
|
+
* ---
|
|
4317
|
+
*
|
|
4318
|
+
* @example
|
|
3715
4319
|
* ```ts
|
|
3716
4320
|
* const request = fetch("https://api.example.com/data");
|
|
3717
4321
|
* const smartRequest = SmartPromise.FromPromise(request);
|
|
@@ -3723,6 +4327,8 @@ const R = class R {
|
|
|
3723
4327
|
* console.log(smartRequest.isFulfilled); // true
|
|
3724
4328
|
* ```
|
|
3725
4329
|
*
|
|
4330
|
+
* ---
|
|
4331
|
+
*
|
|
3726
4332
|
* @param promise The promise to wrap.
|
|
3727
4333
|
*
|
|
3728
4334
|
* @returns A new {@link SmartPromise} object that wraps the provided promise.
|
|
@@ -3757,6 +4363,9 @@ const R = class R {
|
|
|
3757
4363
|
/**
|
|
3758
4364
|
* Attaches a callback that executes right after the promise is settled, regardless of the outcome.
|
|
3759
4365
|
*
|
|
4366
|
+
* ---
|
|
4367
|
+
*
|
|
4368
|
+
* @example
|
|
3760
4369
|
* ```ts
|
|
3761
4370
|
* const promise = new SmartPromise((resolve, reject) =>
|
|
3762
4371
|
* {
|
|
@@ -3771,6 +4380,8 @@ const R = class R {
|
|
|
3771
4380
|
* .finally(() => console.log("Done!")); // Always logs "Done!".
|
|
3772
4381
|
* ```
|
|
3773
4382
|
*
|
|
4383
|
+
* ---
|
|
4384
|
+
*
|
|
3774
4385
|
* @param onFinally The callback to execute when once promise is settled.
|
|
3775
4386
|
*
|
|
3776
4387
|
* @returns A new {@link Promise} that executes the callback once the promise is settled.
|
|
@@ -3781,14 +4392,19 @@ const R = class R {
|
|
|
3781
4392
|
};
|
|
3782
4393
|
let k = R;
|
|
3783
4394
|
var Te, Ee;
|
|
3784
|
-
class
|
|
4395
|
+
class He extends (Ee = k, Te = Symbol.toStringTag, Ee) {
|
|
3785
4396
|
/**
|
|
3786
4397
|
* Initializes a new instance of the {@link DeferredPromise} class.
|
|
3787
4398
|
*
|
|
4399
|
+
* ---
|
|
4400
|
+
*
|
|
4401
|
+
* @example
|
|
3788
4402
|
* ```ts
|
|
3789
4403
|
* const promise = new DeferredPromise<string, string[]>((value: string) => value.split(" "));
|
|
3790
4404
|
* ```
|
|
3791
4405
|
*
|
|
4406
|
+
* ---
|
|
4407
|
+
*
|
|
3792
4408
|
* @param onFulfilled The callback to execute once the promise is fulfilled.
|
|
3793
4409
|
* @param onRejected The callback to execute once the promise is rejected.
|
|
3794
4410
|
*/
|
|
@@ -3829,6 +4445,9 @@ class Ke extends (Ee = k, Te = Symbol.toStringTag, Ee) {
|
|
|
3829
4445
|
/**
|
|
3830
4446
|
* Watches another promise and resolves or rejects this promise when the other one is settled.
|
|
3831
4447
|
*
|
|
4448
|
+
* ---
|
|
4449
|
+
*
|
|
4450
|
+
* @example
|
|
3832
4451
|
* ```ts
|
|
3833
4452
|
* const promise = new Promise<string>((resolve) => setTimeout(() => resolve("Hello, World!"), 1_000));
|
|
3834
4453
|
* const deferred = new DeferredPromise<string, string[]>((value: string) => value.split(" "));
|
|
@@ -3837,6 +4456,8 @@ class Ke extends (Ee = k, Te = Symbol.toStringTag, Ee) {
|
|
|
3837
4456
|
* deferred.watch(promise);
|
|
3838
4457
|
* ```
|
|
3839
4458
|
*
|
|
4459
|
+
* ---
|
|
4460
|
+
*
|
|
3840
4461
|
* @param otherPromise The promise to watch.
|
|
3841
4462
|
*
|
|
3842
4463
|
* @returns The current instance of the {@link DeferredPromise} class.
|
|
@@ -3846,10 +4467,13 @@ class Ke extends (Ee = k, Te = Symbol.toStringTag, Ee) {
|
|
|
3846
4467
|
}
|
|
3847
4468
|
}
|
|
3848
4469
|
var Me, Re;
|
|
3849
|
-
class
|
|
4470
|
+
class at extends (Re = k, Me = Symbol.toStringTag, Re) {
|
|
3850
4471
|
/**
|
|
3851
4472
|
* Initializes a new instance of the {@link TimedPromise} class.
|
|
3852
4473
|
*
|
|
4474
|
+
* ---
|
|
4475
|
+
*
|
|
4476
|
+
* @example
|
|
3853
4477
|
* ```ts
|
|
3854
4478
|
* const promise = new TimedPromise<string>((resolve, reject) =>
|
|
3855
4479
|
* {
|
|
@@ -3858,6 +4482,8 @@ class ot extends (Re = k, Me = Symbol.toStringTag, Re) {
|
|
|
3858
4482
|
* }, 5_000);
|
|
3859
4483
|
* ```
|
|
3860
4484
|
*
|
|
4485
|
+
* ---
|
|
4486
|
+
*
|
|
3861
4487
|
* @param executor
|
|
3862
4488
|
* The function responsible for eventually resolving or rejecting the promise.
|
|
3863
4489
|
* Similarly to the native {@link Promise} object, it's immediately executed after the promise is created.
|
|
@@ -3876,28 +4502,28 @@ class ot extends (Re = k, Me = Symbol.toStringTag, Re) {
|
|
|
3876
4502
|
a(this, Me, "TimedPromise");
|
|
3877
4503
|
}
|
|
3878
4504
|
}
|
|
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
|
|
4505
|
+
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 || {});
|
|
4506
|
+
function lt(i, t, e = 864e5) {
|
|
3881
4507
|
let n;
|
|
3882
4508
|
return i = new Date(i), t = new Date(t), i < t ? n = Math.floor : n = Math.ceil, n((t.getTime() - i.getTime()) / e);
|
|
3883
4509
|
}
|
|
3884
|
-
function
|
|
3885
|
-
if (i >= t)
|
|
3886
|
-
throw new
|
|
3887
|
-
return new
|
|
3888
|
-
const n =
|
|
3889
|
-
let s =
|
|
4510
|
+
function ct(i, t, e = 864e5) {
|
|
4511
|
+
if (i = new Date(i), t = new Date(t), i >= t)
|
|
4512
|
+
throw new b("The end date must be greater than the start date.");
|
|
4513
|
+
return new c(function* () {
|
|
4514
|
+
const n = t.getTime();
|
|
4515
|
+
let s = i.getTime();
|
|
3890
4516
|
for (; s < n; )
|
|
3891
4517
|
yield new Date(s), s += e;
|
|
3892
4518
|
});
|
|
3893
4519
|
}
|
|
3894
|
-
function
|
|
4520
|
+
function Ve(i, t = 864e5) {
|
|
3895
4521
|
if (t <= 1)
|
|
3896
|
-
throw new
|
|
4522
|
+
throw new b(
|
|
3897
4523
|
"Rounding a timestamp by milliseconds or less makes no sense.Use the timestamp value directly instead."
|
|
3898
4524
|
);
|
|
3899
4525
|
if (t > 864e5)
|
|
3900
|
-
throw new
|
|
4526
|
+
throw new b(
|
|
3901
4527
|
"Rounding by more than a day leads to unexpected results. Consider using other methods to round dates by weeks, months or years."
|
|
3902
4528
|
);
|
|
3903
4529
|
return i = new Date(i), new Date(Math.floor(i.getTime() / t) * t);
|
|
@@ -3905,7 +4531,7 @@ function Qe(i, t = 864e5) {
|
|
|
3905
4531
|
function ut(i, t = 0) {
|
|
3906
4532
|
i = new Date(i);
|
|
3907
4533
|
const e = 7 - t, n = (i.getUTCDay() + e) % 7, s = i.getTime() - 864e5 * n;
|
|
3908
|
-
return
|
|
4534
|
+
return Ve(new Date(s));
|
|
3909
4535
|
}
|
|
3910
4536
|
var Fe;
|
|
3911
4537
|
Fe = Symbol.toStringTag;
|
|
@@ -3913,10 +4539,15 @@ class qe {
|
|
|
3913
4539
|
/**
|
|
3914
4540
|
* Initializes a new instance of the {@link GameLoop} class.
|
|
3915
4541
|
*
|
|
4542
|
+
* ---
|
|
4543
|
+
*
|
|
4544
|
+
* @example
|
|
3916
4545
|
* ```ts
|
|
3917
4546
|
* const loop = new GameLoop((elapsedTime: number) => { [...] });
|
|
3918
4547
|
* ```
|
|
3919
4548
|
*
|
|
4549
|
+
* ---
|
|
4550
|
+
*
|
|
3920
4551
|
* @param callback The function that will be executed at each iteration of the game loop.
|
|
3921
4552
|
* @param msIfNotBrowser
|
|
3922
4553
|
* The interval in milliseconds that will be used if the current environment isn't a browser. Default is `40`.
|
|
@@ -3996,11 +4627,16 @@ class qe {
|
|
|
3996
4627
|
*
|
|
3997
4628
|
* If the game loop is already running, a {@link RuntimeException} will be thrown.
|
|
3998
4629
|
*
|
|
4630
|
+
* ---
|
|
4631
|
+
*
|
|
4632
|
+
* @example
|
|
3999
4633
|
* ```ts
|
|
4000
4634
|
* loop.onStart(() => { [...] }); // This callback will be executed.
|
|
4001
4635
|
* loop.start();
|
|
4002
4636
|
* ```
|
|
4003
4637
|
*
|
|
4638
|
+
* ---
|
|
4639
|
+
*
|
|
4004
4640
|
* @param elapsedTime The elapsed time to set as default when the game loop starts. Default is `0`.
|
|
4005
4641
|
*/
|
|
4006
4642
|
start(t = 0) {
|
|
@@ -4013,6 +4649,9 @@ class qe {
|
|
|
4013
4649
|
*
|
|
4014
4650
|
* If the game loop hasn't yet started, a {@link RuntimeException} will be thrown.
|
|
4015
4651
|
*
|
|
4652
|
+
* ---
|
|
4653
|
+
*
|
|
4654
|
+
* @example
|
|
4016
4655
|
* ```ts
|
|
4017
4656
|
* loop.onStop(() => { [...] }); // This callback will be executed.
|
|
4018
4657
|
* loop.stop();
|
|
@@ -4028,10 +4667,15 @@ class qe {
|
|
|
4028
4667
|
/**
|
|
4029
4668
|
* Subscribes to the `start` event of the game loop.
|
|
4030
4669
|
*
|
|
4670
|
+
* ---
|
|
4671
|
+
*
|
|
4672
|
+
* @example
|
|
4031
4673
|
* ```ts
|
|
4032
4674
|
* loop.onStart(() => { console.log("The game loop has started."); });
|
|
4033
4675
|
* ```
|
|
4034
4676
|
*
|
|
4677
|
+
* ---
|
|
4678
|
+
*
|
|
4035
4679
|
* @param callback The function that will be executed when the game loop starts.
|
|
4036
4680
|
*
|
|
4037
4681
|
* @returns A function that can be used to unsubscribe from the event.
|
|
@@ -4042,10 +4686,15 @@ class qe {
|
|
|
4042
4686
|
/**
|
|
4043
4687
|
* Subscribes to the `stop` event of the game loop.
|
|
4044
4688
|
*
|
|
4689
|
+
* ---
|
|
4690
|
+
*
|
|
4691
|
+
* @example
|
|
4045
4692
|
* ```ts
|
|
4046
4693
|
* loop.onStop(() => { console.log("The game loop has stopped."); });
|
|
4047
4694
|
* ```
|
|
4048
4695
|
*
|
|
4696
|
+
* ---
|
|
4697
|
+
*
|
|
4049
4698
|
* @param callback The function that will be executed when the game loop stops.
|
|
4050
4699
|
*
|
|
4051
4700
|
* @returns A function that can be used to unsubscribe from the event.
|
|
@@ -4055,14 +4704,19 @@ class qe {
|
|
|
4055
4704
|
}
|
|
4056
4705
|
}
|
|
4057
4706
|
var Pe, Ce;
|
|
4058
|
-
class
|
|
4707
|
+
class ht extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
4059
4708
|
/**
|
|
4060
4709
|
* Initializes a new instance of the {@link Clock} class.
|
|
4061
4710
|
*
|
|
4711
|
+
* ---
|
|
4712
|
+
*
|
|
4713
|
+
* @example
|
|
4062
4714
|
* ```ts
|
|
4063
4715
|
* const clock = new Clock();
|
|
4064
4716
|
* ```
|
|
4065
4717
|
*
|
|
4718
|
+
* ---
|
|
4719
|
+
*
|
|
4066
4720
|
* @param msIfNotBrowser
|
|
4067
4721
|
* The interval in milliseconds at which the clock will tick if the environment is not a browser.
|
|
4068
4722
|
* `TimeUnit.Second` by default.
|
|
@@ -4081,11 +4735,16 @@ class ct extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
|
4081
4735
|
*
|
|
4082
4736
|
* If the clock is already running, a {@link RuntimeException} will be thrown.
|
|
4083
4737
|
*
|
|
4738
|
+
* ---
|
|
4739
|
+
*
|
|
4740
|
+
* @example
|
|
4084
4741
|
* ```ts
|
|
4085
4742
|
* clock.onStart(() => { [...] }); // This callback will be executed.
|
|
4086
4743
|
* clock.start();
|
|
4087
4744
|
* ```
|
|
4088
4745
|
*
|
|
4746
|
+
* ---
|
|
4747
|
+
*
|
|
4089
4748
|
* @param elapsedTime The elapsed time to set as default when the clock starts. Default is `0`.
|
|
4090
4749
|
*/
|
|
4091
4750
|
start(e = 0) {
|
|
@@ -4098,6 +4757,9 @@ class ct extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
|
4098
4757
|
*
|
|
4099
4758
|
* If the clock hasn't yet started, a {@link RuntimeException} will be thrown.
|
|
4100
4759
|
*
|
|
4760
|
+
* ---
|
|
4761
|
+
*
|
|
4762
|
+
* @example
|
|
4101
4763
|
* ```ts
|
|
4102
4764
|
* clock.onStop(() => { [...] }); // This callback will be executed.
|
|
4103
4765
|
* clock.stop();
|
|
@@ -4113,11 +4775,16 @@ class ct extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
|
4113
4775
|
/**
|
|
4114
4776
|
* Subscribes to the `tick` event of the clock.
|
|
4115
4777
|
*
|
|
4778
|
+
* ---
|
|
4779
|
+
*
|
|
4780
|
+
* @example
|
|
4116
4781
|
* ```ts
|
|
4117
4782
|
* clock.onTick((elapsedTime) => { [...] }); // This callback will be executed.
|
|
4118
4783
|
* clock.start();
|
|
4119
4784
|
* ```
|
|
4120
4785
|
*
|
|
4786
|
+
* ---
|
|
4787
|
+
*
|
|
4121
4788
|
* @param callback The callback that will be executed when the clock ticks.
|
|
4122
4789
|
* @param tickStep
|
|
4123
4790
|
* The minimum time in milliseconds that must pass from the previous execution of the callback to the next one.
|
|
@@ -4131,7 +4798,7 @@ class ct extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
|
4131
4798
|
*/
|
|
4132
4799
|
onTick(e, n = 0) {
|
|
4133
4800
|
if (n < 0)
|
|
4134
|
-
throw new
|
|
4801
|
+
throw new b("The tick step must be a non-negative number.");
|
|
4135
4802
|
if (n === 0)
|
|
4136
4803
|
return this._publisher.subscribe("tick", e);
|
|
4137
4804
|
let s = 0;
|
|
@@ -4141,14 +4808,19 @@ class ct extends (Ce = qe, Pe = Symbol.toStringTag, Ce) {
|
|
|
4141
4808
|
}
|
|
4142
4809
|
}
|
|
4143
4810
|
var je, Ie;
|
|
4144
|
-
class
|
|
4811
|
+
class ft extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
4145
4812
|
/**
|
|
4146
4813
|
* Initializes a new instance of the {@link Countdown} class.
|
|
4147
4814
|
*
|
|
4815
|
+
* ---
|
|
4816
|
+
*
|
|
4817
|
+
* @example
|
|
4148
4818
|
* ```ts
|
|
4149
4819
|
* const countdown = new Countdown(10_000);
|
|
4150
4820
|
* ```
|
|
4151
4821
|
*
|
|
4822
|
+
* ---
|
|
4823
|
+
*
|
|
4152
4824
|
* @param duration
|
|
4153
4825
|
* The total duration of the countdown in milliseconds.
|
|
4154
4826
|
*
|
|
@@ -4196,6 +4868,8 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4196
4868
|
* The internal method actually responsible for stopping the
|
|
4197
4869
|
* countdown and resolving or rejecting the {@link Countdown._deferrer} promise.
|
|
4198
4870
|
*
|
|
4871
|
+
* ---
|
|
4872
|
+
*
|
|
4199
4873
|
* @param reason
|
|
4200
4874
|
* The reason why the countdown has stopped.
|
|
4201
4875
|
*
|
|
@@ -4214,11 +4888,16 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4214
4888
|
*
|
|
4215
4889
|
* If the countdown is already running, a {@link RuntimeException} will be thrown.
|
|
4216
4890
|
*
|
|
4891
|
+
* ---
|
|
4892
|
+
*
|
|
4893
|
+
* @example
|
|
4217
4894
|
* ```ts
|
|
4218
4895
|
* countdown.onStart(() => { [...] }); // This callback will be executed.
|
|
4219
4896
|
* countdown.start();
|
|
4220
4897
|
* ```
|
|
4221
4898
|
*
|
|
4899
|
+
* ---
|
|
4900
|
+
*
|
|
4222
4901
|
* @param remainingTime
|
|
4223
4902
|
* The remaining time to set as default when the countdown starts.
|
|
4224
4903
|
* Default is the {@link Countdown.duration} itself.
|
|
@@ -4230,18 +4909,23 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4230
4909
|
throw new y("The countdown had already stopped or hadn't yet started.");
|
|
4231
4910
|
if (this._deferrer)
|
|
4232
4911
|
throw new x();
|
|
4233
|
-
return this._deferrer = new
|
|
4912
|
+
return this._deferrer = new He(), super.start(this.duration - e), this._publisher.publish("start"), this._deferrer;
|
|
4234
4913
|
}
|
|
4235
4914
|
/**
|
|
4236
4915
|
* Stops the execution of the countdown.
|
|
4237
4916
|
*
|
|
4238
4917
|
* If the countdown hasn't yet started, a {@link RuntimeException} will be thrown.
|
|
4239
4918
|
*
|
|
4919
|
+
* ---
|
|
4920
|
+
*
|
|
4921
|
+
* @example
|
|
4240
4922
|
* ```ts
|
|
4241
4923
|
* countdown.onStop(() => { [...] }); // This callback will be executed.
|
|
4242
4924
|
* countdown.stop();
|
|
4243
4925
|
* ```
|
|
4244
4926
|
*
|
|
4927
|
+
* ---
|
|
4928
|
+
*
|
|
4245
4929
|
* @param reason
|
|
4246
4930
|
* The reason why the countdown has stopped.
|
|
4247
4931
|
*
|
|
@@ -4254,11 +4938,16 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4254
4938
|
/**
|
|
4255
4939
|
* Subscribes to the `expire` event of the countdown.
|
|
4256
4940
|
*
|
|
4941
|
+
* ---
|
|
4942
|
+
*
|
|
4943
|
+
* @example
|
|
4257
4944
|
* ```ts
|
|
4258
4945
|
* countdown.onExpire(() => { [...] }); // This callback will be executed once the countdown has expired.
|
|
4259
4946
|
* countdown.start();
|
|
4260
4947
|
* ```
|
|
4261
4948
|
*
|
|
4949
|
+
* ---
|
|
4950
|
+
*
|
|
4262
4951
|
* @param callback The callback that will be executed when the countdown expires.
|
|
4263
4952
|
*
|
|
4264
4953
|
* @returns A function that can be used to unsubscribe from the event.
|
|
@@ -4269,11 +4958,16 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4269
4958
|
/**
|
|
4270
4959
|
* Subscribes to the `tick` event of the countdown.
|
|
4271
4960
|
*
|
|
4961
|
+
* ---
|
|
4962
|
+
*
|
|
4963
|
+
* @example
|
|
4272
4964
|
* ```ts
|
|
4273
4965
|
* countdown.onTick((remainingTime) => { [...] }); // This callback will be executed.
|
|
4274
4966
|
* countdown.start();
|
|
4275
4967
|
* ```
|
|
4276
4968
|
*
|
|
4969
|
+
* ---
|
|
4970
|
+
*
|
|
4277
4971
|
* @param callback The callback that will be executed when the countdown ticks.
|
|
4278
4972
|
* @param tickStep
|
|
4279
4973
|
* The minimum time in milliseconds that must pass from the previous execution of the callback to the next one.
|
|
@@ -4287,7 +4981,7 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4287
4981
|
*/
|
|
4288
4982
|
onTick(e, n = 0) {
|
|
4289
4983
|
if (n < 0)
|
|
4290
|
-
throw new
|
|
4984
|
+
throw new b("The tick step must be a non-negative number.");
|
|
4291
4985
|
if (n === 0)
|
|
4292
4986
|
return this._publisher.subscribe("tick", e);
|
|
4293
4987
|
let s = this.remainingTime;
|
|
@@ -4298,7 +4992,7 @@ class ht extends (Ie = qe, je = Symbol.toStringTag, Ie) {
|
|
|
4298
4992
|
}
|
|
4299
4993
|
var Ae;
|
|
4300
4994
|
Ae = Symbol.toStringTag;
|
|
4301
|
-
class
|
|
4995
|
+
class dt {
|
|
4302
4996
|
constructor() {
|
|
4303
4997
|
a(this, Ae, "Curve");
|
|
4304
4998
|
}
|
|
@@ -4306,6 +5000,9 @@ class ft {
|
|
|
4306
5000
|
* Generates a given number of values following a linear curve.
|
|
4307
5001
|
* The values are equally spaced and normalized between 0 and 1.
|
|
4308
5002
|
*
|
|
5003
|
+
* ---
|
|
5004
|
+
*
|
|
5005
|
+
* @example
|
|
4309
5006
|
* ```ts
|
|
4310
5007
|
* for (const value of Curve.Linear(5))
|
|
4311
5008
|
* {
|
|
@@ -4313,13 +5010,15 @@ class ft {
|
|
|
4313
5010
|
* }
|
|
4314
5011
|
* ```
|
|
4315
5012
|
*
|
|
5013
|
+
* ---
|
|
5014
|
+
*
|
|
4316
5015
|
* @param values The number of values to generate.
|
|
4317
5016
|
*
|
|
4318
5017
|
* @returns A {@link SmartIterator} object that generates the values following a linear curve.
|
|
4319
5018
|
*/
|
|
4320
5019
|
static Linear(t) {
|
|
4321
5020
|
const e = t - 1;
|
|
4322
|
-
return new
|
|
5021
|
+
return new c(function* () {
|
|
4323
5022
|
for (let n = 0; n < t; n += 1)
|
|
4324
5023
|
yield n / e;
|
|
4325
5024
|
});
|
|
@@ -4328,6 +5027,9 @@ class ft {
|
|
|
4328
5027
|
* Generates a given number of values following an exponential curve.
|
|
4329
5028
|
* The values are equally spaced and normalized between 0 and 1.
|
|
4330
5029
|
*
|
|
5030
|
+
* ---
|
|
5031
|
+
*
|
|
5032
|
+
* @example
|
|
4331
5033
|
* ```ts
|
|
4332
5034
|
* for (const value of Curve.Exponential(6))
|
|
4333
5035
|
* {
|
|
@@ -4335,6 +5037,8 @@ class ft {
|
|
|
4335
5037
|
* }
|
|
4336
5038
|
* ```
|
|
4337
5039
|
*
|
|
5040
|
+
* ---
|
|
5041
|
+
*
|
|
4338
5042
|
* @param values The number of values to generate.
|
|
4339
5043
|
* @param base
|
|
4340
5044
|
* The base of the exponential curve. Default is `2`.
|
|
@@ -4351,7 +5055,7 @@ class ft {
|
|
|
4351
5055
|
if (e < 0)
|
|
4352
5056
|
throw new d("The base of the exponential curve cannot be negative.");
|
|
4353
5057
|
const n = t - 1;
|
|
4354
|
-
return new
|
|
5058
|
+
return new c(function* () {
|
|
4355
5059
|
for (let s = 0; s < t; s += 1)
|
|
4356
5060
|
yield Math.pow(s / n, e);
|
|
4357
5061
|
});
|
|
@@ -4366,6 +5070,9 @@ const F = class F {
|
|
|
4366
5070
|
/**
|
|
4367
5071
|
* Generates a random boolean value.
|
|
4368
5072
|
*
|
|
5073
|
+
* ---
|
|
5074
|
+
*
|
|
5075
|
+
* @example
|
|
4369
5076
|
* ```ts
|
|
4370
5077
|
* if (Random.Boolean())
|
|
4371
5078
|
* {
|
|
@@ -4373,6 +5080,8 @@ const F = class F {
|
|
|
4373
5080
|
* }
|
|
4374
5081
|
* ```
|
|
4375
5082
|
*
|
|
5083
|
+
* ---
|
|
5084
|
+
*
|
|
4376
5085
|
* @param ratio
|
|
4377
5086
|
* The probability of generating `true`.
|
|
4378
5087
|
*
|
|
@@ -4392,6 +5101,8 @@ const F = class F {
|
|
|
4392
5101
|
/**
|
|
4393
5102
|
* Picks a random valid index from a given array of elements.
|
|
4394
5103
|
*
|
|
5104
|
+
* ---
|
|
5105
|
+
*
|
|
4395
5106
|
* @template T The type of the elements in the array.
|
|
4396
5107
|
*
|
|
4397
5108
|
* @param elements
|
|
@@ -4409,6 +5120,8 @@ const F = class F {
|
|
|
4409
5120
|
/**
|
|
4410
5121
|
* Picks a random element from a given array of elements.
|
|
4411
5122
|
*
|
|
5123
|
+
* ---
|
|
5124
|
+
*
|
|
4412
5125
|
* @template T The type of the elements in the array.
|
|
4413
5126
|
*
|
|
4414
5127
|
* @param elements
|
|
@@ -4423,29 +5136,29 @@ const F = class F {
|
|
|
4423
5136
|
}
|
|
4424
5137
|
};
|
|
4425
5138
|
let j = F;
|
|
4426
|
-
function
|
|
5139
|
+
function wt(i) {
|
|
4427
5140
|
return new Promise((t) => setTimeout(t, i));
|
|
4428
5141
|
}
|
|
4429
5142
|
function mt() {
|
|
4430
5143
|
return new Promise((i) => requestAnimationFrame(() => i()));
|
|
4431
5144
|
}
|
|
4432
|
-
function
|
|
5145
|
+
function yt() {
|
|
4433
5146
|
return new Promise((i) => setTimeout(i));
|
|
4434
5147
|
}
|
|
4435
|
-
function
|
|
5148
|
+
function _t(i, t = "text/javascript") {
|
|
4436
5149
|
return new Promise((e, n) => {
|
|
4437
5150
|
const s = document.createElement("script");
|
|
4438
5151
|
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
5152
|
});
|
|
4440
5153
|
}
|
|
4441
|
-
function
|
|
4442
|
-
return new
|
|
5154
|
+
function pt(...i) {
|
|
5155
|
+
return new c(function* () {
|
|
4443
5156
|
for (const t of i)
|
|
4444
5157
|
for (const e of t)
|
|
4445
5158
|
yield e;
|
|
4446
5159
|
});
|
|
4447
5160
|
}
|
|
4448
|
-
function
|
|
5161
|
+
function bt(i) {
|
|
4449
5162
|
if (i instanceof Array)
|
|
4450
5163
|
return i.length;
|
|
4451
5164
|
let t = 0;
|
|
@@ -4453,27 +5166,27 @@ function pt(i) {
|
|
|
4453
5166
|
t += 1;
|
|
4454
5167
|
return t;
|
|
4455
5168
|
}
|
|
4456
|
-
function
|
|
4457
|
-
return new
|
|
5169
|
+
function xt(i) {
|
|
5170
|
+
return new c(function* () {
|
|
4458
5171
|
let t = 0;
|
|
4459
5172
|
for (const e of i)
|
|
4460
5173
|
yield [t, e], t += 1;
|
|
4461
5174
|
});
|
|
4462
5175
|
}
|
|
4463
|
-
function
|
|
5176
|
+
function gt(i, t, e = 1) {
|
|
4464
5177
|
if (e <= 0)
|
|
4465
|
-
throw new
|
|
5178
|
+
throw new b(
|
|
4466
5179
|
"Step must be always a positive number, even when generating numbers in reverse order."
|
|
4467
5180
|
);
|
|
4468
|
-
return t === void 0 && (t = i, i = 0), i > t ? new
|
|
5181
|
+
return t === void 0 && (t = i, i = 0), i > t ? new c(function* () {
|
|
4469
5182
|
for (let n = i; n > t; n -= e)
|
|
4470
5183
|
yield n;
|
|
4471
|
-
}) : new
|
|
5184
|
+
}) : new c(function* () {
|
|
4472
5185
|
for (let n = i; n < t; n += e)
|
|
4473
5186
|
yield n;
|
|
4474
5187
|
});
|
|
4475
5188
|
}
|
|
4476
|
-
function
|
|
5189
|
+
function vt(i) {
|
|
4477
5190
|
const t = Array.from(i);
|
|
4478
5191
|
for (let e = t.length - 1; e > 0; e -= 1) {
|
|
4479
5192
|
const n = Math.floor(Math.random() * (e + 1));
|
|
@@ -4481,16 +5194,16 @@ function gt(i) {
|
|
|
4481
5194
|
}
|
|
4482
5195
|
return t;
|
|
4483
5196
|
}
|
|
4484
|
-
function
|
|
4485
|
-
return new
|
|
5197
|
+
function kt(i) {
|
|
5198
|
+
return new c(function* () {
|
|
4486
5199
|
const t = /* @__PURE__ */ new Set();
|
|
4487
5200
|
for (const e of i)
|
|
4488
5201
|
t.has(e) || (t.add(e), yield e);
|
|
4489
5202
|
});
|
|
4490
5203
|
}
|
|
4491
|
-
function
|
|
5204
|
+
function Xe(i, t) {
|
|
4492
5205
|
const e = i[Symbol.iterator](), n = t[Symbol.iterator]();
|
|
4493
|
-
return new
|
|
5206
|
+
return new c(function* () {
|
|
4494
5207
|
for (; ; ) {
|
|
4495
5208
|
const s = e.next(), r = n.next();
|
|
4496
5209
|
if (s.done || r.done)
|
|
@@ -4499,7 +5212,7 @@ function Ve(i, t) {
|
|
|
4499
5212
|
}
|
|
4500
5213
|
});
|
|
4501
5214
|
}
|
|
4502
|
-
function
|
|
5215
|
+
function St(i, t) {
|
|
4503
5216
|
if (t === void 0) {
|
|
4504
5217
|
let r = 0, o = 0;
|
|
4505
5218
|
for (const l of i)
|
|
@@ -4509,7 +5222,7 @@ function kt(i, t) {
|
|
|
4509
5222
|
return r / o;
|
|
4510
5223
|
}
|
|
4511
5224
|
let e = 0, n = 0, s = 0;
|
|
4512
|
-
for (const [r, o] of
|
|
5225
|
+
for (const [r, o] of Xe(i, t)) {
|
|
4513
5226
|
if (o <= 0)
|
|
4514
5227
|
throw new d(`The weight for the value #${s} must be greater than zero.`);
|
|
4515
5228
|
e += r * o, n += o, s += 1;
|
|
@@ -4520,7 +5233,7 @@ function kt(i, t) {
|
|
|
4520
5233
|
throw new d("The sum of weights must be greater than zero.");
|
|
4521
5234
|
return e / n;
|
|
4522
5235
|
}
|
|
4523
|
-
function
|
|
5236
|
+
function Tt(i) {
|
|
4524
5237
|
let t = 0;
|
|
4525
5238
|
for (let e = 0; e < i.length; e += 1) {
|
|
4526
5239
|
const n = i.charCodeAt(e);
|
|
@@ -4528,74 +5241,74 @@ function St(i) {
|
|
|
4528
5241
|
}
|
|
4529
5242
|
return t;
|
|
4530
5243
|
}
|
|
4531
|
-
function
|
|
5244
|
+
function Et(i) {
|
|
4532
5245
|
let t = 0;
|
|
4533
5246
|
for (const e of i)
|
|
4534
5247
|
t += e;
|
|
4535
5248
|
return t;
|
|
4536
5249
|
}
|
|
4537
|
-
function
|
|
5250
|
+
function Mt(i) {
|
|
4538
5251
|
return `${i.charAt(0).toUpperCase()}${i.slice(1)}`;
|
|
4539
5252
|
}
|
|
4540
|
-
const
|
|
5253
|
+
const Rt = "2.0.2";
|
|
4541
5254
|
export {
|
|
4542
5255
|
T as AggregatedAsyncIterator,
|
|
4543
5256
|
g as AggregatedIterator,
|
|
4544
5257
|
Ge as CallableObject,
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
5258
|
+
ht as Clock,
|
|
5259
|
+
ft as Countdown,
|
|
5260
|
+
dt as Curve,
|
|
5261
|
+
He as DeferredPromise,
|
|
4549
5262
|
Je as EnvironmentException,
|
|
4550
|
-
|
|
5263
|
+
u as Exception,
|
|
4551
5264
|
x as FatalErrorException,
|
|
4552
5265
|
$e as FileException,
|
|
4553
|
-
|
|
4554
|
-
|
|
5266
|
+
et as FileExistsException,
|
|
5267
|
+
tt as FileNotFoundException,
|
|
4555
5268
|
qe as GameLoop,
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
5269
|
+
ot as JSONStorage,
|
|
5270
|
+
_ as KeyException,
|
|
5271
|
+
nt as NetworkException,
|
|
4559
5272
|
Be as NotImplementedException,
|
|
4560
|
-
|
|
5273
|
+
st as PermissionException,
|
|
4561
5274
|
E as Publisher,
|
|
4562
5275
|
j as Random,
|
|
4563
|
-
|
|
5276
|
+
b as RangeException,
|
|
4564
5277
|
h as ReducedIterator,
|
|
4565
5278
|
C as ReferenceException,
|
|
4566
5279
|
y as RuntimeException,
|
|
4567
5280
|
f as SmartAsyncIterator,
|
|
4568
|
-
|
|
5281
|
+
c as SmartIterator,
|
|
4569
5282
|
k as SmartPromise,
|
|
4570
|
-
|
|
5283
|
+
it as SwitchableCallback,
|
|
4571
5284
|
M as TimeUnit,
|
|
4572
|
-
|
|
5285
|
+
at as TimedPromise,
|
|
4573
5286
|
Ye as TimeoutException,
|
|
4574
|
-
|
|
4575
|
-
|
|
5287
|
+
rt as TypeException,
|
|
5288
|
+
Rt as VERSION,
|
|
4576
5289
|
d as ValueException,
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
5290
|
+
Qe as WeekDay,
|
|
5291
|
+
St as average,
|
|
5292
|
+
Mt as capitalize,
|
|
5293
|
+
pt as chain,
|
|
5294
|
+
bt as count,
|
|
5295
|
+
lt as dateDifference,
|
|
5296
|
+
ct as dateRange,
|
|
5297
|
+
Ve as dateRound,
|
|
5298
|
+
wt as delay,
|
|
5299
|
+
xt as enumerate,
|
|
4587
5300
|
ut as getWeek,
|
|
4588
|
-
|
|
5301
|
+
Tt as hash,
|
|
4589
5302
|
Oe as isBrowser,
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
5303
|
+
We as isNode,
|
|
5304
|
+
Ue as isWorker,
|
|
5305
|
+
_t as loadScript,
|
|
4593
5306
|
mt as nextAnimationFrame,
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
5307
|
+
gt as range,
|
|
5308
|
+
vt as shuffle,
|
|
5309
|
+
Et as sum,
|
|
5310
|
+
kt as unique,
|
|
5311
|
+
yt as yieldToEventLoop,
|
|
5312
|
+
Xe as zip
|
|
4600
5313
|
};
|
|
4601
5314
|
//# sourceMappingURL=core.js.map
|