@byloth/core 2.1.7 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/core.cjs +2 -2
- package/dist/core.cjs.map +1 -1
- package/dist/core.esm.js +1304 -1357
- package/dist/core.esm.js.map +1 -1
- package/dist/core.global.js +2 -2
- package/dist/core.global.js.map +1 -1
- package/dist/core.umd.cjs +2 -2
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +1 -4
- package/src/models/aggregators/aggregated-async-iterator.ts +12 -9
- package/src/models/callbacks/callable-object.ts +2 -2
- package/src/models/callbacks/publisher.ts +99 -37
- package/src/models/callbacks/switchable-callback.ts +0 -1
- package/src/models/callbacks/types.ts +3 -3
- package/src/models/collections/map-view.ts +49 -37
- package/src/models/collections/set-view.ts +49 -36
- package/src/models/collections/types.ts +62 -89
- package/src/models/iterators/smart-async-iterator.ts +0 -3
- package/src/models/json/json-storage.ts +1 -2
- package/src/models/promises/promise-queue.ts +8 -7
- package/src/models/promises/smart-promise.ts +7 -5
- package/src/models/timers/clock.ts +6 -5
- package/src/models/timers/countdown.ts +26 -28
- package/src/models/timers/game-loop.ts +7 -6
- package/src/models/types.ts +1 -1
- package/src/utils/async.ts +11 -9
- package/src/utils/date.ts +14 -2
- package/src/utils/dom.ts +5 -3
package/dist/core.esm.js
CHANGED
|
@@ -1,38 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var a = (i, n, e) => Qe(i, typeof n != "symbol" ? n + "" : n, e);
|
|
4
|
-
const Ye = typeof window < "u" && typeof window.document < "u";
|
|
5
|
-
var A;
|
|
6
|
-
const ot = typeof process < "u" && !!((A = process.versions) != null && A.node);
|
|
7
|
-
var N;
|
|
8
|
-
const at = typeof self == "object" && ((N = self.constructor) == null ? void 0 : N.name) === "DedicatedWorkerGlobalScope";
|
|
9
|
-
var O, q;
|
|
10
|
-
class c extends (q = Error, O = Symbol.toStringTag, q) {
|
|
11
|
-
/**
|
|
12
|
-
* Initializes a new instance of the {@link Exception} class.
|
|
13
|
-
*
|
|
14
|
-
* ---
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* throw new Exception("An error occurred while processing the request.");
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* ---
|
|
22
|
-
*
|
|
23
|
-
* @param message The message that describes the error.
|
|
24
|
-
* @param cause The previous caught error that caused this one, if any.
|
|
25
|
-
* @param name The name of the exception. Default is `"Exception"`.
|
|
26
|
-
*/
|
|
27
|
-
constructor(e, t, s = "Exception") {
|
|
28
|
-
super(e);
|
|
29
|
-
a(this, O, "Exception");
|
|
30
|
-
this.cause = t, this.name = s, t && (t instanceof Error ? this.stack += `
|
|
31
|
-
|
|
32
|
-
Caused by ${t.stack}` : this.stack += `
|
|
33
|
-
|
|
34
|
-
Caused by ${t}`);
|
|
35
|
-
}
|
|
1
|
+
const T = typeof window < "u" && typeof window.document < "u", D = typeof process < "u" && !!process.versions?.node, B = typeof self == "object" && self.constructor?.name === "DedicatedWorkerGlobalScope";
|
|
2
|
+
class c extends Error {
|
|
36
3
|
/**
|
|
37
4
|
* A static method to convert a generic caught error, ensuring it's an instance of the {@link Exception} class.
|
|
38
5
|
*
|
|
@@ -64,9 +31,32 @@ Caused by ${t}`);
|
|
|
64
31
|
}
|
|
65
32
|
return new c(`${e}`);
|
|
66
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Initializes a new instance of the {@link Exception} class.
|
|
36
|
+
*
|
|
37
|
+
* ---
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* throw new Exception("An error occurred while processing the request.");
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* ---
|
|
45
|
+
*
|
|
46
|
+
* @param message The message that describes the error.
|
|
47
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
48
|
+
* @param name The name of the exception. Default is `"Exception"`.
|
|
49
|
+
*/
|
|
50
|
+
constructor(e, t, n = "Exception") {
|
|
51
|
+
super(e), this.cause = t, this.name = n, t && (t instanceof Error ? this.stack += `
|
|
52
|
+
|
|
53
|
+
Caused by ${t.stack}` : this.stack += `
|
|
54
|
+
|
|
55
|
+
Caused by ${t}`);
|
|
56
|
+
}
|
|
57
|
+
[Symbol.toStringTag] = "Exception";
|
|
67
58
|
}
|
|
68
|
-
|
|
69
|
-
class g extends (z = c, $ = Symbol.toStringTag, z) {
|
|
59
|
+
class x extends c {
|
|
70
60
|
/**
|
|
71
61
|
* Initializes a new instance of the {@link FatalErrorException} class.
|
|
72
62
|
*
|
|
@@ -83,14 +73,12 @@ class g extends (z = c, $ = Symbol.toStringTag, z) {
|
|
|
83
73
|
* @param cause The previous caught error that caused this one, if any.
|
|
84
74
|
* @param name The name of the exception. Default is `"FatalErrorException"`.
|
|
85
75
|
*/
|
|
86
|
-
constructor(e, t,
|
|
87
|
-
e === void 0 && (e = "The program has encountered an unrecoverable error and cannot continue as expected. Please, try again later. If the problem persists, contact the support team.");
|
|
88
|
-
super(e, t, s);
|
|
89
|
-
a(this, $, "FatalErrorException");
|
|
76
|
+
constructor(e, t, n = "FatalErrorException") {
|
|
77
|
+
e === void 0 && (e = "The program has encountered an unrecoverable error and cannot continue as expected. Please, try again later. If the problem persists, contact the support team."), super(e, t, n);
|
|
90
78
|
}
|
|
79
|
+
[Symbol.toStringTag] = "FatalErrorException";
|
|
91
80
|
}
|
|
92
|
-
|
|
93
|
-
class He extends (B = g, D = Symbol.toStringTag, B) {
|
|
81
|
+
class C extends x {
|
|
94
82
|
/**
|
|
95
83
|
* Initializes a new instance of the {@link NotImplementedException} class.
|
|
96
84
|
*
|
|
@@ -107,14 +95,12 @@ class He extends (B = g, D = Symbol.toStringTag, B) {
|
|
|
107
95
|
* @param cause The previous caught error that caused this one, if any.
|
|
108
96
|
* @param name The name of the exception. Default is `"NotImplementedException"`.
|
|
109
97
|
*/
|
|
110
|
-
constructor(e, t,
|
|
111
|
-
e === void 0 && (e = "This feature isn't implemented yet. Please, try again later.");
|
|
112
|
-
super(e, t, s);
|
|
113
|
-
a(this, D, "NotImplementedException");
|
|
98
|
+
constructor(e, t, n = "NotImplementedException") {
|
|
99
|
+
e === void 0 && (e = "This feature isn't implemented yet. Please, try again later."), super(e, t, n);
|
|
114
100
|
}
|
|
101
|
+
[Symbol.toStringTag] = "NotImplementedException";
|
|
115
102
|
}
|
|
116
|
-
|
|
117
|
-
class Le extends (Y = c, J = Symbol.toStringTag, Y) {
|
|
103
|
+
class E extends c {
|
|
118
104
|
/**
|
|
119
105
|
* Initializes a new instance of the {@link FileException} class.
|
|
120
106
|
*
|
|
@@ -131,13 +117,12 @@ class Le extends (Y = c, J = Symbol.toStringTag, Y) {
|
|
|
131
117
|
* @param cause The previous caught error that caused this one, if any.
|
|
132
118
|
* @param name The name of the exception. Default is `"FileException"`.
|
|
133
119
|
*/
|
|
134
|
-
constructor(e, t,
|
|
135
|
-
super(e, t,
|
|
136
|
-
a(this, J, "FileException");
|
|
120
|
+
constructor(e, t, n = "FileException") {
|
|
121
|
+
super(e, t, n);
|
|
137
122
|
}
|
|
123
|
+
[Symbol.toStringTag] = "FileException";
|
|
138
124
|
}
|
|
139
|
-
|
|
140
|
-
class lt extends (V = Le, L = Symbol.toStringTag, V) {
|
|
125
|
+
class J extends E {
|
|
141
126
|
/**
|
|
142
127
|
* Initializes a new instance of the {@link FileExistsException} class.
|
|
143
128
|
*
|
|
@@ -154,13 +139,12 @@ class lt extends (V = Le, L = Symbol.toStringTag, V) {
|
|
|
154
139
|
* @param cause The previous caught error that caused this one, if any.
|
|
155
140
|
* @param name The name of the exception. Default is `"FileExistsException"`.
|
|
156
141
|
*/
|
|
157
|
-
constructor(e, t,
|
|
158
|
-
super(e, t,
|
|
159
|
-
a(this, L, "FileExistsException");
|
|
142
|
+
constructor(e, t, n = "FileExistsException") {
|
|
143
|
+
super(e, t, n);
|
|
160
144
|
}
|
|
145
|
+
[Symbol.toStringTag] = "FileExistsException";
|
|
161
146
|
}
|
|
162
|
-
|
|
163
|
-
class ut extends (K = Le, G = Symbol.toStringTag, K) {
|
|
147
|
+
class Y extends E {
|
|
164
148
|
/**
|
|
165
149
|
* Initializes a new instance of the {@link FileNotFoundException} class.
|
|
166
150
|
*
|
|
@@ -177,13 +161,12 @@ class ut extends (K = Le, G = Symbol.toStringTag, K) {
|
|
|
177
161
|
* @param cause The previous caught error that caused this one, if any.
|
|
178
162
|
* @param name The name of the exception. Default is `"FileNotFoundException"`.
|
|
179
163
|
*/
|
|
180
|
-
constructor(e, t,
|
|
181
|
-
super(e, t,
|
|
182
|
-
a(this, G, "FileNotFoundException");
|
|
164
|
+
constructor(e, t, n = "FileNotFoundException") {
|
|
165
|
+
super(e, t, n);
|
|
183
166
|
}
|
|
167
|
+
[Symbol.toStringTag] = "FileNotFoundException";
|
|
184
168
|
}
|
|
185
|
-
|
|
186
|
-
class _ extends (H = c, Q = Symbol.toStringTag, H) {
|
|
169
|
+
class _ extends c {
|
|
187
170
|
/**
|
|
188
171
|
* Initializes a new instance of the {@link KeyException} class.
|
|
189
172
|
*
|
|
@@ -200,13 +183,12 @@ class _ extends (H = c, Q = Symbol.toStringTag, H) {
|
|
|
200
183
|
* @param cause The previous caught error that caused this one, if any.
|
|
201
184
|
* @param name The name of the exception. Default is `"KeyException"`.
|
|
202
185
|
*/
|
|
203
|
-
constructor(e, t,
|
|
204
|
-
super(e, t,
|
|
205
|
-
a(this, Q, "KeyException");
|
|
186
|
+
constructor(e, t, n = "KeyException") {
|
|
187
|
+
super(e, t, n);
|
|
206
188
|
}
|
|
189
|
+
[Symbol.toStringTag] = "KeyException";
|
|
207
190
|
}
|
|
208
|
-
|
|
209
|
-
class ct extends (Z = c, X = Symbol.toStringTag, Z) {
|
|
191
|
+
class L extends c {
|
|
210
192
|
/**
|
|
211
193
|
* Initializes a new instance of the {@link NetworkException} class.
|
|
212
194
|
*
|
|
@@ -223,13 +205,12 @@ class ct extends (Z = c, X = Symbol.toStringTag, Z) {
|
|
|
223
205
|
* @param cause The previous caught error that caused this one, if any.
|
|
224
206
|
* @param name The name of the exception. Default is `"NetworkException"`.
|
|
225
207
|
*/
|
|
226
|
-
constructor(e, t,
|
|
227
|
-
super(e, t,
|
|
228
|
-
a(this, X, "NetworkException");
|
|
208
|
+
constructor(e, t, n = "NetworkException") {
|
|
209
|
+
super(e, t, n);
|
|
229
210
|
}
|
|
211
|
+
[Symbol.toStringTag] = "NetworkException";
|
|
230
212
|
}
|
|
231
|
-
|
|
232
|
-
class ht extends (U = c, W = Symbol.toStringTag, U) {
|
|
213
|
+
class V extends c {
|
|
233
214
|
/**
|
|
234
215
|
* Initializes a new instance of the {@link PermissionException} class.
|
|
235
216
|
*
|
|
@@ -246,13 +227,12 @@ class ht extends (U = c, W = Symbol.toStringTag, U) {
|
|
|
246
227
|
* @param cause The previous caught error that caused this one, if any.
|
|
247
228
|
* @param name The name of the exception. Default is `"PermissionException"`.
|
|
248
229
|
*/
|
|
249
|
-
constructor(e, t,
|
|
250
|
-
super(e, t,
|
|
251
|
-
a(this, W, "PermissionException");
|
|
230
|
+
constructor(e, t, n = "PermissionException") {
|
|
231
|
+
super(e, t, n);
|
|
252
232
|
}
|
|
233
|
+
[Symbol.toStringTag] = "PermissionException";
|
|
253
234
|
}
|
|
254
|
-
|
|
255
|
-
class E extends (te = c, ee = Symbol.toStringTag, te) {
|
|
235
|
+
class S extends c {
|
|
256
236
|
/**
|
|
257
237
|
* Initializes a new instance of the {@link ReferenceException} class.
|
|
258
238
|
*
|
|
@@ -269,13 +249,12 @@ class E extends (te = c, ee = Symbol.toStringTag, te) {
|
|
|
269
249
|
* @param cause The previous caught error that caused this one, if any.
|
|
270
250
|
* @param name The name of the exception. Default is `"ReferenceException"`.
|
|
271
251
|
*/
|
|
272
|
-
constructor(e, t,
|
|
273
|
-
super(e, t,
|
|
274
|
-
a(this, ee, "ReferenceException");
|
|
252
|
+
constructor(e, t, n = "ReferenceException") {
|
|
253
|
+
super(e, t, n);
|
|
275
254
|
}
|
|
255
|
+
[Symbol.toStringTag] = "ReferenceException";
|
|
276
256
|
}
|
|
277
|
-
|
|
278
|
-
class p extends (se = c, ne = Symbol.toStringTag, se) {
|
|
257
|
+
class p extends c {
|
|
279
258
|
/**
|
|
280
259
|
* Initializes a new instance of the {@link RuntimeException} class.
|
|
281
260
|
*
|
|
@@ -292,13 +271,12 @@ class p extends (se = c, ne = Symbol.toStringTag, se) {
|
|
|
292
271
|
* @param cause The previous caught error that caused this one, if any.
|
|
293
272
|
* @param name The name of the exception. Default is `"RuntimeException"`.
|
|
294
273
|
*/
|
|
295
|
-
constructor(e, t,
|
|
296
|
-
super(e, t,
|
|
297
|
-
a(this, ne, "RuntimeException");
|
|
274
|
+
constructor(e, t, n = "RuntimeException") {
|
|
275
|
+
super(e, t, n);
|
|
298
276
|
}
|
|
277
|
+
[Symbol.toStringTag] = "RuntimeException";
|
|
299
278
|
}
|
|
300
|
-
|
|
301
|
-
class Xe extends (ie = p, re = Symbol.toStringTag, ie) {
|
|
279
|
+
class P extends p {
|
|
302
280
|
/**
|
|
303
281
|
* Initializes a new instance of the {@link EnvironmentException} class.
|
|
304
282
|
*
|
|
@@ -315,13 +293,12 @@ class Xe extends (ie = p, re = Symbol.toStringTag, ie) {
|
|
|
315
293
|
* @param cause The previous caught error that caused this one, if any.
|
|
316
294
|
* @param name The name of the exception. Default is `"EnvironmentException"`.
|
|
317
295
|
*/
|
|
318
|
-
constructor(e, t,
|
|
319
|
-
super(e, t,
|
|
320
|
-
a(this, re, "EnvironmentException");
|
|
296
|
+
constructor(e, t, n = "EnvironmentException") {
|
|
297
|
+
super(e, t, n);
|
|
321
298
|
}
|
|
299
|
+
[Symbol.toStringTag] = "EnvironmentException";
|
|
322
300
|
}
|
|
323
|
-
|
|
324
|
-
class Ze extends (ae = c, oe = Symbol.toStringTag, ae) {
|
|
301
|
+
class j extends c {
|
|
325
302
|
/**
|
|
326
303
|
* Initializes a new instance of the {@link TimeoutException} class.
|
|
327
304
|
*
|
|
@@ -338,13 +315,12 @@ class Ze extends (ae = c, oe = Symbol.toStringTag, ae) {
|
|
|
338
315
|
* @param cause The previous caught error that caused this one, if any.
|
|
339
316
|
* @param name The name of the exception. Default is `"TimeoutException"`.
|
|
340
317
|
*/
|
|
341
|
-
constructor(e, t,
|
|
342
|
-
super(e, t,
|
|
343
|
-
a(this, oe, "TimeoutException");
|
|
318
|
+
constructor(e, t, n = "TimeoutException") {
|
|
319
|
+
super(e, t, n);
|
|
344
320
|
}
|
|
321
|
+
[Symbol.toStringTag] = "TimeoutException";
|
|
345
322
|
}
|
|
346
|
-
|
|
347
|
-
class ft extends (ue = c, le = Symbol.toStringTag, ue) {
|
|
323
|
+
class G extends c {
|
|
348
324
|
/**
|
|
349
325
|
* Initializes a new instance of the {@link TypeException} class.
|
|
350
326
|
*
|
|
@@ -361,13 +337,12 @@ class ft extends (ue = c, le = Symbol.toStringTag, ue) {
|
|
|
361
337
|
* @param cause The previous caught error that caused this one, if any.
|
|
362
338
|
* @param name The name of the exception. Default is `"TypeException"`.
|
|
363
339
|
*/
|
|
364
|
-
constructor(e, t,
|
|
365
|
-
super(e, t,
|
|
366
|
-
a(this, le, "TypeException");
|
|
340
|
+
constructor(e, t, n = "TypeException") {
|
|
341
|
+
super(e, t, n);
|
|
367
342
|
}
|
|
343
|
+
[Symbol.toStringTag] = "TypeException";
|
|
368
344
|
}
|
|
369
|
-
|
|
370
|
-
class f extends (he = c, ce = Symbol.toStringTag, he) {
|
|
345
|
+
class f extends c {
|
|
371
346
|
/**
|
|
372
347
|
* Initializes a new instance of the {@link ValueException} class.
|
|
373
348
|
*
|
|
@@ -384,13 +359,12 @@ class f extends (he = c, ce = Symbol.toStringTag, he) {
|
|
|
384
359
|
* @param cause The previous caught error that caused this one, if any.
|
|
385
360
|
* @param name The name of the exception. Default is `"ValueException"`.
|
|
386
361
|
*/
|
|
387
|
-
constructor(e, t,
|
|
388
|
-
super(e, t,
|
|
389
|
-
a(this, ce, "ValueException");
|
|
362
|
+
constructor(e, t, n = "ValueException") {
|
|
363
|
+
super(e, t, n);
|
|
390
364
|
}
|
|
365
|
+
[Symbol.toStringTag] = "ValueException";
|
|
391
366
|
}
|
|
392
|
-
|
|
393
|
-
class b extends (de = f, fe = Symbol.toStringTag, de) {
|
|
367
|
+
class b extends f {
|
|
394
368
|
/**
|
|
395
369
|
* Initializes a new instance of the {@link RangeException} class.
|
|
396
370
|
*
|
|
@@ -407,20 +381,18 @@ class b extends (de = f, fe = Symbol.toStringTag, de) {
|
|
|
407
381
|
* @param cause The previous caught error that caused this one, if any.
|
|
408
382
|
* @param name The name of the exception. Default is `"RangeException"`.
|
|
409
383
|
*/
|
|
410
|
-
constructor(e, t,
|
|
411
|
-
super(e, t,
|
|
412
|
-
a(this, fe, "RangeException");
|
|
384
|
+
constructor(e, t, n = "RangeException") {
|
|
385
|
+
super(e, t, n);
|
|
413
386
|
}
|
|
387
|
+
[Symbol.toStringTag] = "RangeException";
|
|
414
388
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
a(this, we, "SmartIterator");
|
|
423
|
-
n instanceof Function ? this._iterator = n() : Symbol.iterator in n ? this._iterator = n[Symbol.iterator]() : this._iterator = n;
|
|
389
|
+
class l {
|
|
390
|
+
/**
|
|
391
|
+
* The native {@link Iterator} object that is being wrapped by this instance.
|
|
392
|
+
*/
|
|
393
|
+
_iterator;
|
|
394
|
+
constructor(e) {
|
|
395
|
+
e instanceof Function ? this._iterator = e() : Symbol.iterator in e ? this._iterator = e[Symbol.iterator]() : this._iterator = e;
|
|
424
396
|
}
|
|
425
397
|
/**
|
|
426
398
|
* Determines whether all elements of the iterator satisfy a given condition.
|
|
@@ -451,15 +423,15 @@ class u {
|
|
|
451
423
|
*
|
|
452
424
|
* @returns `true` if all elements satisfy the condition, `false` otherwise.
|
|
453
425
|
*/
|
|
454
|
-
every(
|
|
455
|
-
let
|
|
426
|
+
every(e) {
|
|
427
|
+
let t = 0;
|
|
456
428
|
for (; ; ) {
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
429
|
+
const n = this._iterator.next();
|
|
430
|
+
if (n.done)
|
|
459
431
|
return !0;
|
|
460
|
-
if (!n
|
|
432
|
+
if (!e(n.value, t))
|
|
461
433
|
return !1;
|
|
462
|
-
|
|
434
|
+
t += 1;
|
|
463
435
|
}
|
|
464
436
|
}
|
|
465
437
|
/**
|
|
@@ -491,26 +463,26 @@ class u {
|
|
|
491
463
|
*
|
|
492
464
|
* @returns `true` if any element satisfies the condition, `false` otherwise.
|
|
493
465
|
*/
|
|
494
|
-
some(
|
|
495
|
-
let
|
|
466
|
+
some(e) {
|
|
467
|
+
let t = 0;
|
|
496
468
|
for (; ; ) {
|
|
497
|
-
const
|
|
498
|
-
if (
|
|
469
|
+
const n = this._iterator.next();
|
|
470
|
+
if (n.done)
|
|
499
471
|
return !1;
|
|
500
|
-
if (n
|
|
472
|
+
if (e(n.value, t))
|
|
501
473
|
return !0;
|
|
502
|
-
|
|
474
|
+
t += 1;
|
|
503
475
|
}
|
|
504
476
|
}
|
|
505
|
-
filter(
|
|
506
|
-
const
|
|
507
|
-
return new
|
|
508
|
-
let
|
|
477
|
+
filter(e) {
|
|
478
|
+
const t = this._iterator;
|
|
479
|
+
return new l(function* () {
|
|
480
|
+
let n = 0;
|
|
509
481
|
for (; ; ) {
|
|
510
|
-
const s =
|
|
482
|
+
const s = t.next();
|
|
511
483
|
if (s.done)
|
|
512
484
|
return s.value;
|
|
513
|
-
|
|
485
|
+
e(s.value, n) && (yield s.value), n += 1;
|
|
514
486
|
}
|
|
515
487
|
});
|
|
516
488
|
}
|
|
@@ -545,31 +517,31 @@ class u {
|
|
|
545
517
|
*
|
|
546
518
|
* @returns A new {@link SmartIterator} containing the transformed elements.
|
|
547
519
|
*/
|
|
548
|
-
map(
|
|
549
|
-
const
|
|
550
|
-
return new
|
|
551
|
-
let
|
|
520
|
+
map(e) {
|
|
521
|
+
const t = this._iterator;
|
|
522
|
+
return new l(function* () {
|
|
523
|
+
let n = 0;
|
|
552
524
|
for (; ; ) {
|
|
553
|
-
const s =
|
|
525
|
+
const s = t.next();
|
|
554
526
|
if (s.done)
|
|
555
527
|
return s.value;
|
|
556
|
-
yield
|
|
528
|
+
yield e(s.value, n), n += 1;
|
|
557
529
|
}
|
|
558
530
|
});
|
|
559
531
|
}
|
|
560
|
-
reduce(
|
|
561
|
-
let
|
|
532
|
+
reduce(e, t) {
|
|
533
|
+
let n = 0, s = t;
|
|
562
534
|
if (s === void 0) {
|
|
563
535
|
const r = this._iterator.next();
|
|
564
536
|
if (r.done)
|
|
565
537
|
throw new f("Cannot reduce an empty iterator without an initial value.");
|
|
566
|
-
s = r.value,
|
|
538
|
+
s = r.value, n += 1;
|
|
567
539
|
}
|
|
568
540
|
for (; ; ) {
|
|
569
541
|
const r = this._iterator.next();
|
|
570
542
|
if (r.done)
|
|
571
543
|
return s;
|
|
572
|
-
s =
|
|
544
|
+
s = e(s, r.value, n), n += 1;
|
|
573
545
|
}
|
|
574
546
|
}
|
|
575
547
|
/**
|
|
@@ -603,21 +575,21 @@ class u {
|
|
|
603
575
|
*
|
|
604
576
|
* @returns A new {@link SmartIterator} containing the flattened elements.
|
|
605
577
|
*/
|
|
606
|
-
flatMap(
|
|
607
|
-
const
|
|
608
|
-
return new
|
|
609
|
-
let
|
|
578
|
+
flatMap(e) {
|
|
579
|
+
const t = this._iterator;
|
|
580
|
+
return new l(function* () {
|
|
581
|
+
let n = 0;
|
|
610
582
|
for (; ; ) {
|
|
611
|
-
const s =
|
|
583
|
+
const s = t.next();
|
|
612
584
|
if (s.done)
|
|
613
585
|
return s.value;
|
|
614
|
-
const r =
|
|
586
|
+
const r = e(s.value, n);
|
|
615
587
|
if (r instanceof Array)
|
|
616
588
|
for (const o of r)
|
|
617
589
|
yield o;
|
|
618
590
|
else
|
|
619
591
|
yield r;
|
|
620
|
-
|
|
592
|
+
n += 1;
|
|
621
593
|
}
|
|
622
594
|
});
|
|
623
595
|
}
|
|
@@ -652,17 +624,17 @@ class u {
|
|
|
652
624
|
*
|
|
653
625
|
* @returns A new {@link SmartIterator} containing the remaining elements.
|
|
654
626
|
*/
|
|
655
|
-
drop(
|
|
656
|
-
const
|
|
657
|
-
return new
|
|
658
|
-
let
|
|
659
|
-
for (;
|
|
660
|
-
if (
|
|
627
|
+
drop(e) {
|
|
628
|
+
const t = this._iterator;
|
|
629
|
+
return new l(function* () {
|
|
630
|
+
let n = 0;
|
|
631
|
+
for (; n < e; ) {
|
|
632
|
+
if (t.next().done)
|
|
661
633
|
return;
|
|
662
|
-
|
|
634
|
+
n += 1;
|
|
663
635
|
}
|
|
664
636
|
for (; ; ) {
|
|
665
|
-
const s =
|
|
637
|
+
const s = t.next();
|
|
666
638
|
if (s.done)
|
|
667
639
|
return s.value;
|
|
668
640
|
yield s.value;
|
|
@@ -701,27 +673,27 @@ class u {
|
|
|
701
673
|
*
|
|
702
674
|
* @returns A new {@link SmartIterator} containing the taken elements.
|
|
703
675
|
*/
|
|
704
|
-
take(
|
|
705
|
-
const
|
|
706
|
-
return new
|
|
707
|
-
let
|
|
708
|
-
for (;
|
|
709
|
-
const s =
|
|
676
|
+
take(e) {
|
|
677
|
+
const t = this._iterator;
|
|
678
|
+
return new l(function* () {
|
|
679
|
+
let n = 0;
|
|
680
|
+
for (; n < e; ) {
|
|
681
|
+
const s = t.next();
|
|
710
682
|
if (s.done)
|
|
711
683
|
return s.value;
|
|
712
|
-
yield s.value,
|
|
684
|
+
yield s.value, n += 1;
|
|
713
685
|
}
|
|
714
686
|
});
|
|
715
687
|
}
|
|
716
|
-
find(
|
|
717
|
-
let
|
|
688
|
+
find(e) {
|
|
689
|
+
let t = 0;
|
|
718
690
|
for (; ; ) {
|
|
719
|
-
const
|
|
720
|
-
if (
|
|
691
|
+
const n = this._iterator.next();
|
|
692
|
+
if (n.done)
|
|
721
693
|
return;
|
|
722
|
-
if (n
|
|
723
|
-
return
|
|
724
|
-
|
|
694
|
+
if (e(n.value, t))
|
|
695
|
+
return n.value;
|
|
696
|
+
t += 1;
|
|
725
697
|
}
|
|
726
698
|
}
|
|
727
699
|
/**
|
|
@@ -750,7 +722,7 @@ class u {
|
|
|
750
722
|
* @returns A new {@link SmartIterator} containing the enumerated elements.
|
|
751
723
|
*/
|
|
752
724
|
enumerate() {
|
|
753
|
-
return this.map((
|
|
725
|
+
return this.map((e, t) => [t, e]);
|
|
754
726
|
}
|
|
755
727
|
/**
|
|
756
728
|
* Removes all duplicate elements from the iterator.
|
|
@@ -778,14 +750,14 @@ class u {
|
|
|
778
750
|
* @returns A new {@link SmartIterator} containing only the unique elements.
|
|
779
751
|
*/
|
|
780
752
|
unique() {
|
|
781
|
-
const
|
|
782
|
-
return new
|
|
783
|
-
const
|
|
753
|
+
const e = this._iterator;
|
|
754
|
+
return new l(function* () {
|
|
755
|
+
const t = /* @__PURE__ */ new Set();
|
|
784
756
|
for (; ; ) {
|
|
785
|
-
const
|
|
786
|
-
if (
|
|
787
|
-
return
|
|
788
|
-
|
|
757
|
+
const n = e.next();
|
|
758
|
+
if (n.done)
|
|
759
|
+
return n.value;
|
|
760
|
+
t.has(n.value) || (t.add(n.value), yield n.value);
|
|
789
761
|
}
|
|
790
762
|
});
|
|
791
763
|
}
|
|
@@ -810,11 +782,11 @@ class u {
|
|
|
810
782
|
* @returns The number of elements in the iterator.
|
|
811
783
|
*/
|
|
812
784
|
count() {
|
|
813
|
-
let
|
|
785
|
+
let e = 0;
|
|
814
786
|
for (; ; ) {
|
|
815
787
|
if (this._iterator.next().done)
|
|
816
|
-
return
|
|
817
|
-
|
|
788
|
+
return e;
|
|
789
|
+
e += 1;
|
|
818
790
|
}
|
|
819
791
|
}
|
|
820
792
|
/**
|
|
@@ -839,13 +811,13 @@ class u {
|
|
|
839
811
|
*
|
|
840
812
|
* @param iteratee The function to apply to each element of the iterator.
|
|
841
813
|
*/
|
|
842
|
-
forEach(
|
|
843
|
-
let
|
|
814
|
+
forEach(e) {
|
|
815
|
+
let t = 0;
|
|
844
816
|
for (; ; ) {
|
|
845
|
-
const
|
|
846
|
-
if (
|
|
817
|
+
const n = this._iterator.next();
|
|
818
|
+
if (n.done)
|
|
847
819
|
return;
|
|
848
|
-
n
|
|
820
|
+
e(n.value, t), t += 1;
|
|
849
821
|
}
|
|
850
822
|
}
|
|
851
823
|
/**
|
|
@@ -877,8 +849,8 @@ class u {
|
|
|
877
849
|
*
|
|
878
850
|
* @returns The result of the iteration, containing the value of the operation.
|
|
879
851
|
*/
|
|
880
|
-
next(...
|
|
881
|
-
return this._iterator.next(...
|
|
852
|
+
next(...e) {
|
|
853
|
+
return this._iterator.next(...e);
|
|
882
854
|
}
|
|
883
855
|
/**
|
|
884
856
|
* An utility method that may be used to close the iterator gracefully,
|
|
@@ -912,8 +884,8 @@ class u {
|
|
|
912
884
|
*
|
|
913
885
|
* @returns The result of the iterator.
|
|
914
886
|
*/
|
|
915
|
-
return(
|
|
916
|
-
return this._iterator.return ? this._iterator.return(
|
|
887
|
+
return(e) {
|
|
888
|
+
return this._iterator.return ? this._iterator.return(e) : { done: !0, value: e };
|
|
917
889
|
}
|
|
918
890
|
/**
|
|
919
891
|
* An utility method that may be used to close the iterator due to an error,
|
|
@@ -956,10 +928,10 @@ class u {
|
|
|
956
928
|
*
|
|
957
929
|
* @returns The final result of the iterator.
|
|
958
930
|
*/
|
|
959
|
-
throw(
|
|
931
|
+
throw(e) {
|
|
960
932
|
if (this._iterator.throw)
|
|
961
|
-
return this._iterator.throw(
|
|
962
|
-
throw
|
|
933
|
+
return this._iterator.throw(e);
|
|
934
|
+
throw e;
|
|
963
935
|
}
|
|
964
936
|
/**
|
|
965
937
|
* An utility method that aggregates the elements of the iterator using a given key function.
|
|
@@ -991,8 +963,8 @@ class u {
|
|
|
991
963
|
*
|
|
992
964
|
* @returns A new instance of the {@link AggregatedIterator} class containing the grouped elements.
|
|
993
965
|
*/
|
|
994
|
-
groupBy(
|
|
995
|
-
return new
|
|
966
|
+
groupBy(e) {
|
|
967
|
+
return new h(this.map((t, n) => [e(t, n), t]));
|
|
996
968
|
}
|
|
997
969
|
/**
|
|
998
970
|
* Materializes the iterator into an array.
|
|
@@ -1020,20 +992,18 @@ class u {
|
|
|
1020
992
|
toArray() {
|
|
1021
993
|
return Array.from(this);
|
|
1022
994
|
}
|
|
1023
|
-
[
|
|
995
|
+
[Symbol.toStringTag] = "SmartIterator";
|
|
996
|
+
[Symbol.iterator]() {
|
|
1024
997
|
return this;
|
|
1025
998
|
}
|
|
1026
999
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
a(this, "_elements");
|
|
1035
|
-
a(this, me, "ReducedIterator");
|
|
1036
|
-
this._elements = new u(n);
|
|
1000
|
+
class u {
|
|
1001
|
+
/**
|
|
1002
|
+
* The internal {@link SmartIterator} object that holds the reduced elements.
|
|
1003
|
+
*/
|
|
1004
|
+
_elements;
|
|
1005
|
+
constructor(e) {
|
|
1006
|
+
this._elements = new l(e);
|
|
1037
1007
|
}
|
|
1038
1008
|
/**
|
|
1039
1009
|
* Determines whether all elements of the reduced iterator satisfy the given condition.
|
|
@@ -1066,9 +1036,9 @@ const y = class y {
|
|
|
1066
1036
|
*
|
|
1067
1037
|
* @returns `true` if all elements satisfy the condition, `false` otherwise.
|
|
1068
1038
|
*/
|
|
1069
|
-
every(
|
|
1070
|
-
for (const [
|
|
1071
|
-
if (!n
|
|
1039
|
+
every(e) {
|
|
1040
|
+
for (const [t, [n, s]] of this._elements.enumerate())
|
|
1041
|
+
if (!e(n, s, t))
|
|
1072
1042
|
return !1;
|
|
1073
1043
|
return !0;
|
|
1074
1044
|
}
|
|
@@ -1103,17 +1073,17 @@ const y = class y {
|
|
|
1103
1073
|
*
|
|
1104
1074
|
* @returns `true` if any element satisfies the condition, `false` otherwise.
|
|
1105
1075
|
*/
|
|
1106
|
-
some(
|
|
1107
|
-
for (const [
|
|
1108
|
-
if (n
|
|
1076
|
+
some(e) {
|
|
1077
|
+
for (const [t, [n, s]] of this._elements.enumerate())
|
|
1078
|
+
if (e(n, s, t))
|
|
1109
1079
|
return !0;
|
|
1110
1080
|
return !1;
|
|
1111
1081
|
}
|
|
1112
|
-
filter(
|
|
1113
|
-
const
|
|
1114
|
-
return new
|
|
1115
|
-
for (const [
|
|
1116
|
-
|
|
1082
|
+
filter(e) {
|
|
1083
|
+
const t = this._elements.enumerate();
|
|
1084
|
+
return new u(function* () {
|
|
1085
|
+
for (const [n, [s, r]] of t)
|
|
1086
|
+
e(s, r, n) && (yield [s, r]);
|
|
1117
1087
|
});
|
|
1118
1088
|
}
|
|
1119
1089
|
/**
|
|
@@ -1149,23 +1119,23 @@ const y = class y {
|
|
|
1149
1119
|
*
|
|
1150
1120
|
* @returns A new {@link ReducedIterator} containing the transformed elements.
|
|
1151
1121
|
*/
|
|
1152
|
-
map(
|
|
1153
|
-
const
|
|
1154
|
-
return new
|
|
1155
|
-
for (const [
|
|
1156
|
-
yield [s,
|
|
1122
|
+
map(e) {
|
|
1123
|
+
const t = this._elements.enumerate();
|
|
1124
|
+
return new u(function* () {
|
|
1125
|
+
for (const [n, [s, r]] of t)
|
|
1126
|
+
yield [s, e(s, r, n)];
|
|
1157
1127
|
});
|
|
1158
1128
|
}
|
|
1159
|
-
reduce(
|
|
1160
|
-
let
|
|
1129
|
+
reduce(e, t) {
|
|
1130
|
+
let n = 0, s = t;
|
|
1161
1131
|
if (s === void 0) {
|
|
1162
1132
|
const r = this._elements.next();
|
|
1163
1133
|
if (r.done)
|
|
1164
1134
|
throw new f("Cannot reduce an empty iterator without an initial value.");
|
|
1165
|
-
s = r.value[1],
|
|
1135
|
+
s = r.value[1], n += 1;
|
|
1166
1136
|
}
|
|
1167
1137
|
for (const [r, o] of this._elements)
|
|
1168
|
-
s =
|
|
1138
|
+
s = e(r, s, o, n), n += 1;
|
|
1169
1139
|
return s;
|
|
1170
1140
|
}
|
|
1171
1141
|
/**
|
|
@@ -1201,14 +1171,14 @@ const y = class y {
|
|
|
1201
1171
|
*
|
|
1202
1172
|
* @returns A new {@link AggregatedIterator} containing the flattened elements.
|
|
1203
1173
|
*/
|
|
1204
|
-
flatMap(
|
|
1205
|
-
const
|
|
1206
|
-
return new
|
|
1207
|
-
for (const [
|
|
1208
|
-
const o =
|
|
1174
|
+
flatMap(e) {
|
|
1175
|
+
const t = this._elements.enumerate();
|
|
1176
|
+
return new h(function* () {
|
|
1177
|
+
for (const [n, [s, r]] of t) {
|
|
1178
|
+
const o = e(s, r, n);
|
|
1209
1179
|
if (o instanceof Array)
|
|
1210
|
-
for (const
|
|
1211
|
-
yield [s,
|
|
1180
|
+
for (const a of o)
|
|
1181
|
+
yield [s, a];
|
|
1212
1182
|
else
|
|
1213
1183
|
yield [s, o];
|
|
1214
1184
|
}
|
|
@@ -1247,11 +1217,11 @@ const y = class y {
|
|
|
1247
1217
|
*
|
|
1248
1218
|
* @returns A new {@link ReducedIterator} containing the remaining elements.
|
|
1249
1219
|
*/
|
|
1250
|
-
drop(
|
|
1251
|
-
const
|
|
1252
|
-
return new
|
|
1253
|
-
for (const [
|
|
1254
|
-
|
|
1220
|
+
drop(e) {
|
|
1221
|
+
const t = this._elements.enumerate();
|
|
1222
|
+
return new u(function* () {
|
|
1223
|
+
for (const [n, [s, r]] of t)
|
|
1224
|
+
n >= e && (yield [s, r]);
|
|
1255
1225
|
});
|
|
1256
1226
|
}
|
|
1257
1227
|
/**
|
|
@@ -1289,19 +1259,19 @@ const y = class y {
|
|
|
1289
1259
|
*
|
|
1290
1260
|
* @returns A new {@link ReducedIterator} containing the taken elements.
|
|
1291
1261
|
*/
|
|
1292
|
-
take(
|
|
1293
|
-
const
|
|
1294
|
-
return new
|
|
1295
|
-
for (const [
|
|
1296
|
-
if (
|
|
1262
|
+
take(e) {
|
|
1263
|
+
const t = this._elements.enumerate();
|
|
1264
|
+
return new u(function* () {
|
|
1265
|
+
for (const [n, [s, r]] of t) {
|
|
1266
|
+
if (n >= e)
|
|
1297
1267
|
break;
|
|
1298
1268
|
yield [s, r];
|
|
1299
1269
|
}
|
|
1300
1270
|
});
|
|
1301
1271
|
}
|
|
1302
|
-
find(
|
|
1303
|
-
for (const [
|
|
1304
|
-
if (n
|
|
1272
|
+
find(e) {
|
|
1273
|
+
for (const [t, [n, s]] of this._elements.enumerate())
|
|
1274
|
+
if (e(n, s, t))
|
|
1305
1275
|
return s;
|
|
1306
1276
|
}
|
|
1307
1277
|
/**
|
|
@@ -1332,7 +1302,7 @@ const y = class y {
|
|
|
1332
1302
|
* @returns A new {@link ReducedIterator} object containing the enumerated elements.
|
|
1333
1303
|
*/
|
|
1334
1304
|
enumerate() {
|
|
1335
|
-
return this.map((
|
|
1305
|
+
return this.map((e, t, n) => [n, t]);
|
|
1336
1306
|
}
|
|
1337
1307
|
/**
|
|
1338
1308
|
* Removes all duplicate elements from the reduced iterator.
|
|
@@ -1360,11 +1330,11 @@ const y = class y {
|
|
|
1360
1330
|
* @returns A new {@link ReducedIterator} containing only the unique elements.
|
|
1361
1331
|
*/
|
|
1362
1332
|
unique() {
|
|
1363
|
-
const
|
|
1364
|
-
return new
|
|
1365
|
-
const
|
|
1366
|
-
for (const [
|
|
1367
|
-
|
|
1333
|
+
const e = this._elements;
|
|
1334
|
+
return new u(function* () {
|
|
1335
|
+
const t = /* @__PURE__ */ new Set();
|
|
1336
|
+
for (const [n, s] of e)
|
|
1337
|
+
t.has(s) || (t.add(s), yield [n, s]);
|
|
1368
1338
|
});
|
|
1369
1339
|
}
|
|
1370
1340
|
/**
|
|
@@ -1390,10 +1360,10 @@ const y = class y {
|
|
|
1390
1360
|
* @returns The number of elements in the iterator.
|
|
1391
1361
|
*/
|
|
1392
1362
|
count() {
|
|
1393
|
-
let
|
|
1394
|
-
for (const
|
|
1395
|
-
|
|
1396
|
-
return
|
|
1363
|
+
let e = 0;
|
|
1364
|
+
for (const t of this._elements)
|
|
1365
|
+
e += 1;
|
|
1366
|
+
return e;
|
|
1397
1367
|
}
|
|
1398
1368
|
/**
|
|
1399
1369
|
* Iterates over all elements of the reduced iterator.
|
|
@@ -1420,9 +1390,9 @@ const y = class y {
|
|
|
1420
1390
|
*
|
|
1421
1391
|
* @param iteratee The function to apply to each element of the reduced iterator.
|
|
1422
1392
|
*/
|
|
1423
|
-
forEach(
|
|
1424
|
-
for (const [
|
|
1425
|
-
n
|
|
1393
|
+
forEach(e) {
|
|
1394
|
+
for (const [t, [n, s]] of this._elements.enumerate())
|
|
1395
|
+
e(n, s, t);
|
|
1426
1396
|
}
|
|
1427
1397
|
/**
|
|
1428
1398
|
* Reaggregates the elements of the reduced iterator.
|
|
@@ -1455,11 +1425,11 @@ const y = class y {
|
|
|
1455
1425
|
*
|
|
1456
1426
|
* @returns A new {@link AggregatedIterator} containing the elements reorganized by the new keys.
|
|
1457
1427
|
*/
|
|
1458
|
-
reorganizeBy(
|
|
1459
|
-
const
|
|
1460
|
-
return new
|
|
1461
|
-
for (const [
|
|
1462
|
-
yield [
|
|
1428
|
+
reorganizeBy(e) {
|
|
1429
|
+
const t = this._elements.enumerate();
|
|
1430
|
+
return new h(function* () {
|
|
1431
|
+
for (const [n, [s, r]] of t)
|
|
1432
|
+
yield [e(s, r, n), r];
|
|
1463
1433
|
});
|
|
1464
1434
|
}
|
|
1465
1435
|
/**
|
|
@@ -1490,10 +1460,10 @@ const y = class y {
|
|
|
1490
1460
|
* @returns A new {@link SmartIterator} containing all the keys of the iterator.
|
|
1491
1461
|
*/
|
|
1492
1462
|
keys() {
|
|
1493
|
-
const
|
|
1494
|
-
return new
|
|
1495
|
-
for (const [
|
|
1496
|
-
yield
|
|
1463
|
+
const e = this._elements;
|
|
1464
|
+
return new l(function* () {
|
|
1465
|
+
for (const [t] of e)
|
|
1466
|
+
yield t;
|
|
1497
1467
|
});
|
|
1498
1468
|
}
|
|
1499
1469
|
/**
|
|
@@ -1555,10 +1525,10 @@ const y = class y {
|
|
|
1555
1525
|
* @returns A new {@link SmartIterator} containing all the values of the iterator.
|
|
1556
1526
|
*/
|
|
1557
1527
|
values() {
|
|
1558
|
-
const
|
|
1559
|
-
return new
|
|
1560
|
-
for (const [
|
|
1561
|
-
yield
|
|
1528
|
+
const e = this._elements;
|
|
1529
|
+
return new l(function* () {
|
|
1530
|
+
for (const [t, n] of e)
|
|
1531
|
+
yield n;
|
|
1562
1532
|
});
|
|
1563
1533
|
}
|
|
1564
1534
|
/**
|
|
@@ -1633,18 +1603,15 @@ const y = class y {
|
|
|
1633
1603
|
toObject() {
|
|
1634
1604
|
return Object.fromEntries(this.entries());
|
|
1635
1605
|
}
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
a(this, "_elements");
|
|
1646
|
-
a(this, pe, "AggregatedAsyncIterator");
|
|
1647
|
-
this._elements = new d(n);
|
|
1606
|
+
[Symbol.toStringTag] = "ReducedIterator";
|
|
1607
|
+
}
|
|
1608
|
+
class m {
|
|
1609
|
+
/**
|
|
1610
|
+
* The internal {@link SmartAsyncIterator} object that holds the elements to aggregate.
|
|
1611
|
+
*/
|
|
1612
|
+
_elements;
|
|
1613
|
+
constructor(e) {
|
|
1614
|
+
this._elements = new d(e);
|
|
1648
1615
|
}
|
|
1649
1616
|
/**
|
|
1650
1617
|
* Determines whether all elements of each group of the iterator satisfy a given condition.
|
|
@@ -1677,15 +1644,15 @@ const w = class w {
|
|
|
1677
1644
|
* @returns
|
|
1678
1645
|
* A {@link Promise} resolving to a new {@link ReducedIterator} containing the boolean results for each group.
|
|
1679
1646
|
*/
|
|
1680
|
-
async every(
|
|
1681
|
-
const
|
|
1682
|
-
for await (const [
|
|
1683
|
-
const [r, o] =
|
|
1684
|
-
o &&
|
|
1647
|
+
async every(e) {
|
|
1648
|
+
const t = /* @__PURE__ */ new Map();
|
|
1649
|
+
for await (const [n, s] of this._elements) {
|
|
1650
|
+
const [r, o] = t.get(n) ?? [0, !0];
|
|
1651
|
+
o && t.set(n, [r + 1, await e(n, s, r)]);
|
|
1685
1652
|
}
|
|
1686
|
-
return new
|
|
1687
|
-
for (const [
|
|
1688
|
-
yield [
|
|
1653
|
+
return new u(function* () {
|
|
1654
|
+
for (const [n, [s, r]] of t)
|
|
1655
|
+
yield [n, r];
|
|
1689
1656
|
});
|
|
1690
1657
|
}
|
|
1691
1658
|
/**
|
|
@@ -1719,24 +1686,24 @@ const w = class w {
|
|
|
1719
1686
|
* @returns
|
|
1720
1687
|
* A {@link Promise} resolving to a new {@link ReducedIterator} containing the boolean results for each group.
|
|
1721
1688
|
*/
|
|
1722
|
-
async some(
|
|
1723
|
-
const
|
|
1724
|
-
for await (const [
|
|
1725
|
-
const [r, o] =
|
|
1726
|
-
o ||
|
|
1689
|
+
async some(e) {
|
|
1690
|
+
const t = /* @__PURE__ */ new Map();
|
|
1691
|
+
for await (const [n, s] of this._elements) {
|
|
1692
|
+
const [r, o] = t.get(n) ?? [0, !1];
|
|
1693
|
+
o || t.set(n, [r + 1, await e(n, s, r)]);
|
|
1727
1694
|
}
|
|
1728
|
-
return new
|
|
1729
|
-
for (const [
|
|
1730
|
-
yield [
|
|
1695
|
+
return new u(function* () {
|
|
1696
|
+
for (const [n, [s, r]] of t)
|
|
1697
|
+
yield [n, r];
|
|
1731
1698
|
});
|
|
1732
1699
|
}
|
|
1733
|
-
filter(
|
|
1734
|
-
const
|
|
1735
|
-
return new
|
|
1736
|
-
const
|
|
1737
|
-
for await (const [s, r] of
|
|
1738
|
-
const o =
|
|
1739
|
-
await
|
|
1700
|
+
filter(e) {
|
|
1701
|
+
const t = this._elements;
|
|
1702
|
+
return new m(async function* () {
|
|
1703
|
+
const n = /* @__PURE__ */ new Map();
|
|
1704
|
+
for await (const [s, r] of t) {
|
|
1705
|
+
const o = n.get(s) ?? 0;
|
|
1706
|
+
await e(s, r, o) && (yield [s, r]), n.set(s, o + 1);
|
|
1740
1707
|
}
|
|
1741
1708
|
});
|
|
1742
1709
|
}
|
|
@@ -1772,32 +1739,32 @@ const w = class w {
|
|
|
1772
1739
|
*
|
|
1773
1740
|
* @returns A new {@link AggregatedAsyncIterator} containing the transformed elements.
|
|
1774
1741
|
*/
|
|
1775
|
-
map(
|
|
1776
|
-
const
|
|
1777
|
-
return new
|
|
1778
|
-
const
|
|
1779
|
-
for await (const [s, r] of
|
|
1780
|
-
const o =
|
|
1781
|
-
yield [s, await
|
|
1742
|
+
map(e) {
|
|
1743
|
+
const t = this._elements;
|
|
1744
|
+
return new m(async function* () {
|
|
1745
|
+
const n = /* @__PURE__ */ new Map();
|
|
1746
|
+
for await (const [s, r] of t) {
|
|
1747
|
+
const o = n.get(s) ?? 0;
|
|
1748
|
+
yield [s, await e(s, r, o)], n.set(s, o + 1);
|
|
1782
1749
|
}
|
|
1783
1750
|
});
|
|
1784
1751
|
}
|
|
1785
|
-
async reduce(
|
|
1786
|
-
const
|
|
1752
|
+
async reduce(e, t) {
|
|
1753
|
+
const n = /* @__PURE__ */ new Map();
|
|
1787
1754
|
for await (const [s, r] of this._elements) {
|
|
1788
|
-
let o,
|
|
1789
|
-
if (
|
|
1790
|
-
[o,
|
|
1791
|
-
else if (
|
|
1792
|
-
o = 0,
|
|
1755
|
+
let o, a;
|
|
1756
|
+
if (n.has(s))
|
|
1757
|
+
[o, a] = n.get(s);
|
|
1758
|
+
else if (t !== void 0)
|
|
1759
|
+
o = 0, t instanceof Function ? a = await t(s) : a = await t;
|
|
1793
1760
|
else {
|
|
1794
|
-
|
|
1761
|
+
n.set(s, [0, r]);
|
|
1795
1762
|
continue;
|
|
1796
1763
|
}
|
|
1797
|
-
|
|
1764
|
+
n.set(s, [o + 1, await e(s, a, r, o)]);
|
|
1798
1765
|
}
|
|
1799
|
-
return new
|
|
1800
|
-
for (const [s, [r, o]] of
|
|
1766
|
+
return new u(function* () {
|
|
1767
|
+
for (const [s, [r, o]] of n)
|
|
1801
1768
|
yield [s, o];
|
|
1802
1769
|
});
|
|
1803
1770
|
}
|
|
@@ -1837,18 +1804,18 @@ const w = class w {
|
|
|
1837
1804
|
*
|
|
1838
1805
|
* @returns A new {@link AggregatedAsyncIterator} containing the transformed elements.
|
|
1839
1806
|
*/
|
|
1840
|
-
flatMap(
|
|
1841
|
-
const
|
|
1842
|
-
return new
|
|
1843
|
-
const
|
|
1844
|
-
for await (const [s, r] of
|
|
1845
|
-
const o =
|
|
1846
|
-
if (
|
|
1847
|
-
for (const
|
|
1848
|
-
yield [s,
|
|
1807
|
+
flatMap(e) {
|
|
1808
|
+
const t = this._elements;
|
|
1809
|
+
return new m(async function* () {
|
|
1810
|
+
const n = /* @__PURE__ */ new Map();
|
|
1811
|
+
for await (const [s, r] of t) {
|
|
1812
|
+
const o = n.get(s) ?? 0, a = await e(s, r, o);
|
|
1813
|
+
if (a instanceof Array)
|
|
1814
|
+
for (const y of a)
|
|
1815
|
+
yield [s, y];
|
|
1849
1816
|
else
|
|
1850
|
-
yield [s,
|
|
1851
|
-
|
|
1817
|
+
yield [s, a];
|
|
1818
|
+
n.set(s, o + 1);
|
|
1852
1819
|
}
|
|
1853
1820
|
});
|
|
1854
1821
|
}
|
|
@@ -1881,14 +1848,14 @@ const w = class w {
|
|
|
1881
1848
|
*
|
|
1882
1849
|
* @returns A new {@link AggregatedAsyncIterator} containing the remaining elements.
|
|
1883
1850
|
*/
|
|
1884
|
-
drop(
|
|
1885
|
-
const
|
|
1886
|
-
return new
|
|
1887
|
-
const
|
|
1888
|
-
for await (const [s, r] of
|
|
1889
|
-
const o =
|
|
1890
|
-
if (o <
|
|
1891
|
-
|
|
1851
|
+
drop(e) {
|
|
1852
|
+
const t = this._elements;
|
|
1853
|
+
return new m(async function* () {
|
|
1854
|
+
const n = /* @__PURE__ */ new Map();
|
|
1855
|
+
for await (const [s, r] of t) {
|
|
1856
|
+
const o = n.get(s) ?? 0;
|
|
1857
|
+
if (o < e) {
|
|
1858
|
+
n.set(s, o + 1);
|
|
1892
1859
|
continue;
|
|
1893
1860
|
}
|
|
1894
1861
|
yield [s, r];
|
|
@@ -1924,25 +1891,25 @@ const w = class w {
|
|
|
1924
1891
|
*
|
|
1925
1892
|
* @returns A new {@link AggregatedAsyncIterator} containing the taken elements.
|
|
1926
1893
|
*/
|
|
1927
|
-
take(
|
|
1928
|
-
const
|
|
1929
|
-
return new
|
|
1930
|
-
const
|
|
1931
|
-
for await (const [s, r] of
|
|
1932
|
-
const o =
|
|
1933
|
-
o >=
|
|
1894
|
+
take(e) {
|
|
1895
|
+
const t = this._elements;
|
|
1896
|
+
return new m(async function* () {
|
|
1897
|
+
const n = /* @__PURE__ */ new Map();
|
|
1898
|
+
for await (const [s, r] of t) {
|
|
1899
|
+
const o = n.get(s) ?? 0;
|
|
1900
|
+
o >= e || (yield [s, r], n.set(s, o + 1));
|
|
1934
1901
|
}
|
|
1935
1902
|
});
|
|
1936
1903
|
}
|
|
1937
|
-
async find(
|
|
1938
|
-
const
|
|
1939
|
-
for await (const [
|
|
1940
|
-
let [r, o] =
|
|
1941
|
-
o === void 0 && (await n
|
|
1904
|
+
async find(e) {
|
|
1905
|
+
const t = /* @__PURE__ */ new Map();
|
|
1906
|
+
for await (const [n, s] of this._elements) {
|
|
1907
|
+
let [r, o] = t.get(n) ?? [0, void 0];
|
|
1908
|
+
o === void 0 && (await e(n, s, r) && (o = s), t.set(n, [r + 1, o]));
|
|
1942
1909
|
}
|
|
1943
|
-
return new
|
|
1944
|
-
for (const [
|
|
1945
|
-
yield [
|
|
1910
|
+
return new u(function* () {
|
|
1911
|
+
for (const [n, [s, r]] of t)
|
|
1912
|
+
yield [n, r];
|
|
1946
1913
|
});
|
|
1947
1914
|
}
|
|
1948
1915
|
/**
|
|
@@ -1972,7 +1939,7 @@ const w = class w {
|
|
|
1972
1939
|
* @returns A new {@link AggregatedAsyncIterator} containing the enumerated elements.
|
|
1973
1940
|
*/
|
|
1974
1941
|
enumerate() {
|
|
1975
|
-
return this.map((
|
|
1942
|
+
return this.map((e, t, n) => [n, t]);
|
|
1976
1943
|
}
|
|
1977
1944
|
/**
|
|
1978
1945
|
* Removes all duplicate elements from within each group of the iterator.
|
|
@@ -2001,12 +1968,12 @@ const w = class w {
|
|
|
2001
1968
|
* @returns A new {@link AggregatedAsyncIterator} containing only the unique elements.
|
|
2002
1969
|
*/
|
|
2003
1970
|
unique() {
|
|
2004
|
-
const
|
|
2005
|
-
return new
|
|
2006
|
-
const
|
|
2007
|
-
for await (const [
|
|
2008
|
-
const r =
|
|
2009
|
-
r.has(s) || (r.add(s),
|
|
1971
|
+
const e = this._elements;
|
|
1972
|
+
return new m(async function* () {
|
|
1973
|
+
const t = /* @__PURE__ */ new Map();
|
|
1974
|
+
for await (const [n, s] of e) {
|
|
1975
|
+
const r = t.get(n) ?? /* @__PURE__ */ new Set();
|
|
1976
|
+
r.has(s) || (r.add(s), t.set(n, r), yield [n, s]);
|
|
2010
1977
|
}
|
|
2011
1978
|
});
|
|
2012
1979
|
}
|
|
@@ -2033,14 +2000,14 @@ const w = class w {
|
|
|
2033
2000
|
* A {@link Promise} resolving to a new {@link ReducedIterator} containing the number of elements for each group.
|
|
2034
2001
|
*/
|
|
2035
2002
|
async count() {
|
|
2036
|
-
const
|
|
2037
|
-
for await (const [
|
|
2038
|
-
const
|
|
2039
|
-
|
|
2003
|
+
const e = /* @__PURE__ */ new Map();
|
|
2004
|
+
for await (const [t] of this._elements) {
|
|
2005
|
+
const n = e.get(t) ?? 0;
|
|
2006
|
+
e.set(t, n + 1);
|
|
2040
2007
|
}
|
|
2041
|
-
return new
|
|
2042
|
-
for (const [
|
|
2043
|
-
yield [
|
|
2008
|
+
return new u(function* () {
|
|
2009
|
+
for (const [t, n] of e)
|
|
2010
|
+
yield [t, n];
|
|
2044
2011
|
});
|
|
2045
2012
|
}
|
|
2046
2013
|
/**
|
|
@@ -2069,11 +2036,11 @@ const w = class w {
|
|
|
2069
2036
|
*
|
|
2070
2037
|
* @returns A {@link Promise} that will resolve once the iteration is complete.
|
|
2071
2038
|
*/
|
|
2072
|
-
async forEach(
|
|
2073
|
-
const
|
|
2074
|
-
for await (const [
|
|
2075
|
-
const r =
|
|
2076
|
-
await n
|
|
2039
|
+
async forEach(e) {
|
|
2040
|
+
const t = /* @__PURE__ */ new Map();
|
|
2041
|
+
for await (const [n, s] of this._elements) {
|
|
2042
|
+
const r = t.get(n) ?? 0;
|
|
2043
|
+
await e(n, s, r), t.set(n, r + 1);
|
|
2077
2044
|
}
|
|
2078
2045
|
}
|
|
2079
2046
|
/**
|
|
@@ -2107,13 +2074,13 @@ const w = class w {
|
|
|
2107
2074
|
*
|
|
2108
2075
|
* @returns A new {@link AggregatedAsyncIterator} containing the elements reorganized by the new keys.
|
|
2109
2076
|
*/
|
|
2110
|
-
reorganizeBy(
|
|
2111
|
-
const
|
|
2112
|
-
return new
|
|
2113
|
-
const
|
|
2114
|
-
for await (const [s, r] of
|
|
2115
|
-
const o =
|
|
2116
|
-
yield [await
|
|
2077
|
+
reorganizeBy(e) {
|
|
2078
|
+
const t = this._elements;
|
|
2079
|
+
return new m(async function* () {
|
|
2080
|
+
const n = /* @__PURE__ */ new Map();
|
|
2081
|
+
for await (const [s, r] of t) {
|
|
2082
|
+
const o = n.get(s) ?? 0;
|
|
2083
|
+
yield [await e(s, r, o), r], n.set(s, o + 1);
|
|
2117
2084
|
}
|
|
2118
2085
|
});
|
|
2119
2086
|
}
|
|
@@ -2144,11 +2111,11 @@ const w = class w {
|
|
|
2144
2111
|
* @returns A new {@link SmartAsyncIterator} containing all the keys of the iterator.
|
|
2145
2112
|
*/
|
|
2146
2113
|
keys() {
|
|
2147
|
-
const
|
|
2114
|
+
const e = this._elements;
|
|
2148
2115
|
return new d(async function* () {
|
|
2149
|
-
const
|
|
2150
|
-
for await (const [
|
|
2151
|
-
|
|
2116
|
+
const t = /* @__PURE__ */ new Set();
|
|
2117
|
+
for await (const [n] of e)
|
|
2118
|
+
t.has(n) || (t.add(n), yield n);
|
|
2152
2119
|
});
|
|
2153
2120
|
}
|
|
2154
2121
|
/**
|
|
@@ -2208,10 +2175,10 @@ const w = class w {
|
|
|
2208
2175
|
* @returns A new {@link SmartAsyncIterator} containing all the values of the iterator.
|
|
2209
2176
|
*/
|
|
2210
2177
|
values() {
|
|
2211
|
-
const
|
|
2178
|
+
const e = this._elements;
|
|
2212
2179
|
return new d(async function* () {
|
|
2213
|
-
for await (const [
|
|
2214
|
-
yield
|
|
2180
|
+
for await (const [t, n] of e)
|
|
2181
|
+
yield n;
|
|
2215
2182
|
});
|
|
2216
2183
|
}
|
|
2217
2184
|
/**
|
|
@@ -2235,8 +2202,8 @@ const w = class w {
|
|
|
2235
2202
|
* @returns A {@link Promise} resolving to an {@link Array} containing all the values of the iterator.
|
|
2236
2203
|
*/
|
|
2237
2204
|
async toArray() {
|
|
2238
|
-
const
|
|
2239
|
-
return Array.from(
|
|
2205
|
+
const e = await this.toMap();
|
|
2206
|
+
return Array.from(e.values());
|
|
2240
2207
|
}
|
|
2241
2208
|
/**
|
|
2242
2209
|
* Materializes the iterator into a map.
|
|
@@ -2259,12 +2226,12 @@ const w = class w {
|
|
|
2259
2226
|
* @returns A {@link Promise} resolving to a {@link Map} containing all the entries of the iterator.
|
|
2260
2227
|
*/
|
|
2261
2228
|
async toMap() {
|
|
2262
|
-
const
|
|
2263
|
-
for await (const [
|
|
2264
|
-
const s =
|
|
2265
|
-
s.push(
|
|
2229
|
+
const e = /* @__PURE__ */ new Map();
|
|
2230
|
+
for await (const [t, n] of this._elements) {
|
|
2231
|
+
const s = e.get(t) ?? [];
|
|
2232
|
+
s.push(n), e.set(t, s);
|
|
2266
2233
|
}
|
|
2267
|
-
return
|
|
2234
|
+
return e;
|
|
2268
2235
|
}
|
|
2269
2236
|
/**
|
|
2270
2237
|
* Materializes the iterator into an object.
|
|
@@ -2287,56 +2254,54 @@ const w = class w {
|
|
|
2287
2254
|
* @returns A {@link Promise} resolving to an object containing all the entries of the iterator.
|
|
2288
2255
|
*/
|
|
2289
2256
|
async toObject() {
|
|
2290
|
-
const
|
|
2291
|
-
for await (const [
|
|
2292
|
-
const s =
|
|
2293
|
-
s.push(
|
|
2257
|
+
const e = {};
|
|
2258
|
+
for await (const [t, n] of this._elements) {
|
|
2259
|
+
const s = e[t] ?? [];
|
|
2260
|
+
s.push(n), e[t] = s;
|
|
2294
2261
|
}
|
|
2295
|
-
return
|
|
2262
|
+
return e;
|
|
2296
2263
|
}
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
var _e;
|
|
2264
|
+
[Symbol.toStringTag] = "AggregatedAsyncIterator";
|
|
2265
|
+
}
|
|
2300
2266
|
class d {
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
let t = [];
|
|
2267
|
+
/**
|
|
2268
|
+
* The native {@link AsyncIterator} object that is being wrapped by this instance.
|
|
2269
|
+
*/
|
|
2270
|
+
_iterator;
|
|
2271
|
+
constructor(e) {
|
|
2272
|
+
if (e instanceof Function) {
|
|
2273
|
+
const t = e();
|
|
2274
|
+
Symbol.asyncIterator in t ? this._iterator = t : this._iterator = (async function* () {
|
|
2275
|
+
let n = [];
|
|
2311
2276
|
for (; ; ) {
|
|
2312
|
-
const s =
|
|
2277
|
+
const s = t.next(...n);
|
|
2313
2278
|
if (s.done)
|
|
2314
2279
|
return s.value;
|
|
2315
|
-
|
|
2280
|
+
n = [yield s.value];
|
|
2316
2281
|
}
|
|
2317
|
-
}();
|
|
2318
|
-
} else if (Symbol.asyncIterator in
|
|
2319
|
-
this._iterator =
|
|
2320
|
-
else if (Symbol.iterator in
|
|
2321
|
-
const
|
|
2322
|
-
this._iterator = async function* () {
|
|
2282
|
+
})();
|
|
2283
|
+
} else if (Symbol.asyncIterator in e)
|
|
2284
|
+
this._iterator = e[Symbol.asyncIterator]();
|
|
2285
|
+
else if (Symbol.iterator in e) {
|
|
2286
|
+
const t = e[Symbol.iterator]();
|
|
2287
|
+
this._iterator = (async function* () {
|
|
2323
2288
|
for (; ; ) {
|
|
2324
|
-
const
|
|
2325
|
-
if (
|
|
2326
|
-
return
|
|
2327
|
-
yield
|
|
2289
|
+
const n = t.next();
|
|
2290
|
+
if (n.done)
|
|
2291
|
+
return n.value;
|
|
2292
|
+
yield n.value;
|
|
2328
2293
|
}
|
|
2329
|
-
}();
|
|
2294
|
+
})();
|
|
2330
2295
|
} else
|
|
2331
|
-
this._iterator = async function* () {
|
|
2332
|
-
let
|
|
2296
|
+
this._iterator = (async function* () {
|
|
2297
|
+
let t = [];
|
|
2333
2298
|
for (; ; ) {
|
|
2334
|
-
const
|
|
2335
|
-
if (
|
|
2336
|
-
return
|
|
2337
|
-
|
|
2299
|
+
const n = await e.next(...t);
|
|
2300
|
+
if (n.done)
|
|
2301
|
+
return n.value;
|
|
2302
|
+
t = [yield n.value];
|
|
2338
2303
|
}
|
|
2339
|
-
}();
|
|
2304
|
+
})();
|
|
2340
2305
|
}
|
|
2341
2306
|
/**
|
|
2342
2307
|
* Determines whether all elements of the iterator satisfy a given condition.
|
|
@@ -2368,15 +2333,15 @@ class d {
|
|
|
2368
2333
|
* @returns
|
|
2369
2334
|
* A {@link Promise} that will resolve to `true` if all elements satisfy the condition, `false` otherwise.
|
|
2370
2335
|
*/
|
|
2371
|
-
async every(
|
|
2372
|
-
let
|
|
2336
|
+
async every(e) {
|
|
2337
|
+
let t = 0;
|
|
2373
2338
|
for (; ; ) {
|
|
2374
|
-
const
|
|
2375
|
-
if (
|
|
2339
|
+
const n = await this._iterator.next();
|
|
2340
|
+
if (n.done)
|
|
2376
2341
|
return !0;
|
|
2377
|
-
if (!await n
|
|
2342
|
+
if (!await e(n.value, t))
|
|
2378
2343
|
return !1;
|
|
2379
|
-
|
|
2344
|
+
t += 1;
|
|
2380
2345
|
}
|
|
2381
2346
|
}
|
|
2382
2347
|
/**
|
|
@@ -2409,26 +2374,26 @@ class d {
|
|
|
2409
2374
|
* @returns
|
|
2410
2375
|
* A {@link Promise} that will resolve to `true` if any element satisfies the condition, `false` otherwise.
|
|
2411
2376
|
*/
|
|
2412
|
-
async some(
|
|
2413
|
-
let
|
|
2377
|
+
async some(e) {
|
|
2378
|
+
let t = 0;
|
|
2414
2379
|
for (; ; ) {
|
|
2415
|
-
const
|
|
2416
|
-
if (
|
|
2380
|
+
const n = await this._iterator.next();
|
|
2381
|
+
if (n.done)
|
|
2417
2382
|
return !1;
|
|
2418
|
-
if (await n
|
|
2383
|
+
if (await e(n.value, t))
|
|
2419
2384
|
return !0;
|
|
2420
|
-
|
|
2385
|
+
t += 1;
|
|
2421
2386
|
}
|
|
2422
2387
|
}
|
|
2423
|
-
filter(
|
|
2424
|
-
const
|
|
2388
|
+
filter(e) {
|
|
2389
|
+
const t = this._iterator;
|
|
2425
2390
|
return new d(async function* () {
|
|
2426
|
-
let
|
|
2391
|
+
let n = 0;
|
|
2427
2392
|
for (; ; ) {
|
|
2428
|
-
const s = await
|
|
2393
|
+
const s = await t.next();
|
|
2429
2394
|
if (s.done)
|
|
2430
2395
|
return s.value;
|
|
2431
|
-
await
|
|
2396
|
+
await e(s.value, n) && (yield s.value), n += 1;
|
|
2432
2397
|
}
|
|
2433
2398
|
});
|
|
2434
2399
|
}
|
|
@@ -2463,31 +2428,31 @@ class d {
|
|
|
2463
2428
|
*
|
|
2464
2429
|
* @returns A new {@link SmartAsyncIterator} containing the transformed elements.
|
|
2465
2430
|
*/
|
|
2466
|
-
map(
|
|
2467
|
-
const
|
|
2431
|
+
map(e) {
|
|
2432
|
+
const t = this._iterator;
|
|
2468
2433
|
return new d(async function* () {
|
|
2469
|
-
let
|
|
2434
|
+
let n = 0;
|
|
2470
2435
|
for (; ; ) {
|
|
2471
|
-
const s = await
|
|
2436
|
+
const s = await t.next();
|
|
2472
2437
|
if (s.done)
|
|
2473
2438
|
return s.value;
|
|
2474
|
-
yield await
|
|
2439
|
+
yield await e(s.value, n), n += 1;
|
|
2475
2440
|
}
|
|
2476
2441
|
});
|
|
2477
2442
|
}
|
|
2478
|
-
async reduce(
|
|
2479
|
-
let
|
|
2443
|
+
async reduce(e, t) {
|
|
2444
|
+
let n = 0, s = t;
|
|
2480
2445
|
if (s === void 0) {
|
|
2481
2446
|
const r = await this._iterator.next();
|
|
2482
2447
|
if (r.done)
|
|
2483
2448
|
throw new f("Cannot reduce an empty iterator without an initial value.");
|
|
2484
|
-
s = r.value,
|
|
2449
|
+
s = r.value, n += 1;
|
|
2485
2450
|
}
|
|
2486
2451
|
for (; ; ) {
|
|
2487
2452
|
const r = await this._iterator.next();
|
|
2488
2453
|
if (r.done)
|
|
2489
2454
|
return s;
|
|
2490
|
-
s = await
|
|
2455
|
+
s = await e(s, r.value, n), n += 1;
|
|
2491
2456
|
}
|
|
2492
2457
|
}
|
|
2493
2458
|
/**
|
|
@@ -2521,21 +2486,21 @@ class d {
|
|
|
2521
2486
|
*
|
|
2522
2487
|
* @returns A new {@link SmartAsyncIterator} containing the flattened elements.
|
|
2523
2488
|
*/
|
|
2524
|
-
flatMap(
|
|
2525
|
-
const
|
|
2489
|
+
flatMap(e) {
|
|
2490
|
+
const t = this._iterator;
|
|
2526
2491
|
return new d(async function* () {
|
|
2527
|
-
let
|
|
2492
|
+
let n = 0;
|
|
2528
2493
|
for (; ; ) {
|
|
2529
|
-
const s = await
|
|
2494
|
+
const s = await t.next();
|
|
2530
2495
|
if (s.done)
|
|
2531
2496
|
return s.value;
|
|
2532
|
-
const r = await
|
|
2497
|
+
const r = await e(s.value, n);
|
|
2533
2498
|
if (r instanceof Array)
|
|
2534
2499
|
for (const o of r)
|
|
2535
2500
|
yield o;
|
|
2536
2501
|
else
|
|
2537
2502
|
yield r;
|
|
2538
|
-
|
|
2503
|
+
n += 1;
|
|
2539
2504
|
}
|
|
2540
2505
|
});
|
|
2541
2506
|
}
|
|
@@ -2570,17 +2535,17 @@ class d {
|
|
|
2570
2535
|
*
|
|
2571
2536
|
* @returns A new {@link SmartAsyncIterator} containing the remaining elements.
|
|
2572
2537
|
*/
|
|
2573
|
-
drop(
|
|
2574
|
-
const
|
|
2538
|
+
drop(e) {
|
|
2539
|
+
const t = this._iterator;
|
|
2575
2540
|
return new d(async function* () {
|
|
2576
|
-
let
|
|
2577
|
-
for (;
|
|
2578
|
-
if ((await
|
|
2541
|
+
let n = 0;
|
|
2542
|
+
for (; n < e; ) {
|
|
2543
|
+
if ((await t.next()).done)
|
|
2579
2544
|
return;
|
|
2580
|
-
|
|
2545
|
+
n += 1;
|
|
2581
2546
|
}
|
|
2582
2547
|
for (; ; ) {
|
|
2583
|
-
const s = await
|
|
2548
|
+
const s = await t.next();
|
|
2584
2549
|
if (s.done)
|
|
2585
2550
|
return s.value;
|
|
2586
2551
|
yield s.value;
|
|
@@ -2619,27 +2584,27 @@ class d {
|
|
|
2619
2584
|
*
|
|
2620
2585
|
* @returns A new {@link SmartAsyncIterator} containing the taken elements.
|
|
2621
2586
|
*/
|
|
2622
|
-
take(
|
|
2623
|
-
const
|
|
2587
|
+
take(e) {
|
|
2588
|
+
const t = this._iterator;
|
|
2624
2589
|
return new d(async function* () {
|
|
2625
|
-
let
|
|
2626
|
-
for (;
|
|
2627
|
-
const s = await
|
|
2590
|
+
let n = 0;
|
|
2591
|
+
for (; n < e; ) {
|
|
2592
|
+
const s = await t.next();
|
|
2628
2593
|
if (s.done)
|
|
2629
2594
|
return s.value;
|
|
2630
|
-
yield s.value,
|
|
2595
|
+
yield s.value, n += 1;
|
|
2631
2596
|
}
|
|
2632
2597
|
});
|
|
2633
2598
|
}
|
|
2634
|
-
async find(
|
|
2635
|
-
let
|
|
2599
|
+
async find(e) {
|
|
2600
|
+
let t = 0;
|
|
2636
2601
|
for (; ; ) {
|
|
2637
|
-
const
|
|
2638
|
-
if (
|
|
2602
|
+
const n = await this._iterator.next();
|
|
2603
|
+
if (n.done)
|
|
2639
2604
|
return;
|
|
2640
|
-
if (await n
|
|
2641
|
-
return
|
|
2642
|
-
|
|
2605
|
+
if (await e(n.value, t))
|
|
2606
|
+
return n.value;
|
|
2607
|
+
t += 1;
|
|
2643
2608
|
}
|
|
2644
2609
|
}
|
|
2645
2610
|
/**
|
|
@@ -2671,7 +2636,7 @@ class d {
|
|
|
2671
2636
|
* @returns A new {@link SmartAsyncIterator} containing the enumerated elements.
|
|
2672
2637
|
*/
|
|
2673
2638
|
enumerate() {
|
|
2674
|
-
return this.map((
|
|
2639
|
+
return this.map((e, t) => [t, e]);
|
|
2675
2640
|
}
|
|
2676
2641
|
/**
|
|
2677
2642
|
* Removes all duplicate elements from the iterator.
|
|
@@ -2699,14 +2664,14 @@ class d {
|
|
|
2699
2664
|
* @returns A new {@link SmartAsyncIterator} containing only the unique elements.
|
|
2700
2665
|
*/
|
|
2701
2666
|
unique() {
|
|
2702
|
-
const
|
|
2667
|
+
const e = this._iterator;
|
|
2703
2668
|
return new d(async function* () {
|
|
2704
|
-
const
|
|
2669
|
+
const t = /* @__PURE__ */ new Set();
|
|
2705
2670
|
for (; ; ) {
|
|
2706
|
-
const
|
|
2707
|
-
if (
|
|
2708
|
-
return
|
|
2709
|
-
|
|
2671
|
+
const n = await e.next();
|
|
2672
|
+
if (n.done)
|
|
2673
|
+
return n.value;
|
|
2674
|
+
t.has(n.value) || (t.add(n.value), yield n.value);
|
|
2710
2675
|
}
|
|
2711
2676
|
});
|
|
2712
2677
|
}
|
|
@@ -2731,11 +2696,11 @@ class d {
|
|
|
2731
2696
|
* @returns A {@link Promise} that will resolve to the number of elements in the iterator.
|
|
2732
2697
|
*/
|
|
2733
2698
|
async count() {
|
|
2734
|
-
let
|
|
2699
|
+
let e = 0;
|
|
2735
2700
|
for (; ; ) {
|
|
2736
2701
|
if ((await this._iterator.next()).done)
|
|
2737
|
-
return
|
|
2738
|
-
|
|
2702
|
+
return e;
|
|
2703
|
+
e += 1;
|
|
2739
2704
|
}
|
|
2740
2705
|
}
|
|
2741
2706
|
/**
|
|
@@ -2762,13 +2727,13 @@ class d {
|
|
|
2762
2727
|
*
|
|
2763
2728
|
* @returns A {@link Promise} that will resolve once the iteration is complete.
|
|
2764
2729
|
*/
|
|
2765
|
-
async forEach(
|
|
2766
|
-
let
|
|
2730
|
+
async forEach(e) {
|
|
2731
|
+
let t = 0;
|
|
2767
2732
|
for (; ; ) {
|
|
2768
|
-
const
|
|
2769
|
-
if (
|
|
2733
|
+
const n = await this._iterator.next();
|
|
2734
|
+
if (n.done)
|
|
2770
2735
|
return;
|
|
2771
|
-
await n
|
|
2736
|
+
await e(n.value, t), t += 1;
|
|
2772
2737
|
}
|
|
2773
2738
|
}
|
|
2774
2739
|
/**
|
|
@@ -2801,8 +2766,8 @@ class d {
|
|
|
2801
2766
|
* @returns
|
|
2802
2767
|
* A {@link Promise} that will resolve to the result of the iteration, containing the value of the operation.
|
|
2803
2768
|
*/
|
|
2804
|
-
next(...
|
|
2805
|
-
return this._iterator.next(...
|
|
2769
|
+
next(...e) {
|
|
2770
|
+
return this._iterator.next(...e);
|
|
2806
2771
|
}
|
|
2807
2772
|
/**
|
|
2808
2773
|
* An utility method that may be used to close the iterator gracefully,
|
|
@@ -2836,9 +2801,9 @@ class d {
|
|
|
2836
2801
|
*
|
|
2837
2802
|
* @returns A {@link Promise} that will resolve to the final result of the iterator.
|
|
2838
2803
|
*/
|
|
2839
|
-
async return(
|
|
2840
|
-
const
|
|
2841
|
-
return this._iterator.return ? await this._iterator.return(
|
|
2804
|
+
async return(e) {
|
|
2805
|
+
const t = await e;
|
|
2806
|
+
return this._iterator.return ? await this._iterator.return(t) : { done: !0, value: t };
|
|
2842
2807
|
}
|
|
2843
2808
|
/**
|
|
2844
2809
|
* An utility method that may be used to close the iterator due to an error,
|
|
@@ -2881,10 +2846,10 @@ class d {
|
|
|
2881
2846
|
*
|
|
2882
2847
|
* @returns A {@link Promise} that will resolve to the final result of the iterator.
|
|
2883
2848
|
*/
|
|
2884
|
-
throw(
|
|
2849
|
+
throw(e) {
|
|
2885
2850
|
if (this._iterator.throw)
|
|
2886
|
-
return this._iterator.throw(
|
|
2887
|
-
throw
|
|
2851
|
+
return this._iterator.throw(e);
|
|
2852
|
+
throw e;
|
|
2888
2853
|
}
|
|
2889
2854
|
/**
|
|
2890
2855
|
* An utility method that aggregates the elements of the iterator using a given key function.
|
|
@@ -2916,8 +2881,8 @@ class d {
|
|
|
2916
2881
|
*
|
|
2917
2882
|
* @returns A new instance of the {@link AggregatedAsyncIterator} class containing the grouped elements.
|
|
2918
2883
|
*/
|
|
2919
|
-
groupBy(
|
|
2920
|
-
return new
|
|
2884
|
+
groupBy(e) {
|
|
2885
|
+
return new m(this.map(async (t, n) => [await e(t, n), t]));
|
|
2921
2886
|
}
|
|
2922
2887
|
/**
|
|
2923
2888
|
* Materializes the iterator into an array.
|
|
@@ -2945,20 +2910,18 @@ class d {
|
|
|
2945
2910
|
toArray() {
|
|
2946
2911
|
return Array.fromAsync(this);
|
|
2947
2912
|
}
|
|
2948
|
-
[
|
|
2913
|
+
[Symbol.toStringTag] = "SmartAsyncIterator";
|
|
2914
|
+
[Symbol.asyncIterator]() {
|
|
2949
2915
|
return this;
|
|
2950
2916
|
}
|
|
2951
2917
|
}
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
a(this, "_elements");
|
|
2960
|
-
a(this, ye, "AggregatedIterator");
|
|
2961
|
-
this._elements = new u(n);
|
|
2918
|
+
class h {
|
|
2919
|
+
/**
|
|
2920
|
+
* The internal {@link SmartIterator} object that holds the elements to aggregate.
|
|
2921
|
+
*/
|
|
2922
|
+
_elements;
|
|
2923
|
+
constructor(e) {
|
|
2924
|
+
this._elements = new l(e);
|
|
2962
2925
|
}
|
|
2963
2926
|
/**
|
|
2964
2927
|
* Determines whether all elements of each group of the iterator satisfy a given condition.
|
|
@@ -2990,15 +2953,15 @@ const m = class m {
|
|
|
2990
2953
|
*
|
|
2991
2954
|
* @returns A new {@link ReducedIterator} containing the boolean results for each group.
|
|
2992
2955
|
*/
|
|
2993
|
-
every(
|
|
2994
|
-
const
|
|
2995
|
-
for (const [
|
|
2996
|
-
const [r, o] =
|
|
2997
|
-
o &&
|
|
2956
|
+
every(e) {
|
|
2957
|
+
const t = /* @__PURE__ */ new Map();
|
|
2958
|
+
for (const [n, s] of this._elements) {
|
|
2959
|
+
const [r, o] = t.get(n) ?? [0, !0];
|
|
2960
|
+
o && t.set(n, [r + 1, e(n, s, r)]);
|
|
2998
2961
|
}
|
|
2999
|
-
return new
|
|
3000
|
-
for (const [
|
|
3001
|
-
yield [
|
|
2962
|
+
return new u(function* () {
|
|
2963
|
+
for (const [n, [s, r]] of t)
|
|
2964
|
+
yield [n, r];
|
|
3002
2965
|
});
|
|
3003
2966
|
}
|
|
3004
2967
|
/**
|
|
@@ -3031,24 +2994,24 @@ const m = class m {
|
|
|
3031
2994
|
*
|
|
3032
2995
|
* @returns A {@link ReducedIterator} containing the boolean results for each group.
|
|
3033
2996
|
*/
|
|
3034
|
-
some(
|
|
3035
|
-
const
|
|
3036
|
-
for (const [
|
|
3037
|
-
const [r, o] =
|
|
3038
|
-
o ||
|
|
2997
|
+
some(e) {
|
|
2998
|
+
const t = /* @__PURE__ */ new Map();
|
|
2999
|
+
for (const [n, s] of this._elements) {
|
|
3000
|
+
const [r, o] = t.get(n) ?? [0, !1];
|
|
3001
|
+
o || t.set(n, [r + 1, e(n, s, r)]);
|
|
3039
3002
|
}
|
|
3040
|
-
return new
|
|
3041
|
-
for (const [
|
|
3042
|
-
yield [
|
|
3003
|
+
return new u(function* () {
|
|
3004
|
+
for (const [n, [s, r]] of t)
|
|
3005
|
+
yield [n, r];
|
|
3043
3006
|
});
|
|
3044
3007
|
}
|
|
3045
|
-
filter(
|
|
3046
|
-
const
|
|
3047
|
-
return new
|
|
3048
|
-
const
|
|
3049
|
-
for (const [s, r] of
|
|
3050
|
-
const o =
|
|
3051
|
-
|
|
3008
|
+
filter(e) {
|
|
3009
|
+
const t = this._elements;
|
|
3010
|
+
return new h(function* () {
|
|
3011
|
+
const n = /* @__PURE__ */ new Map();
|
|
3012
|
+
for (const [s, r] of t) {
|
|
3013
|
+
const o = n.get(s) ?? 0;
|
|
3014
|
+
e(s, r, o) && (yield [s, r]), n.set(s, o + 1);
|
|
3052
3015
|
}
|
|
3053
3016
|
});
|
|
3054
3017
|
}
|
|
@@ -3084,32 +3047,32 @@ const m = class m {
|
|
|
3084
3047
|
*
|
|
3085
3048
|
* @returns A new {@link AggregatedIterator} containing the transformed elements.
|
|
3086
3049
|
*/
|
|
3087
|
-
map(
|
|
3088
|
-
const
|
|
3089
|
-
return new
|
|
3090
|
-
const
|
|
3091
|
-
for (const [s, r] of
|
|
3092
|
-
const o =
|
|
3093
|
-
yield [s,
|
|
3050
|
+
map(e) {
|
|
3051
|
+
const t = this._elements;
|
|
3052
|
+
return new h(function* () {
|
|
3053
|
+
const n = /* @__PURE__ */ new Map();
|
|
3054
|
+
for (const [s, r] of t) {
|
|
3055
|
+
const o = n.get(s) ?? 0;
|
|
3056
|
+
yield [s, e(s, r, o)], n.set(s, o + 1);
|
|
3094
3057
|
}
|
|
3095
3058
|
});
|
|
3096
3059
|
}
|
|
3097
|
-
reduce(
|
|
3098
|
-
const
|
|
3060
|
+
reduce(e, t) {
|
|
3061
|
+
const n = /* @__PURE__ */ new Map();
|
|
3099
3062
|
for (const [s, r] of this._elements) {
|
|
3100
|
-
let o,
|
|
3101
|
-
if (
|
|
3102
|
-
[o,
|
|
3103
|
-
else if (
|
|
3104
|
-
o = 0,
|
|
3063
|
+
let o, a;
|
|
3064
|
+
if (n.has(s))
|
|
3065
|
+
[o, a] = n.get(s);
|
|
3066
|
+
else if (t !== void 0)
|
|
3067
|
+
o = 0, t instanceof Function ? a = t(s) : a = t;
|
|
3105
3068
|
else {
|
|
3106
|
-
|
|
3069
|
+
n.set(s, [0, r]);
|
|
3107
3070
|
continue;
|
|
3108
3071
|
}
|
|
3109
|
-
|
|
3072
|
+
n.set(s, [o + 1, e(s, a, r, o)]);
|
|
3110
3073
|
}
|
|
3111
|
-
return new
|
|
3112
|
-
for (const [s, [r, o]] of
|
|
3074
|
+
return new u(function* () {
|
|
3075
|
+
for (const [s, [r, o]] of n)
|
|
3113
3076
|
yield [s, o];
|
|
3114
3077
|
});
|
|
3115
3078
|
}
|
|
@@ -3149,18 +3112,18 @@ const m = class m {
|
|
|
3149
3112
|
*
|
|
3150
3113
|
* @returns A new {@link AggregatedIterator} containing the transformed elements.
|
|
3151
3114
|
*/
|
|
3152
|
-
flatMap(
|
|
3153
|
-
const
|
|
3154
|
-
return new
|
|
3155
|
-
const
|
|
3156
|
-
for (const [s, r] of
|
|
3157
|
-
const o =
|
|
3158
|
-
if (
|
|
3159
|
-
for (const
|
|
3160
|
-
yield [s,
|
|
3115
|
+
flatMap(e) {
|
|
3116
|
+
const t = this._elements;
|
|
3117
|
+
return new h(function* () {
|
|
3118
|
+
const n = /* @__PURE__ */ new Map();
|
|
3119
|
+
for (const [s, r] of t) {
|
|
3120
|
+
const o = n.get(s) ?? 0, a = e(s, r, o);
|
|
3121
|
+
if (a instanceof Array)
|
|
3122
|
+
for (const y of a)
|
|
3123
|
+
yield [s, y];
|
|
3161
3124
|
else
|
|
3162
|
-
yield [s,
|
|
3163
|
-
|
|
3125
|
+
yield [s, a];
|
|
3126
|
+
n.set(s, o + 1);
|
|
3164
3127
|
}
|
|
3165
3128
|
});
|
|
3166
3129
|
}
|
|
@@ -3193,14 +3156,14 @@ const m = class m {
|
|
|
3193
3156
|
*
|
|
3194
3157
|
* @returns A new {@link AggregatedIterator} containing the remaining elements.
|
|
3195
3158
|
*/
|
|
3196
|
-
drop(
|
|
3197
|
-
const
|
|
3198
|
-
return new
|
|
3199
|
-
const
|
|
3200
|
-
for (const [s, r] of
|
|
3201
|
-
const o =
|
|
3202
|
-
if (o <
|
|
3203
|
-
|
|
3159
|
+
drop(e) {
|
|
3160
|
+
const t = this._elements;
|
|
3161
|
+
return new h(function* () {
|
|
3162
|
+
const n = /* @__PURE__ */ new Map();
|
|
3163
|
+
for (const [s, r] of t) {
|
|
3164
|
+
const o = n.get(s) ?? 0;
|
|
3165
|
+
if (o < e) {
|
|
3166
|
+
n.set(s, o + 1);
|
|
3204
3167
|
continue;
|
|
3205
3168
|
}
|
|
3206
3169
|
yield [s, r];
|
|
@@ -3236,25 +3199,25 @@ const m = class m {
|
|
|
3236
3199
|
*
|
|
3237
3200
|
* @returns A new {@link AggregatedIterator} containing the taken elements.
|
|
3238
3201
|
*/
|
|
3239
|
-
take(
|
|
3240
|
-
const
|
|
3241
|
-
return new
|
|
3242
|
-
const
|
|
3243
|
-
for (const [s, r] of
|
|
3244
|
-
const o =
|
|
3245
|
-
o >=
|
|
3202
|
+
take(e) {
|
|
3203
|
+
const t = this._elements;
|
|
3204
|
+
return new h(function* () {
|
|
3205
|
+
const n = /* @__PURE__ */ new Map();
|
|
3206
|
+
for (const [s, r] of t) {
|
|
3207
|
+
const o = n.get(s) ?? 0;
|
|
3208
|
+
o >= e || (yield [s, r], n.set(s, o + 1));
|
|
3246
3209
|
}
|
|
3247
3210
|
});
|
|
3248
3211
|
}
|
|
3249
|
-
find(
|
|
3250
|
-
const
|
|
3251
|
-
for (const [
|
|
3252
|
-
let [r, o] =
|
|
3253
|
-
o === void 0 && (n
|
|
3212
|
+
find(e) {
|
|
3213
|
+
const t = /* @__PURE__ */ new Map();
|
|
3214
|
+
for (const [n, s] of this._elements) {
|
|
3215
|
+
let [r, o] = t.get(n) ?? [0, void 0];
|
|
3216
|
+
o === void 0 && (e(n, s, r) && (o = s), t.set(n, [r + 1, o]));
|
|
3254
3217
|
}
|
|
3255
|
-
return new
|
|
3256
|
-
for (const [
|
|
3257
|
-
yield [
|
|
3218
|
+
return new u(function* () {
|
|
3219
|
+
for (const [n, [s, r]] of t)
|
|
3220
|
+
yield [n, r];
|
|
3258
3221
|
});
|
|
3259
3222
|
}
|
|
3260
3223
|
/**
|
|
@@ -3284,7 +3247,7 @@ const m = class m {
|
|
|
3284
3247
|
* @returns A new {@link AggregatedIterator} containing the enumerated elements.
|
|
3285
3248
|
*/
|
|
3286
3249
|
enumerate() {
|
|
3287
|
-
return this.map((
|
|
3250
|
+
return this.map((e, t, n) => [n, t]);
|
|
3288
3251
|
}
|
|
3289
3252
|
/**
|
|
3290
3253
|
* Removes all duplicate elements from within each group of the iterator.
|
|
@@ -3313,12 +3276,12 @@ const m = class m {
|
|
|
3313
3276
|
* @returns A new {@link AggregatedIterator} containing only the unique elements.
|
|
3314
3277
|
*/
|
|
3315
3278
|
unique() {
|
|
3316
|
-
const
|
|
3317
|
-
return new
|
|
3318
|
-
const
|
|
3319
|
-
for (const [
|
|
3320
|
-
const r =
|
|
3321
|
-
r.has(s) || (r.add(s),
|
|
3279
|
+
const e = this._elements;
|
|
3280
|
+
return new h(function* () {
|
|
3281
|
+
const t = /* @__PURE__ */ new Map();
|
|
3282
|
+
for (const [n, s] of e) {
|
|
3283
|
+
const r = t.get(n) ?? /* @__PURE__ */ new Set();
|
|
3284
|
+
r.has(s) || (r.add(s), t.set(n, r), yield [n, s]);
|
|
3322
3285
|
}
|
|
3323
3286
|
});
|
|
3324
3287
|
}
|
|
@@ -3344,14 +3307,14 @@ const m = class m {
|
|
|
3344
3307
|
* @returns A new {@link ReducedIterator} containing the number of elements for each group.
|
|
3345
3308
|
*/
|
|
3346
3309
|
count() {
|
|
3347
|
-
const
|
|
3348
|
-
for (const [
|
|
3349
|
-
const
|
|
3350
|
-
|
|
3310
|
+
const e = /* @__PURE__ */ new Map();
|
|
3311
|
+
for (const [t] of this._elements) {
|
|
3312
|
+
const n = e.get(t) ?? 0;
|
|
3313
|
+
e.set(t, n + 1);
|
|
3351
3314
|
}
|
|
3352
|
-
return new
|
|
3353
|
-
for (const [
|
|
3354
|
-
yield [
|
|
3315
|
+
return new u(function* () {
|
|
3316
|
+
for (const [t, n] of e)
|
|
3317
|
+
yield [t, n];
|
|
3355
3318
|
});
|
|
3356
3319
|
}
|
|
3357
3320
|
/**
|
|
@@ -3378,11 +3341,11 @@ const m = class m {
|
|
|
3378
3341
|
*
|
|
3379
3342
|
* @param iteratee The function to execute for each element of the iterator.
|
|
3380
3343
|
*/
|
|
3381
|
-
forEach(
|
|
3382
|
-
const
|
|
3383
|
-
for (const [
|
|
3384
|
-
const r =
|
|
3385
|
-
n
|
|
3344
|
+
forEach(e) {
|
|
3345
|
+
const t = /* @__PURE__ */ new Map();
|
|
3346
|
+
for (const [n, s] of this._elements) {
|
|
3347
|
+
const r = t.get(n) ?? 0;
|
|
3348
|
+
e(n, s, r), t.set(n, r + 1);
|
|
3386
3349
|
}
|
|
3387
3350
|
}
|
|
3388
3351
|
/**
|
|
@@ -3416,13 +3379,13 @@ const m = class m {
|
|
|
3416
3379
|
*
|
|
3417
3380
|
* @returns A new {@link AggregatedIterator} containing the elements reorganized by the new keys.
|
|
3418
3381
|
*/
|
|
3419
|
-
reorganizeBy(
|
|
3420
|
-
const
|
|
3421
|
-
return new
|
|
3422
|
-
const
|
|
3423
|
-
for (const [s, r] of
|
|
3424
|
-
const o =
|
|
3425
|
-
yield [
|
|
3382
|
+
reorganizeBy(e) {
|
|
3383
|
+
const t = this._elements;
|
|
3384
|
+
return new h(function* () {
|
|
3385
|
+
const n = /* @__PURE__ */ new Map();
|
|
3386
|
+
for (const [s, r] of t) {
|
|
3387
|
+
const o = n.get(s) ?? 0;
|
|
3388
|
+
yield [e(s, r, o), r], n.set(s, o + 1);
|
|
3426
3389
|
}
|
|
3427
3390
|
});
|
|
3428
3391
|
}
|
|
@@ -3453,11 +3416,11 @@ const m = class m {
|
|
|
3453
3416
|
* @returns A new {@link SmartIterator} containing all the keys of the iterator.
|
|
3454
3417
|
*/
|
|
3455
3418
|
keys() {
|
|
3456
|
-
const
|
|
3457
|
-
return new
|
|
3458
|
-
const
|
|
3459
|
-
for (const [
|
|
3460
|
-
|
|
3419
|
+
const e = this._elements;
|
|
3420
|
+
return new l(function* () {
|
|
3421
|
+
const t = /* @__PURE__ */ new Set();
|
|
3422
|
+
for (const [n] of e)
|
|
3423
|
+
t.has(n) || (t.add(n), yield n);
|
|
3461
3424
|
});
|
|
3462
3425
|
}
|
|
3463
3426
|
/**
|
|
@@ -3517,10 +3480,10 @@ const m = class m {
|
|
|
3517
3480
|
* @returns A new {@link SmartIterator} containing all the values of the iterator.
|
|
3518
3481
|
*/
|
|
3519
3482
|
values() {
|
|
3520
|
-
const
|
|
3521
|
-
return new
|
|
3522
|
-
for (const [
|
|
3523
|
-
yield
|
|
3483
|
+
const e = this._elements;
|
|
3484
|
+
return new l(function* () {
|
|
3485
|
+
for (const [t, n] of e)
|
|
3486
|
+
yield n;
|
|
3524
3487
|
});
|
|
3525
3488
|
}
|
|
3526
3489
|
/**
|
|
@@ -3544,8 +3507,8 @@ const m = class m {
|
|
|
3544
3507
|
* @returns An {@link Array} of arrays containing the elements of the iterator.
|
|
3545
3508
|
*/
|
|
3546
3509
|
toArray() {
|
|
3547
|
-
const
|
|
3548
|
-
return Array.from(
|
|
3510
|
+
const e = this.toMap();
|
|
3511
|
+
return Array.from(e.values());
|
|
3549
3512
|
}
|
|
3550
3513
|
/**
|
|
3551
3514
|
* Materializes the iterator into a map.
|
|
@@ -3568,12 +3531,12 @@ const m = class m {
|
|
|
3568
3531
|
* @returns A {@link Map} containing the elements of the iterator.
|
|
3569
3532
|
*/
|
|
3570
3533
|
toMap() {
|
|
3571
|
-
const
|
|
3572
|
-
for (const [
|
|
3573
|
-
const s =
|
|
3574
|
-
s.push(
|
|
3534
|
+
const e = /* @__PURE__ */ new Map();
|
|
3535
|
+
for (const [t, n] of this._elements) {
|
|
3536
|
+
const s = e.get(t) ?? [];
|
|
3537
|
+
s.push(n), e.set(t, s);
|
|
3575
3538
|
}
|
|
3576
|
-
return
|
|
3539
|
+
return e;
|
|
3577
3540
|
}
|
|
3578
3541
|
/**
|
|
3579
3542
|
* Materializes the iterator into an object.
|
|
@@ -3596,31 +3559,35 @@ const m = class m {
|
|
|
3596
3559
|
* @returns An {@link Object} containing the elements of the iterator.
|
|
3597
3560
|
*/
|
|
3598
3561
|
toObject() {
|
|
3599
|
-
const
|
|
3600
|
-
for (const [
|
|
3601
|
-
const s =
|
|
3602
|
-
s.push(
|
|
3562
|
+
const e = {};
|
|
3563
|
+
for (const [t, n] of this._elements) {
|
|
3564
|
+
const s = e[t] ?? [];
|
|
3565
|
+
s.push(n), e[t] = s;
|
|
3603
3566
|
}
|
|
3604
|
-
return
|
|
3567
|
+
return e;
|
|
3605
3568
|
}
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
const
|
|
3609
|
-
|
|
3610
|
-
class Ue extends (ge = We, be = Symbol.toStringTag, ge) {
|
|
3569
|
+
[Symbol.toStringTag] = "AggregatedIterator";
|
|
3570
|
+
}
|
|
3571
|
+
const N = Function;
|
|
3572
|
+
class O extends N {
|
|
3611
3573
|
/**
|
|
3612
3574
|
* Initializes a new instance of the {@link CallableObject} class.
|
|
3613
3575
|
*/
|
|
3614
3576
|
constructor() {
|
|
3615
3577
|
super("return this._invoke(...arguments);");
|
|
3616
|
-
a(this, be, "CallableObject");
|
|
3617
3578
|
const e = this.bind(this);
|
|
3618
3579
|
return Object.setPrototypeOf(this, e), e;
|
|
3619
3580
|
}
|
|
3581
|
+
[Symbol.toStringTag] = "CallableObject";
|
|
3620
3582
|
}
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3583
|
+
class g {
|
|
3584
|
+
/**
|
|
3585
|
+
* A map containing all the subscribers for each event.
|
|
3586
|
+
*
|
|
3587
|
+
* The keys are the names of the events they are subscribed to.
|
|
3588
|
+
* The values are the arrays of the subscribers themselves.
|
|
3589
|
+
*/
|
|
3590
|
+
_subscribers;
|
|
3624
3591
|
/**
|
|
3625
3592
|
* Initializes a new instance of the {@link Publisher} class.
|
|
3626
3593
|
*
|
|
@@ -3632,39 +3599,8 @@ const F = class F {
|
|
|
3632
3599
|
* ```
|
|
3633
3600
|
*/
|
|
3634
3601
|
constructor() {
|
|
3635
|
-
/**
|
|
3636
|
-
* A map containing all the subscribers for each event.
|
|
3637
|
-
*
|
|
3638
|
-
* The keys are the names of the events they are subscribed to.
|
|
3639
|
-
* The values are the arrays of the subscribers themselves.
|
|
3640
|
-
*/
|
|
3641
|
-
a(this, "_subscribers");
|
|
3642
|
-
a(this, xe, "Publisher");
|
|
3643
3602
|
this._subscribers = /* @__PURE__ */ new Map();
|
|
3644
3603
|
}
|
|
3645
|
-
/**
|
|
3646
|
-
* Unsubscribes all the subscribers from all the events.
|
|
3647
|
-
*
|
|
3648
|
-
* ---
|
|
3649
|
-
*
|
|
3650
|
-
* @example
|
|
3651
|
-
* ```ts
|
|
3652
|
-
* publisher.subscribe("player:spawn", (evt) => { [...] });
|
|
3653
|
-
* publisher.subscribe("player:move", (coords) => { [...] });
|
|
3654
|
-
* publisher.subscribe("player:move", () => { [...] });
|
|
3655
|
-
* publisher.subscribe("player:move", ({ x, y }) => { [...] });
|
|
3656
|
-
* publisher.subscribe("player:death", () => { [...] });
|
|
3657
|
-
*
|
|
3658
|
-
* // All these subscribers are working fine...
|
|
3659
|
-
*
|
|
3660
|
-
* publisher.clear();
|
|
3661
|
-
*
|
|
3662
|
-
* // ... but now they're all gone!
|
|
3663
|
-
* ```
|
|
3664
|
-
*/
|
|
3665
|
-
clear() {
|
|
3666
|
-
this.publish("__internals__:clear"), this._subscribers.clear();
|
|
3667
|
-
}
|
|
3668
3604
|
/**
|
|
3669
3605
|
* Creates a new scoped instance of the {@link Publisher} class,
|
|
3670
3606
|
* which can be used to publish and subscribe events within a specific context.
|
|
@@ -3680,8 +3616,8 @@ const F = class F {
|
|
|
3680
3616
|
* const publisher = new Publisher();
|
|
3681
3617
|
* const context = publisher.createScope();
|
|
3682
3618
|
*
|
|
3683
|
-
* publisher.subscribe("player:death", () => console.log(
|
|
3684
|
-
* context.subscribe("player:spawn", () => console.log(
|
|
3619
|
+
* publisher.subscribe("player:death", () => console.log("Player has died."));
|
|
3620
|
+
* context.subscribe("player:spawn", () => console.log("Player has spawned."));
|
|
3685
3621
|
*
|
|
3686
3622
|
* publisher.publish("player:spawn"); // "Player has spawned."
|
|
3687
3623
|
* context.publish("player:death"); // * no output *
|
|
@@ -3700,93 +3636,116 @@ const F = class F {
|
|
|
3700
3636
|
*/
|
|
3701
3637
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
3702
3638
|
createScope() {
|
|
3703
|
-
const
|
|
3704
|
-
return this.subscribe("__internals__:clear", () =>
|
|
3705
|
-
|
|
3706
|
-
}),
|
|
3707
|
-
}
|
|
3708
|
-
publish(
|
|
3709
|
-
let
|
|
3710
|
-
return s ?
|
|
3711
|
-
}
|
|
3712
|
-
subscribe(
|
|
3713
|
-
const
|
|
3714
|
-
return
|
|
3715
|
-
const s =
|
|
3639
|
+
const e = new g();
|
|
3640
|
+
return this.subscribe("__internals__:clear", () => e.clear()), this.subscribe("*", (t, ...n) => {
|
|
3641
|
+
e.publish(t, ...n);
|
|
3642
|
+
}), e;
|
|
3643
|
+
}
|
|
3644
|
+
publish(e, ...t) {
|
|
3645
|
+
let n, s = this._subscribers.get(e);
|
|
3646
|
+
return s ? n = s.slice().map((r) => r(...t)) : n = [], e.startsWith("__") || (s = this._subscribers.get("*"), s && s.slice().forEach((r) => r(e, ...t))), n;
|
|
3647
|
+
}
|
|
3648
|
+
subscribe(e, t) {
|
|
3649
|
+
const n = this._subscribers.get(e) ?? [];
|
|
3650
|
+
return n.push(t), this._subscribers.set(e, n), () => {
|
|
3651
|
+
const s = n.indexOf(t);
|
|
3716
3652
|
if (s < 0)
|
|
3717
|
-
throw new
|
|
3718
|
-
|
|
3653
|
+
throw new S("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed.");
|
|
3654
|
+
n.splice(s, 1);
|
|
3719
3655
|
};
|
|
3720
3656
|
}
|
|
3721
|
-
unsubscribe(
|
|
3722
|
-
const
|
|
3723
|
-
if (!
|
|
3724
|
-
throw new
|
|
3725
|
-
const s =
|
|
3657
|
+
unsubscribe(e, t) {
|
|
3658
|
+
const n = this._subscribers.get(e);
|
|
3659
|
+
if (!n)
|
|
3660
|
+
throw new S("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed or was never subscribed.");
|
|
3661
|
+
const s = n.indexOf(t);
|
|
3726
3662
|
if (s < 0)
|
|
3727
|
-
throw new
|
|
3728
|
-
|
|
3663
|
+
throw new S("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed or was never subscribed.");
|
|
3664
|
+
n.splice(s, 1), n.length === 0 && this._subscribers.delete(e);
|
|
3729
3665
|
}
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
const et = () => {
|
|
3733
|
-
};
|
|
3734
|
-
var ve, Se;
|
|
3735
|
-
class dt extends (Se = Ue, ve = Symbol.toStringTag, Se) {
|
|
3736
|
-
constructor(e, t = "default") {
|
|
3737
|
-
super();
|
|
3738
|
-
/**
|
|
3739
|
-
* The currently selected implementation of the callback.
|
|
3740
|
-
*/
|
|
3741
|
-
a(this, "_callback");
|
|
3742
|
-
/**
|
|
3743
|
-
* All the implementations that have been registered for the callback.
|
|
3744
|
-
*
|
|
3745
|
-
* The keys are the names of the implementations they were registered with.
|
|
3746
|
-
* The values are the implementations themselves.
|
|
3747
|
-
*/
|
|
3748
|
-
a(this, "_callbacks");
|
|
3749
|
-
/**
|
|
3750
|
-
* A flag indicating whether the callback is enabled or not.
|
|
3751
|
-
*
|
|
3752
|
-
* This protected property is the only one that can be modified directly by the derived classes.
|
|
3753
|
-
* If you're looking for the public and readonly property, use
|
|
3754
|
-
* the {@link SwitchableCallback.isEnabled} getter instead.
|
|
3755
|
-
*/
|
|
3756
|
-
a(this, "_isEnabled");
|
|
3757
|
-
/**
|
|
3758
|
-
* The key that is associated with the currently selected implementation.
|
|
3759
|
-
*
|
|
3760
|
-
* This protected property is the only one that can be modified directly by the derived classes.
|
|
3761
|
-
* If you're looking for the public and readonly property, use the {@link SwitchableCallback.key} getter instead.
|
|
3762
|
-
*/
|
|
3763
|
-
a(this, "_key");
|
|
3764
|
-
/**
|
|
3765
|
-
* The function that will be called by the extended class when the object is invoked as a function.
|
|
3766
|
-
*/
|
|
3767
|
-
a(this, "_invoke");
|
|
3768
|
-
a(this, ve, "SwitchableCallback");
|
|
3769
|
-
this._callbacks = /* @__PURE__ */ new Map(), this._isEnabled = !0, e ? this._callbacks.set(t, e) : (t = "", e = () => {
|
|
3770
|
-
throw new He(
|
|
3771
|
-
"The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
|
|
3772
|
-
);
|
|
3773
|
-
}), this._key = t, this._callback = e, this._invoke = (...s) => this._callback(...s);
|
|
3666
|
+
unsubscribeAll(e) {
|
|
3667
|
+
this._subscribers.delete(e);
|
|
3774
3668
|
}
|
|
3775
3669
|
/**
|
|
3776
|
-
*
|
|
3670
|
+
* Unsubscribes all the subscribers from all the events.
|
|
3777
3671
|
*
|
|
3778
|
-
*
|
|
3779
|
-
*
|
|
3672
|
+
* ---
|
|
3673
|
+
*
|
|
3674
|
+
* @example
|
|
3675
|
+
* ```ts
|
|
3676
|
+
* publisher.subscribe("player:spawn", (evt) => { [...] });
|
|
3677
|
+
* publisher.subscribe("player:move", (coords) => { [...] });
|
|
3678
|
+
* publisher.subscribe("*", () => { [...] });
|
|
3679
|
+
* publisher.subscribe("player:move", ({ x, y }) => { [...] });
|
|
3680
|
+
* publisher.subscribe("player:death", () => { [...] });
|
|
3681
|
+
*
|
|
3682
|
+
* // All these subscribers are working fine...
|
|
3683
|
+
*
|
|
3684
|
+
* publisher.clear();
|
|
3685
|
+
*
|
|
3686
|
+
* // ... but now they're all gone!
|
|
3687
|
+
* ```
|
|
3688
|
+
*/
|
|
3689
|
+
clear() {
|
|
3690
|
+
this.publish("__internals__:clear"), this._subscribers.clear();
|
|
3691
|
+
}
|
|
3692
|
+
[Symbol.toStringTag] = "Publisher";
|
|
3693
|
+
}
|
|
3694
|
+
const q = () => {
|
|
3695
|
+
};
|
|
3696
|
+
class K extends O {
|
|
3697
|
+
/**
|
|
3698
|
+
* The currently selected implementation of the callback.
|
|
3699
|
+
*/
|
|
3700
|
+
_callback;
|
|
3701
|
+
/**
|
|
3702
|
+
* All the implementations that have been registered for the callback.
|
|
3703
|
+
*
|
|
3704
|
+
* The keys are the names of the implementations they were registered with.
|
|
3705
|
+
* The values are the implementations themselves.
|
|
3706
|
+
*/
|
|
3707
|
+
_callbacks;
|
|
3708
|
+
/**
|
|
3709
|
+
* A flag indicating whether the callback is enabled or not.
|
|
3710
|
+
*
|
|
3711
|
+
* This protected property is the only one that can be modified directly by the derived classes.
|
|
3712
|
+
* If you're looking for the public and readonly property, use
|
|
3713
|
+
* the {@link SwitchableCallback.isEnabled} getter instead.
|
|
3714
|
+
*/
|
|
3715
|
+
_isEnabled;
|
|
3716
|
+
/**
|
|
3717
|
+
* A flag indicating whether the callback is enabled or not.
|
|
3718
|
+
*
|
|
3719
|
+
* It indicates whether the callback is currently able to execute the currently selected implementation.
|
|
3720
|
+
* If it's disabled, the callback will be invoked without executing anything.
|
|
3780
3721
|
*/
|
|
3781
3722
|
get isEnabled() {
|
|
3782
3723
|
return this._isEnabled;
|
|
3783
3724
|
}
|
|
3725
|
+
/**
|
|
3726
|
+
* The key that is associated with the currently selected implementation.
|
|
3727
|
+
*
|
|
3728
|
+
* This protected property is the only one that can be modified directly by the derived classes.
|
|
3729
|
+
* If you're looking for the public and readonly property, use the {@link SwitchableCallback.key} getter instead.
|
|
3730
|
+
*/
|
|
3731
|
+
_key;
|
|
3784
3732
|
/**
|
|
3785
3733
|
* The key that is associated with the currently selected implementation.
|
|
3786
3734
|
*/
|
|
3787
3735
|
get key() {
|
|
3788
3736
|
return this._key;
|
|
3789
3737
|
}
|
|
3738
|
+
/**
|
|
3739
|
+
* The function that will be called by the extended class when the object is invoked as a function.
|
|
3740
|
+
*/
|
|
3741
|
+
_invoke;
|
|
3742
|
+
constructor(e, t = "default") {
|
|
3743
|
+
super(), this._callbacks = /* @__PURE__ */ new Map(), this._isEnabled = !0, e ? this._callbacks.set(t, e) : (t = "", e = (() => {
|
|
3744
|
+
throw new C(
|
|
3745
|
+
"The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
|
|
3746
|
+
);
|
|
3747
|
+
})), this._key = t, this._callback = e, this._invoke = (...n) => this._callback(...n);
|
|
3748
|
+
}
|
|
3790
3749
|
/**
|
|
3791
3750
|
* Enables the callback, allowing it to execute the currently selected implementation.
|
|
3792
3751
|
*
|
|
@@ -3840,7 +3799,7 @@ class dt extends (Se = Ue, ve = Symbol.toStringTag, Se) {
|
|
|
3840
3799
|
disable() {
|
|
3841
3800
|
if (!this._isEnabled)
|
|
3842
3801
|
throw new p("The `SwitchableCallback` is already disabled.");
|
|
3843
|
-
this._callback =
|
|
3802
|
+
this._callback = q, this._isEnabled = !1;
|
|
3844
3803
|
}
|
|
3845
3804
|
/**
|
|
3846
3805
|
* Registers a new implementation for the callback.
|
|
@@ -3917,9 +3876,13 @@ class dt extends (Se = Ue, ve = Symbol.toStringTag, Se) {
|
|
|
3917
3876
|
throw new _(`The key '${e}' doesn't yet have any associated callback.`);
|
|
3918
3877
|
this._key !== e && (this._key = e, this._isEnabled && (this._callback = this._callbacks.get(e)));
|
|
3919
3878
|
}
|
|
3879
|
+
[Symbol.toStringTag] = "SwitchableCallback";
|
|
3920
3880
|
}
|
|
3921
|
-
|
|
3922
|
-
|
|
3881
|
+
class Q extends Map {
|
|
3882
|
+
/**
|
|
3883
|
+
* The internal {@link Publisher} instance used to publish events.
|
|
3884
|
+
*/
|
|
3885
|
+
_publisher;
|
|
3923
3886
|
/**
|
|
3924
3887
|
* Initializes a new instance of the {@link MapView} class.
|
|
3925
3888
|
*
|
|
@@ -3935,15 +3898,9 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
3935
3898
|
* @param iterable An optional iterable of key-value pairs to initialize the {@link Map} with.
|
|
3936
3899
|
*/
|
|
3937
3900
|
constructor(e) {
|
|
3938
|
-
super()
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
*/
|
|
3942
|
-
a(this, "_publisher");
|
|
3943
|
-
a(this, ke, "MapView");
|
|
3944
|
-
if (this._publisher = new v(), e)
|
|
3945
|
-
for (const [t, s] of e)
|
|
3946
|
-
this.set(t, s);
|
|
3901
|
+
if (super(), this._publisher = new g(), e)
|
|
3902
|
+
for (const [t, n] of e)
|
|
3903
|
+
this.set(t, n);
|
|
3947
3904
|
}
|
|
3948
3905
|
/**
|
|
3949
3906
|
* Adds a new entry with a specified key and value to the {@link Map}.
|
|
@@ -3969,7 +3926,7 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
3969
3926
|
* @returns The current instance of the {@link MapView} class.
|
|
3970
3927
|
*/
|
|
3971
3928
|
set(e, t) {
|
|
3972
|
-
return super.set(e, t), this._publisher.publish("
|
|
3929
|
+
return super.set(e, t), this._publisher.publish("add", e, t), this;
|
|
3973
3930
|
}
|
|
3974
3931
|
/**
|
|
3975
3932
|
* Removes an entry with a specified key from the {@link Map}.
|
|
@@ -3993,7 +3950,7 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
3993
3950
|
*/
|
|
3994
3951
|
delete(e) {
|
|
3995
3952
|
const t = this.get(e);
|
|
3996
|
-
return t === void 0 ? !1 : (super.delete(e), this._publisher.publish("
|
|
3953
|
+
return t === void 0 ? !1 : (super.delete(e), this._publisher.publish("remove", e, t), !0);
|
|
3997
3954
|
}
|
|
3998
3955
|
/**
|
|
3999
3956
|
* Removes all entries from the {@link Map}.
|
|
@@ -4010,70 +3967,79 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
4010
3967
|
*/
|
|
4011
3968
|
clear() {
|
|
4012
3969
|
const e = this.size;
|
|
4013
|
-
super.clear(), e > 0 && this._publisher.publish("
|
|
3970
|
+
super.clear(), e > 0 && this._publisher.publish("clear");
|
|
4014
3971
|
}
|
|
4015
3972
|
/**
|
|
4016
|
-
* Subscribes to
|
|
3973
|
+
* Subscribes to the `add` event of the map with a callback that will be executed when an entry is added.
|
|
4017
3974
|
*
|
|
4018
3975
|
* ---
|
|
4019
3976
|
*
|
|
4020
3977
|
* @example
|
|
4021
3978
|
* ```ts
|
|
4022
|
-
*
|
|
4023
|
-
* const unsubscribe = map.subscribe("entry:add", (key: string, value: number) =>
|
|
4024
|
-
* {
|
|
4025
|
-
* if (key === "answer") { unsubscribe(); }
|
|
4026
|
-
* console.log(`Added ${key}: ${value}`);
|
|
4027
|
-
* });
|
|
3979
|
+
* map.onAdd((key, value) => console.log(`Added ${key}: ${value}`));
|
|
4028
3980
|
*
|
|
4029
3981
|
* map.set("key1", 2); // "Added key1: 2"
|
|
4030
3982
|
* map.set("answer", 42); // "Added answer: 42"
|
|
4031
|
-
* map.set("key2", 4);
|
|
4032
|
-
* map.set("key3", 8);
|
|
4033
3983
|
* ```
|
|
4034
3984
|
*
|
|
4035
3985
|
* ---
|
|
4036
3986
|
*
|
|
4037
|
-
* @
|
|
4038
|
-
*
|
|
4039
|
-
* @param event The name of the event to subscribe to.
|
|
4040
|
-
* @param subscriber The callback to execute when the event is published.
|
|
3987
|
+
* @param callback The callback that will be executed when an entry is added to the map.
|
|
4041
3988
|
*
|
|
4042
|
-
* @returns A function that can be used to unsubscribe
|
|
3989
|
+
* @returns A function that can be used to unsubscribe from the event.
|
|
4043
3990
|
*/
|
|
4044
|
-
|
|
4045
|
-
return this._publisher.subscribe(
|
|
3991
|
+
onAdd(e) {
|
|
3992
|
+
return this._publisher.subscribe("add", e);
|
|
4046
3993
|
}
|
|
4047
3994
|
/**
|
|
4048
|
-
*
|
|
3995
|
+
* Subscribes to the `remove` event of the map with a callback that will be executed when an entry is removed.
|
|
4049
3996
|
*
|
|
4050
3997
|
* ---
|
|
4051
3998
|
*
|
|
4052
3999
|
* @example
|
|
4053
4000
|
* ```ts
|
|
4054
|
-
*
|
|
4055
|
-
* const map = new MapView<string, number>();
|
|
4001
|
+
* map.onRemove((key, value) => console.log(`Removed ${key}: ${value}`));
|
|
4056
4002
|
*
|
|
4057
|
-
* map.
|
|
4058
|
-
* map.
|
|
4003
|
+
* map.delete("key1"); // "Removed key1: 2"
|
|
4004
|
+
* map.delete("answer"); // "Removed answer: 42"
|
|
4005
|
+
* ```
|
|
4059
4006
|
*
|
|
4060
|
-
*
|
|
4061
|
-
*
|
|
4007
|
+
* ---
|
|
4008
|
+
*
|
|
4009
|
+
* @param callback The callback that will be executed when an entry is removed from the map.
|
|
4010
|
+
*
|
|
4011
|
+
* @returns A function that can be used to unsubscribe from the event.
|
|
4012
|
+
*/
|
|
4013
|
+
onRemove(e) {
|
|
4014
|
+
return this._publisher.subscribe("remove", e);
|
|
4015
|
+
}
|
|
4016
|
+
/**
|
|
4017
|
+
* Subscribes to the `clear` event of the map with a callback that will be executed when the map is cleared.
|
|
4018
|
+
*
|
|
4019
|
+
* ---
|
|
4020
|
+
*
|
|
4021
|
+
* @example
|
|
4022
|
+
* ```ts
|
|
4023
|
+
* map.onClear(() => console.log("The map has all been cleared."));
|
|
4024
|
+
* map.clear(); // "The map has all been cleared."
|
|
4062
4025
|
* ```
|
|
4063
4026
|
*
|
|
4064
4027
|
* ---
|
|
4065
4028
|
*
|
|
4066
|
-
* @
|
|
4029
|
+
* @param callback The callback that will be executed when the map is cleared.
|
|
4067
4030
|
*
|
|
4068
|
-
* @
|
|
4069
|
-
* @param subscriber The callback to remove from the event.
|
|
4031
|
+
* @returns A function that can be used to unsubscribe from the event.
|
|
4070
4032
|
*/
|
|
4071
|
-
|
|
4072
|
-
this._publisher.
|
|
4033
|
+
onClear(e) {
|
|
4034
|
+
return this._publisher.subscribe("clear", e);
|
|
4073
4035
|
}
|
|
4036
|
+
[Symbol.toStringTag] = "MapView";
|
|
4074
4037
|
}
|
|
4075
|
-
|
|
4076
|
-
|
|
4038
|
+
class H extends Set {
|
|
4039
|
+
/**
|
|
4040
|
+
* The internal {@link Publisher} instance used to publish events.
|
|
4041
|
+
*/
|
|
4042
|
+
_publisher;
|
|
4077
4043
|
/**
|
|
4078
4044
|
* Initializes a new instance of the {@link SetView} class.
|
|
4079
4045
|
*
|
|
@@ -4089,13 +4055,7 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4089
4055
|
* @param iterable An optional iterable of values to initialize the {@link Set} with.
|
|
4090
4056
|
*/
|
|
4091
4057
|
constructor(e) {
|
|
4092
|
-
super()
|
|
4093
|
-
/**
|
|
4094
|
-
* The internal {@link Publisher} instance used to publish events.
|
|
4095
|
-
*/
|
|
4096
|
-
a(this, "_publisher");
|
|
4097
|
-
a(this, Ee, "SetView");
|
|
4098
|
-
if (this._publisher = new v(), e)
|
|
4058
|
+
if (super(), this._publisher = new g(), e)
|
|
4099
4059
|
for (const t of e)
|
|
4100
4060
|
this.add(t);
|
|
4101
4061
|
}
|
|
@@ -4122,7 +4082,7 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4122
4082
|
* @returns The current instance of the {@link SetView} class.
|
|
4123
4083
|
*/
|
|
4124
4084
|
add(e) {
|
|
4125
|
-
return super.add(e), this._publisher.publish("
|
|
4085
|
+
return super.add(e), this._publisher.publish("add", e), this;
|
|
4126
4086
|
}
|
|
4127
4087
|
/**
|
|
4128
4088
|
* Removes the specified value from the {@link Set}.
|
|
@@ -4146,7 +4106,7 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4146
4106
|
*/
|
|
4147
4107
|
delete(e) {
|
|
4148
4108
|
const t = super.delete(e);
|
|
4149
|
-
return t && this._publisher.publish("
|
|
4109
|
+
return t && this._publisher.publish("remove", e), t;
|
|
4150
4110
|
}
|
|
4151
4111
|
/**
|
|
4152
4112
|
* Removes all entries from the {@link Set}.
|
|
@@ -4163,71 +4123,90 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4163
4123
|
*/
|
|
4164
4124
|
clear() {
|
|
4165
4125
|
const e = this.size;
|
|
4166
|
-
super.clear(), e > 0 && this._publisher.publish("
|
|
4126
|
+
super.clear(), e > 0 && this._publisher.publish("clear");
|
|
4167
4127
|
}
|
|
4168
4128
|
/**
|
|
4169
|
-
* Subscribes to
|
|
4129
|
+
* Subscribes to the `add` event of the set with a callback that will be executed when a value is added.
|
|
4170
4130
|
*
|
|
4171
4131
|
* ---
|
|
4172
4132
|
*
|
|
4173
4133
|
* @example
|
|
4174
4134
|
* ```ts
|
|
4175
|
-
*
|
|
4176
|
-
* const unsubscribe = set.subscribe("entry:add", (value: number) =>
|
|
4177
|
-
* {
|
|
4178
|
-
* if (value === 42) { unsubscribe(); }
|
|
4179
|
-
* console.log(`Added ${value}`);
|
|
4180
|
-
* });
|
|
4135
|
+
* set.onAdd((value) => console.log(`Added ${value}`));
|
|
4181
4136
|
*
|
|
4182
4137
|
* set.add(2); // "Added 2"
|
|
4183
4138
|
* set.add(42); // "Added 42"
|
|
4184
|
-
* set.add(4);
|
|
4185
|
-
* set.add(8);
|
|
4186
4139
|
* ```
|
|
4187
4140
|
*
|
|
4188
4141
|
* ---
|
|
4189
4142
|
*
|
|
4190
|
-
* @
|
|
4191
|
-
*
|
|
4192
|
-
* @param event The name of the event to subscribe to.
|
|
4193
|
-
* @param subscriber The callback to execute when the event is published.
|
|
4143
|
+
* @param callback The callback that will be executed when a value is added to the set.
|
|
4194
4144
|
*
|
|
4195
|
-
* @returns A function that can be used to unsubscribe
|
|
4145
|
+
* @returns A function that can be used to unsubscribe from the event.
|
|
4196
4146
|
*/
|
|
4197
|
-
|
|
4198
|
-
return this._publisher.subscribe(
|
|
4147
|
+
onAdd(e) {
|
|
4148
|
+
return this._publisher.subscribe("add", e);
|
|
4199
4149
|
}
|
|
4200
4150
|
/**
|
|
4201
|
-
*
|
|
4151
|
+
* Subscribes to the `remove` event of the set with a callback that will be executed when a value is removed.
|
|
4202
4152
|
*
|
|
4203
4153
|
* ---
|
|
4204
4154
|
*
|
|
4205
4155
|
* @example
|
|
4206
4156
|
* ```ts
|
|
4207
|
-
*
|
|
4208
|
-
* const set = new SetView<number>();
|
|
4157
|
+
* set.onRemove((value) => console.log(`Removed ${value}`));
|
|
4209
4158
|
*
|
|
4210
|
-
* set.
|
|
4211
|
-
* set.
|
|
4159
|
+
* set.delete(2); // "Removed 2"
|
|
4160
|
+
* set.delete(42); // "Removed 42"
|
|
4161
|
+
* ```
|
|
4162
|
+
*
|
|
4163
|
+
* ---
|
|
4164
|
+
*
|
|
4165
|
+
* @param callback The callback that will be executed when a value is removed from the set.
|
|
4166
|
+
*
|
|
4167
|
+
* @returns A function that can be used to unsubscribe from the event.
|
|
4168
|
+
*/
|
|
4169
|
+
onRemove(e) {
|
|
4170
|
+
return this._publisher.subscribe("remove", e);
|
|
4171
|
+
}
|
|
4172
|
+
/**
|
|
4173
|
+
* Subscribes to the `clear` event of the set with a callback that will be executed when the set is cleared.
|
|
4212
4174
|
*
|
|
4213
|
-
*
|
|
4214
|
-
*
|
|
4175
|
+
* ---
|
|
4176
|
+
*
|
|
4177
|
+
* @example
|
|
4178
|
+
* ```ts
|
|
4179
|
+
* set.onClear(() => console.log("The set has all been cleared."));
|
|
4180
|
+
* set.clear(); // "The set has all been cleared."
|
|
4215
4181
|
* ```
|
|
4216
4182
|
*
|
|
4217
4183
|
* ---
|
|
4218
4184
|
*
|
|
4219
|
-
* @
|
|
4185
|
+
* @param callback The callback that will be executed when the set is cleared.
|
|
4220
4186
|
*
|
|
4221
|
-
* @
|
|
4222
|
-
* @param subscriber The callback to remove from the event.
|
|
4187
|
+
* @returns A function that can be used to unsubscribe from the event.
|
|
4223
4188
|
*/
|
|
4224
|
-
|
|
4225
|
-
this._publisher.
|
|
4189
|
+
onClear(e) {
|
|
4190
|
+
return this._publisher.subscribe("clear", e);
|
|
4226
4191
|
}
|
|
4192
|
+
[Symbol.toStringTag] = "SetView";
|
|
4227
4193
|
}
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4194
|
+
class X {
|
|
4195
|
+
/**
|
|
4196
|
+
* Whether to prefer the {@link localStorage} over the {@link sessionStorage} when calling an ambivalent method.
|
|
4197
|
+
*
|
|
4198
|
+
* If `true`, the persistent storage is preferred. If `false`, the volatile storage is preferred.
|
|
4199
|
+
* Default is `true`.
|
|
4200
|
+
*/
|
|
4201
|
+
_preferPersistence;
|
|
4202
|
+
/**
|
|
4203
|
+
* A reference to the volatile {@link sessionStorage} storage.
|
|
4204
|
+
*/
|
|
4205
|
+
_volatile;
|
|
4206
|
+
/**
|
|
4207
|
+
* A reference to the persistent {@link localStorage} storage.
|
|
4208
|
+
*/
|
|
4209
|
+
_persistent;
|
|
4231
4210
|
/**
|
|
4232
4211
|
* Initializes a new instance of the {@link JSONStorage} class.
|
|
4233
4212
|
* It cannot be instantiated outside of a browser environment or an {@link EnvironmentException} is thrown.
|
|
@@ -4245,57 +4224,41 @@ class pt {
|
|
|
4245
4224
|
* Whether to prefer the {@link localStorage} over the {@link sessionStorage} when calling an ambivalent method.
|
|
4246
4225
|
* If omitted, it defaults to `true` to prefer the persistent storage.
|
|
4247
4226
|
*/
|
|
4248
|
-
constructor(
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
*
|
|
4252
|
-
* If `true`, the persistent storage is preferred. If `false`, the volatile storage is preferred.
|
|
4253
|
-
* Default is `true`.
|
|
4254
|
-
*/
|
|
4255
|
-
a(this, "_preferPersistence");
|
|
4256
|
-
/**
|
|
4257
|
-
* A reference to the volatile {@link sessionStorage} storage.
|
|
4258
|
-
*/
|
|
4259
|
-
a(this, "_volatile");
|
|
4260
|
-
/**
|
|
4261
|
-
* A reference to the persistent {@link localStorage} storage.
|
|
4262
|
-
*/
|
|
4263
|
-
a(this, "_persistent");
|
|
4264
|
-
a(this, Re, "JSONStorage");
|
|
4265
|
-
if (!Ye)
|
|
4266
|
-
throw new Xe(
|
|
4227
|
+
constructor(e = !0) {
|
|
4228
|
+
if (!T)
|
|
4229
|
+
throw new P(
|
|
4267
4230
|
"The `JSONStorage` class can only be instantiated within a browser environment."
|
|
4268
4231
|
);
|
|
4269
|
-
this._preferPersistence =
|
|
4232
|
+
this._preferPersistence = e, this._volatile = window.sessionStorage, this._persistent = window.localStorage;
|
|
4270
4233
|
}
|
|
4271
|
-
_get(
|
|
4272
|
-
const s =
|
|
4234
|
+
_get(e, t, n) {
|
|
4235
|
+
const s = e.getItem(t);
|
|
4273
4236
|
if (s)
|
|
4274
4237
|
try {
|
|
4275
4238
|
return JSON.parse(s);
|
|
4276
4239
|
} catch {
|
|
4277
4240
|
console.warn(
|
|
4278
|
-
`The "${s}" value for "${
|
|
4279
|
-
),
|
|
4241
|
+
`The "${s}" value for "${t}" property cannot be parsed. Clearing the storage...`
|
|
4242
|
+
), e.removeItem(t);
|
|
4280
4243
|
}
|
|
4281
|
-
return
|
|
4244
|
+
return n;
|
|
4282
4245
|
}
|
|
4283
|
-
_set(
|
|
4284
|
-
const s = JSON.stringify(
|
|
4285
|
-
s ?
|
|
4246
|
+
_set(e, t, n) {
|
|
4247
|
+
const s = JSON.stringify(n);
|
|
4248
|
+
s ? e.setItem(t, s) : e.removeItem(t);
|
|
4286
4249
|
}
|
|
4287
|
-
get(
|
|
4288
|
-
const s =
|
|
4289
|
-
return this._get(s,
|
|
4250
|
+
get(e, t, n = this._preferPersistence) {
|
|
4251
|
+
const s = n ? this._persistent : this._volatile;
|
|
4252
|
+
return this._get(s, e, t);
|
|
4290
4253
|
}
|
|
4291
|
-
recall(
|
|
4292
|
-
return this._get(this._volatile,
|
|
4254
|
+
recall(e, t) {
|
|
4255
|
+
return this._get(this._volatile, e, t);
|
|
4293
4256
|
}
|
|
4294
|
-
retrieve(
|
|
4295
|
-
return this.recall(
|
|
4257
|
+
retrieve(e, t) {
|
|
4258
|
+
return this.recall(e) ?? this.read(e, t);
|
|
4296
4259
|
}
|
|
4297
|
-
read(
|
|
4298
|
-
return this._get(this._persistent,
|
|
4260
|
+
read(e, t) {
|
|
4261
|
+
return this._get(this._persistent, e, t);
|
|
4299
4262
|
}
|
|
4300
4263
|
/**
|
|
4301
4264
|
* Checks whether the value with the specified key exists within the default storage.
|
|
@@ -4319,8 +4282,8 @@ class pt {
|
|
|
4319
4282
|
*
|
|
4320
4283
|
* @returns `true` if the key exists, `false` otherwise.
|
|
4321
4284
|
*/
|
|
4322
|
-
has(
|
|
4323
|
-
return (
|
|
4285
|
+
has(e, t) {
|
|
4286
|
+
return (t ? this._persistent : this._volatile).getItem(e) !== null;
|
|
4324
4287
|
}
|
|
4325
4288
|
/**
|
|
4326
4289
|
* Checks whether the value with the specified key exists within the volatile {@link sessionStorage}.
|
|
@@ -4341,8 +4304,8 @@ class pt {
|
|
|
4341
4304
|
*
|
|
4342
4305
|
* @returns `true` if the key exists, `false` otherwise.
|
|
4343
4306
|
*/
|
|
4344
|
-
knows(
|
|
4345
|
-
return this._volatile.getItem(
|
|
4307
|
+
knows(e) {
|
|
4308
|
+
return this._volatile.getItem(e) !== null;
|
|
4346
4309
|
}
|
|
4347
4310
|
/**
|
|
4348
4311
|
* Checks whether the value with the specified key exists looking first in the
|
|
@@ -4364,8 +4327,8 @@ class pt {
|
|
|
4364
4327
|
*
|
|
4365
4328
|
* @returns `true` if the key exists, `false` otherwise.
|
|
4366
4329
|
*/
|
|
4367
|
-
find(
|
|
4368
|
-
return this.knows(
|
|
4330
|
+
find(e) {
|
|
4331
|
+
return this.knows(e) ?? this.exists(e);
|
|
4369
4332
|
}
|
|
4370
4333
|
/**
|
|
4371
4334
|
* Checks whether the value with the specified key exists within the persistent {@link localStorage}.
|
|
@@ -4386,8 +4349,8 @@ class pt {
|
|
|
4386
4349
|
*
|
|
4387
4350
|
* @returns `true` if the key exists, `false` otherwise.
|
|
4388
4351
|
*/
|
|
4389
|
-
exists(
|
|
4390
|
-
return this._persistent.getItem(
|
|
4352
|
+
exists(e) {
|
|
4353
|
+
return this._persistent.getItem(e) !== null;
|
|
4391
4354
|
}
|
|
4392
4355
|
/**
|
|
4393
4356
|
* Sets the value with the specified key in the default storage.
|
|
@@ -4412,9 +4375,9 @@ class pt {
|
|
|
4412
4375
|
* Whether to prefer the persistent {@link localStorage} over the volatile {@link sessionStorage}.
|
|
4413
4376
|
* If omitted, it defaults to the `preferPersistence` value set in the constructor.
|
|
4414
4377
|
*/
|
|
4415
|
-
set(
|
|
4416
|
-
const s =
|
|
4417
|
-
this._set(s,
|
|
4378
|
+
set(e, t, n = this._preferPersistence) {
|
|
4379
|
+
const s = n ? this._persistent : this._volatile;
|
|
4380
|
+
this._set(s, e, t);
|
|
4418
4381
|
}
|
|
4419
4382
|
/**
|
|
4420
4383
|
* Sets the value with the specified key in the volatile {@link sessionStorage}.
|
|
@@ -4436,8 +4399,8 @@ class pt {
|
|
|
4436
4399
|
* @param key The key of the value to set.
|
|
4437
4400
|
* @param newValue The new value to set. If it's `undefined` or omitted, the key is removed instead.
|
|
4438
4401
|
*/
|
|
4439
|
-
remember(
|
|
4440
|
-
this._set(this._volatile,
|
|
4402
|
+
remember(e, t) {
|
|
4403
|
+
this._set(this._volatile, e, t);
|
|
4441
4404
|
}
|
|
4442
4405
|
/**
|
|
4443
4406
|
* Sets the value with the specified key in the persistent {@link localStorage}.
|
|
@@ -4459,8 +4422,8 @@ class pt {
|
|
|
4459
4422
|
* @param key The key of the value to set.
|
|
4460
4423
|
* @param newValue The new value to set. If it's `undefined` or omitted, the key is removed instead.
|
|
4461
4424
|
*/
|
|
4462
|
-
write(
|
|
4463
|
-
this._set(this._persistent,
|
|
4425
|
+
write(e, t) {
|
|
4426
|
+
this._set(this._persistent, e, t);
|
|
4464
4427
|
}
|
|
4465
4428
|
/**
|
|
4466
4429
|
* Removes the value with the specified key from the default storage.
|
|
@@ -4479,8 +4442,8 @@ class pt {
|
|
|
4479
4442
|
* Whether to prefer the persistent {@link localStorage} over the volatile {@link sessionStorage}.
|
|
4480
4443
|
* If omitted, it defaults to the `preferPersistence` value set in the constructor.
|
|
4481
4444
|
*/
|
|
4482
|
-
delete(
|
|
4483
|
-
(
|
|
4445
|
+
delete(e, t) {
|
|
4446
|
+
(t ? this._persistent : this._volatile).removeItem(e);
|
|
4484
4447
|
}
|
|
4485
4448
|
/**
|
|
4486
4449
|
* Removes the value with the specified key from the volatile {@link sessionStorage}.
|
|
@@ -4496,8 +4459,8 @@ class pt {
|
|
|
4496
4459
|
*
|
|
4497
4460
|
* @param key The key of the value to remove.
|
|
4498
4461
|
*/
|
|
4499
|
-
forget(
|
|
4500
|
-
this._volatile.removeItem(
|
|
4462
|
+
forget(e) {
|
|
4463
|
+
this._volatile.removeItem(e);
|
|
4501
4464
|
}
|
|
4502
4465
|
/**
|
|
4503
4466
|
* Removes the value with the specified key from the persistent {@link localStorage}.
|
|
@@ -4513,8 +4476,8 @@ class pt {
|
|
|
4513
4476
|
*
|
|
4514
4477
|
* @param key The key of the value to remove.
|
|
4515
4478
|
*/
|
|
4516
|
-
erase(
|
|
4517
|
-
this._persistent.removeItem(
|
|
4479
|
+
erase(e) {
|
|
4480
|
+
this._persistent.removeItem(e);
|
|
4518
4481
|
}
|
|
4519
4482
|
/**
|
|
4520
4483
|
* Removes the value with the specified key from both the
|
|
@@ -4531,65 +4494,12 @@ class pt {
|
|
|
4531
4494
|
*
|
|
4532
4495
|
* @param key The key of the value to remove.
|
|
4533
4496
|
*/
|
|
4534
|
-
clear(
|
|
4535
|
-
this._volatile.removeItem(
|
|
4497
|
+
clear(e) {
|
|
4498
|
+
this._volatile.removeItem(e), this._persistent.removeItem(e);
|
|
4536
4499
|
}
|
|
4500
|
+
[Symbol.toStringTag] = "JSONStorage";
|
|
4537
4501
|
}
|
|
4538
|
-
|
|
4539
|
-
Fe = Symbol.toStringTag;
|
|
4540
|
-
const P = class P {
|
|
4541
|
-
/**
|
|
4542
|
-
* Initializes a new instance of the {@link SmartPromise} class.
|
|
4543
|
-
*
|
|
4544
|
-
* ---
|
|
4545
|
-
*
|
|
4546
|
-
* @example
|
|
4547
|
-
* ```ts
|
|
4548
|
-
* const promise = new SmartPromise<string>((resolve, reject) =>
|
|
4549
|
-
* {
|
|
4550
|
-
* setTimeout(() => resolve("Hello, World!"), 1_000);
|
|
4551
|
-
* });
|
|
4552
|
-
* ```
|
|
4553
|
-
*
|
|
4554
|
-
* ---
|
|
4555
|
-
*
|
|
4556
|
-
* @param executor
|
|
4557
|
-
* The function responsible for eventually resolving or rejecting the promise.
|
|
4558
|
-
* Similarly to the native {@link Promise} object, it's immediately executed after the promise is created.
|
|
4559
|
-
*/
|
|
4560
|
-
constructor(n) {
|
|
4561
|
-
/**
|
|
4562
|
-
* A flag indicating whether the promise is still pending or not.
|
|
4563
|
-
*
|
|
4564
|
-
* The protected property is the only one that can be modified directly by the derived classes.
|
|
4565
|
-
* If you're looking for the public and readonly property, use the {@link SmartPromise.isPending} getter instead.
|
|
4566
|
-
*/
|
|
4567
|
-
a(this, "_isPending");
|
|
4568
|
-
/**
|
|
4569
|
-
* A flag indicating whether the promise has been fulfilled or not.
|
|
4570
|
-
*
|
|
4571
|
-
* The protected property is the only one that can be modified directly by the derived classes.
|
|
4572
|
-
* If you're looking for the public and readonly property, use the {@link SmartPromise.isFulfilled} getter instead.
|
|
4573
|
-
*/
|
|
4574
|
-
a(this, "_isFulfilled");
|
|
4575
|
-
/**
|
|
4576
|
-
* A flag indicating whether the promise has been rejected or not.
|
|
4577
|
-
*
|
|
4578
|
-
* The protected property is the only one that can be modified directly by the derived classes.
|
|
4579
|
-
* If you're looking for the public and readonly property, use the {@link SmartPromise.isRejected} getter instead.
|
|
4580
|
-
*/
|
|
4581
|
-
a(this, "_isRejected");
|
|
4582
|
-
/**
|
|
4583
|
-
* The native {@link Promise} object wrapped by this instance.
|
|
4584
|
-
*/
|
|
4585
|
-
a(this, "_promise");
|
|
4586
|
-
a(this, Fe, "SmartPromise");
|
|
4587
|
-
this._isPending = !0, this._isFulfilled = !1, this._isRejected = !1;
|
|
4588
|
-
const e = (s) => (this._isPending = !1, this._isFulfilled = !0, s), t = (s) => {
|
|
4589
|
-
throw this._isPending = !1, this._isRejected = !0, s;
|
|
4590
|
-
};
|
|
4591
|
-
this._promise = new Promise(n).then(e, t);
|
|
4592
|
-
}
|
|
4502
|
+
class w {
|
|
4593
4503
|
/**
|
|
4594
4504
|
* Wraps a new {@link SmartPromise} object around an existing native {@link Promise} object.
|
|
4595
4505
|
*
|
|
@@ -4613,32 +4523,83 @@ const P = class P {
|
|
|
4613
4523
|
*
|
|
4614
4524
|
* @returns A new {@link SmartPromise} object that wraps the provided promise.
|
|
4615
4525
|
*/
|
|
4616
|
-
static FromPromise(
|
|
4617
|
-
return new
|
|
4526
|
+
static FromPromise(e) {
|
|
4527
|
+
return new w((t, n) => e.then(t, n));
|
|
4618
4528
|
}
|
|
4529
|
+
/**
|
|
4530
|
+
* A flag indicating whether the promise is still pending or not.
|
|
4531
|
+
*
|
|
4532
|
+
* The protected property is the only one that can be modified directly by the derived classes.
|
|
4533
|
+
* If you're looking for the public and readonly property, use the {@link SmartPromise.isPending} getter instead.
|
|
4534
|
+
*/
|
|
4535
|
+
_isPending;
|
|
4619
4536
|
/**
|
|
4620
4537
|
* A flag indicating whether the promise is still pending or not.
|
|
4621
4538
|
*/
|
|
4622
4539
|
get isPending() {
|
|
4623
4540
|
return this._isPending;
|
|
4624
4541
|
}
|
|
4542
|
+
/**
|
|
4543
|
+
* A flag indicating whether the promise has been fulfilled or not.
|
|
4544
|
+
*
|
|
4545
|
+
* The protected property is the only one that can be modified directly by the derived classes.
|
|
4546
|
+
* If you're looking for the public and readonly property, use the {@link SmartPromise.isFulfilled} getter instead.
|
|
4547
|
+
*/
|
|
4548
|
+
_isFulfilled;
|
|
4625
4549
|
/**
|
|
4626
4550
|
* A flag indicating whether the promise has been fulfilled or not.
|
|
4627
4551
|
*/
|
|
4628
4552
|
get isFulfilled() {
|
|
4629
4553
|
return this._isFulfilled;
|
|
4630
4554
|
}
|
|
4555
|
+
/**
|
|
4556
|
+
* A flag indicating whether the promise has been rejected or not.
|
|
4557
|
+
*
|
|
4558
|
+
* The protected property is the only one that can be modified directly by the derived classes.
|
|
4559
|
+
* If you're looking for the public and readonly property, use the {@link SmartPromise.isRejected} getter instead.
|
|
4560
|
+
*/
|
|
4561
|
+
_isRejected;
|
|
4631
4562
|
/**
|
|
4632
4563
|
* A flag indicating whether the promise has been rejected or not.
|
|
4633
4564
|
*/
|
|
4634
4565
|
get isRejected() {
|
|
4635
4566
|
return this._isRejected;
|
|
4636
4567
|
}
|
|
4637
|
-
|
|
4638
|
-
|
|
4568
|
+
/**
|
|
4569
|
+
* The native {@link Promise} object wrapped by this instance.
|
|
4570
|
+
*/
|
|
4571
|
+
_promise;
|
|
4572
|
+
/**
|
|
4573
|
+
* Initializes a new instance of the {@link SmartPromise} class.
|
|
4574
|
+
*
|
|
4575
|
+
* ---
|
|
4576
|
+
*
|
|
4577
|
+
* @example
|
|
4578
|
+
* ```ts
|
|
4579
|
+
* const promise = new SmartPromise<string>((resolve, reject) =>
|
|
4580
|
+
* {
|
|
4581
|
+
* setTimeout(() => resolve("Hello, World!"), 1_000);
|
|
4582
|
+
* });
|
|
4583
|
+
* ```
|
|
4584
|
+
*
|
|
4585
|
+
* ---
|
|
4586
|
+
*
|
|
4587
|
+
* @param executor
|
|
4588
|
+
* The function responsible for eventually resolving or rejecting the promise.
|
|
4589
|
+
* Similarly to the native {@link Promise} object, it's immediately executed after the promise is created.
|
|
4590
|
+
*/
|
|
4591
|
+
constructor(e) {
|
|
4592
|
+
this._isPending = !0, this._isFulfilled = !1, this._isRejected = !1;
|
|
4593
|
+
const t = (s) => (this._isPending = !1, this._isFulfilled = !0, s), n = (s) => {
|
|
4594
|
+
throw this._isPending = !1, this._isRejected = !0, s;
|
|
4595
|
+
};
|
|
4596
|
+
this._promise = new Promise(e).then(t, n);
|
|
4597
|
+
}
|
|
4598
|
+
then(e, t) {
|
|
4599
|
+
return this._promise.then(e, t);
|
|
4639
4600
|
}
|
|
4640
|
-
catch(
|
|
4641
|
-
return this._promise.catch(
|
|
4601
|
+
catch(e) {
|
|
4602
|
+
return this._promise.catch(e);
|
|
4642
4603
|
}
|
|
4643
4604
|
/**
|
|
4644
4605
|
* Attaches a callback that executes right after the promise is settled, regardless of the outcome.
|
|
@@ -4666,13 +4627,38 @@ const P = class P {
|
|
|
4666
4627
|
*
|
|
4667
4628
|
* @returns A new {@link Promise} that executes the callback once the promise is settled.
|
|
4668
4629
|
*/
|
|
4669
|
-
finally(
|
|
4670
|
-
return this._promise.finally(
|
|
4630
|
+
finally(e) {
|
|
4631
|
+
return this._promise.finally(e);
|
|
4632
|
+
}
|
|
4633
|
+
[Symbol.toStringTag] = "SmartPromise";
|
|
4634
|
+
}
|
|
4635
|
+
class M extends w {
|
|
4636
|
+
/**
|
|
4637
|
+
* The exposed function that allows to resolve the promise.
|
|
4638
|
+
*
|
|
4639
|
+
* This protected property is the only one that can be modified directly by the derived classes.
|
|
4640
|
+
* If you're looking for the public and readonly property, use the {@link DeferredPromise.resolve} getter instead.
|
|
4641
|
+
*/
|
|
4642
|
+
_resolve;
|
|
4643
|
+
/**
|
|
4644
|
+
* The exposed function that allows to reject the promise.
|
|
4645
|
+
*/
|
|
4646
|
+
get resolve() {
|
|
4647
|
+
return this._resolve;
|
|
4648
|
+
}
|
|
4649
|
+
/**
|
|
4650
|
+
* The exposed function that allows to reject the promise.
|
|
4651
|
+
*
|
|
4652
|
+
* This protected property is the only one that can be modified directly by the derived classes.
|
|
4653
|
+
* If you're looking for the public and readonly property, use the {@link DeferredPromise.reject} getter instead.
|
|
4654
|
+
*/
|
|
4655
|
+
_reject;
|
|
4656
|
+
/**
|
|
4657
|
+
* The exposed function that allows to reject the promise.
|
|
4658
|
+
*/
|
|
4659
|
+
get reject() {
|
|
4660
|
+
return this._reject;
|
|
4671
4661
|
}
|
|
4672
|
-
};
|
|
4673
|
-
let S = P;
|
|
4674
|
-
var Pe, je;
|
|
4675
|
-
class Ve extends (je = S, Pe = Symbol.toStringTag, je) {
|
|
4676
4662
|
/**
|
|
4677
4663
|
* Initializes a new instance of the {@link DeferredPromise} class.
|
|
4678
4664
|
*
|
|
@@ -4689,38 +4675,10 @@ class Ve extends (je = S, Pe = Symbol.toStringTag, je) {
|
|
|
4689
4675
|
* @param onRejected The callback to execute once the promise is rejected.
|
|
4690
4676
|
*/
|
|
4691
4677
|
constructor(e, t) {
|
|
4692
|
-
let
|
|
4693
|
-
super((
|
|
4694
|
-
|
|
4695
|
-
});
|
|
4696
|
-
/**
|
|
4697
|
-
* The exposed function that allows to resolve the promise.
|
|
4698
|
-
*
|
|
4699
|
-
* This protected property is the only one that can be modified directly by the derived classes.
|
|
4700
|
-
* If you're looking for the public and readonly property, use the {@link DeferredPromise.resolve} getter instead.
|
|
4701
|
-
*/
|
|
4702
|
-
a(this, "_resolve");
|
|
4703
|
-
/**
|
|
4704
|
-
* The exposed function that allows to reject the promise.
|
|
4705
|
-
*
|
|
4706
|
-
* This protected property is the only one that can be modified directly by the derived classes.
|
|
4707
|
-
* If you're looking for the public and readonly property, use the {@link DeferredPromise.reject} getter instead.
|
|
4708
|
-
*/
|
|
4709
|
-
a(this, "_reject");
|
|
4710
|
-
a(this, Pe, "DeferredPromise");
|
|
4711
|
-
this._promise = this._promise.then(e, t), this._resolve = s, this._reject = r;
|
|
4712
|
-
}
|
|
4713
|
-
/**
|
|
4714
|
-
* The exposed function that allows to reject the promise.
|
|
4715
|
-
*/
|
|
4716
|
-
get resolve() {
|
|
4717
|
-
return this._resolve;
|
|
4718
|
-
}
|
|
4719
|
-
/**
|
|
4720
|
-
* The exposed function that allows to reject the promise.
|
|
4721
|
-
*/
|
|
4722
|
-
get reject() {
|
|
4723
|
-
return this._reject;
|
|
4678
|
+
let n, s;
|
|
4679
|
+
super((r, o) => {
|
|
4680
|
+
n = r, s = o;
|
|
4681
|
+
}), this._promise = this._promise.then(e, t), this._resolve = n, this._reject = s;
|
|
4724
4682
|
}
|
|
4725
4683
|
/**
|
|
4726
4684
|
* Watches another promise and resolves or rejects this promise when the other one is settled.
|
|
@@ -4745,9 +4703,9 @@ class Ve extends (je = S, Pe = Symbol.toStringTag, je) {
|
|
|
4745
4703
|
watch(e) {
|
|
4746
4704
|
return e.then(this.resolve, this.reject), this;
|
|
4747
4705
|
}
|
|
4706
|
+
[Symbol.toStringTag] = "DeferredPromise";
|
|
4748
4707
|
}
|
|
4749
|
-
|
|
4750
|
-
class tt extends (Ie = S, Ce = Symbol.toStringTag, Ie) {
|
|
4708
|
+
class $ extends w {
|
|
4751
4709
|
/**
|
|
4752
4710
|
* Initializes a new instance of the {@link TimedPromise} class.
|
|
4753
4711
|
*
|
|
@@ -4771,31 +4729,22 @@ class tt extends (Ie = S, Ce = Symbol.toStringTag, Ie) {
|
|
|
4771
4729
|
* @param timeout The maximum time in milliseconds that the operation can take before timing out.
|
|
4772
4730
|
*/
|
|
4773
4731
|
constructor(e, t) {
|
|
4774
|
-
super((
|
|
4775
|
-
const
|
|
4776
|
-
clearTimeout(
|
|
4777
|
-
},
|
|
4778
|
-
clearTimeout(
|
|
4779
|
-
},
|
|
4780
|
-
e(
|
|
4732
|
+
super((n, s) => {
|
|
4733
|
+
const r = (v) => {
|
|
4734
|
+
clearTimeout(y), n(v);
|
|
4735
|
+
}, o = (v) => {
|
|
4736
|
+
clearTimeout(y), s(v);
|
|
4737
|
+
}, y = setTimeout(() => o(new j("The operation has timed out.")), t);
|
|
4738
|
+
e(r, o);
|
|
4781
4739
|
});
|
|
4782
|
-
a(this, Ce, "TimedPromise");
|
|
4783
4740
|
}
|
|
4741
|
+
[Symbol.toStringTag] = "TimedPromise";
|
|
4784
4742
|
}
|
|
4785
|
-
|
|
4786
|
-
class _t extends (Ne = S, Ae = Symbol.toStringTag, Ne) {
|
|
4743
|
+
class Z extends w {
|
|
4787
4744
|
/**
|
|
4788
|
-
*
|
|
4745
|
+
* The number of promises currently in the queue.
|
|
4789
4746
|
*/
|
|
4790
|
-
|
|
4791
|
-
super((e) => e());
|
|
4792
|
-
/**
|
|
4793
|
-
* The number of promises currently in the queue.
|
|
4794
|
-
*/
|
|
4795
|
-
a(this, "_count");
|
|
4796
|
-
a(this, Ae, "PromiseQueue");
|
|
4797
|
-
this._count = 0, this._isPending = !1, this._isFulfilled = !1, this._isRejected = !1;
|
|
4798
|
-
}
|
|
4747
|
+
_count;
|
|
4799
4748
|
/**
|
|
4800
4749
|
* A flag indicating whether the promise is still pending or not.
|
|
4801
4750
|
*/
|
|
@@ -4817,120 +4766,74 @@ class _t extends (Ne = S, Ae = Symbol.toStringTag, Ne) {
|
|
|
4817
4766
|
get isRejected() {
|
|
4818
4767
|
throw new f("`PromiseQueue` doesn't support rejection states.");
|
|
4819
4768
|
}
|
|
4769
|
+
/**
|
|
4770
|
+
* Initializes a new instance of the {@link PromiseQueue} class.
|
|
4771
|
+
*/
|
|
4772
|
+
constructor() {
|
|
4773
|
+
super((e) => e()), this._count = 0, this._isPending = !1, this._isFulfilled = !1, this._isRejected = !1;
|
|
4774
|
+
}
|
|
4820
4775
|
enqueue(e, t) {
|
|
4821
|
-
if (this._count += 1, e instanceof
|
|
4822
|
-
const
|
|
4823
|
-
e = () => (
|
|
4776
|
+
if (this._count += 1, e instanceof M) {
|
|
4777
|
+
const s = e;
|
|
4778
|
+
e = () => (s.resolve(), s);
|
|
4824
4779
|
}
|
|
4825
|
-
const
|
|
4826
|
-
this._promise = this._promise.then(e).then((
|
|
4827
|
-
this._count -= 1,
|
|
4828
|
-
}).catch((
|
|
4829
|
-
this._count -= 1, o
|
|
4780
|
+
const n = (s, r) => {
|
|
4781
|
+
this._promise = this._promise.then(e).then((o) => {
|
|
4782
|
+
this._count -= 1, s(o);
|
|
4783
|
+
}).catch((o) => {
|
|
4784
|
+
this._count -= 1, r(o);
|
|
4830
4785
|
});
|
|
4831
4786
|
};
|
|
4832
|
-
return t ? new
|
|
4787
|
+
return t ? new $(n, t) : new w(n);
|
|
4833
4788
|
}
|
|
4789
|
+
[Symbol.toStringTag] = "PromiseQueue";
|
|
4834
4790
|
}
|
|
4835
|
-
var
|
|
4836
|
-
function
|
|
4837
|
-
let
|
|
4838
|
-
return i = new Date(i),
|
|
4791
|
+
var k = /* @__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))(k || {}), z = /* @__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))(z || {});
|
|
4792
|
+
function W(i, e, t = 864e5) {
|
|
4793
|
+
let n;
|
|
4794
|
+
return i = new Date(i), e = new Date(e), i < e ? n = Math.floor : n = Math.ceil, n((e.getTime() - i.getTime()) / t);
|
|
4839
4795
|
}
|
|
4840
|
-
function
|
|
4841
|
-
if (i = new Date(i),
|
|
4796
|
+
function U(i, e, t = 864e5) {
|
|
4797
|
+
if (i = new Date(i), e = new Date(e), i >= e)
|
|
4842
4798
|
throw new b("The end date must be greater than the start date.");
|
|
4843
|
-
return new
|
|
4844
|
-
const
|
|
4799
|
+
return new l(function* () {
|
|
4800
|
+
const n = e.getTime();
|
|
4845
4801
|
let s = i.getTime();
|
|
4846
|
-
for (; s <
|
|
4847
|
-
yield new Date(s), s +=
|
|
4802
|
+
for (; s < n; )
|
|
4803
|
+
yield new Date(s), s += t;
|
|
4848
4804
|
});
|
|
4849
4805
|
}
|
|
4850
|
-
function
|
|
4851
|
-
if (
|
|
4806
|
+
function I(i, e = 864e5) {
|
|
4807
|
+
if (e <= 1)
|
|
4852
4808
|
throw new b(
|
|
4853
4809
|
"Rounding a timestamp by milliseconds or less makes no sense.Use the timestamp value directly instead."
|
|
4854
4810
|
);
|
|
4855
|
-
if (
|
|
4811
|
+
if (e > 864e5)
|
|
4856
4812
|
throw new b(
|
|
4857
4813
|
"Rounding by more than a day leads to unexpected results. Consider using other methods to round dates by weeks, months or years."
|
|
4858
4814
|
);
|
|
4859
|
-
return i = new Date(i), new Date(Math.floor(i.getTime() /
|
|
4815
|
+
return i = new Date(i), new Date(Math.floor(i.getTime() / e) * e);
|
|
4860
4816
|
}
|
|
4861
|
-
function
|
|
4817
|
+
function ee(i, e = 0) {
|
|
4862
4818
|
i = new Date(i);
|
|
4863
|
-
const
|
|
4864
|
-
return
|
|
4819
|
+
const t = 7 - e, n = (i.getUTCDay() + t) % 7, s = i.getTime() - 864e5 * n;
|
|
4820
|
+
return I(new Date(s));
|
|
4865
4821
|
}
|
|
4866
|
-
|
|
4867
|
-
Oe = Symbol.toStringTag;
|
|
4868
|
-
class Ge {
|
|
4822
|
+
class R {
|
|
4869
4823
|
/**
|
|
4870
|
-
*
|
|
4871
|
-
*
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
*
|
|
4876
|
-
*
|
|
4877
|
-
*
|
|
4878
|
-
*
|
|
4879
|
-
* ---
|
|
4824
|
+
* The handle of the interval or the animation frame, depending on the environment.
|
|
4825
|
+
* It's used to stop the game loop when the {@link GameLoop._stop} method is called.
|
|
4826
|
+
*/
|
|
4827
|
+
_handle;
|
|
4828
|
+
/**
|
|
4829
|
+
* The time when the game loop has started.
|
|
4830
|
+
* In addition to indicating the {@link https://en.wikipedia.org/wiki/Unix_time|Unix timestamp}
|
|
4831
|
+
* of the start of the game loop, it's also used to calculate the elapsed time.
|
|
4880
4832
|
*
|
|
4881
|
-
*
|
|
4882
|
-
* @
|
|
4883
|
-
* The interval in milliseconds that will be used if the current environment isn't a browser. Default is `40`.
|
|
4833
|
+
* This protected property is the only one that can be modified directly by the derived classes.
|
|
4834
|
+
* If you're looking for the public and readonly property, use the {@link GameLoop.startTime} getter instead.
|
|
4884
4835
|
*/
|
|
4885
|
-
|
|
4886
|
-
/**
|
|
4887
|
-
* The handle of the interval or the animation frame, depending on the environment.
|
|
4888
|
-
* It's used to stop the game loop when the {@link GameLoop._stop} method is called.
|
|
4889
|
-
*/
|
|
4890
|
-
a(this, "_handle");
|
|
4891
|
-
/**
|
|
4892
|
-
* The time when the game loop has started.
|
|
4893
|
-
* In addition to indicating the {@link https://en.wikipedia.org/wiki/Unix_time|Unix timestamp}
|
|
4894
|
-
* of the start of the game loop, it's also used to calculate the elapsed time.
|
|
4895
|
-
*
|
|
4896
|
-
* This protected property is the only one that can be modified directly by the derived classes.
|
|
4897
|
-
* If you're looking for the public and readonly property, use the {@link GameLoop.startTime} getter instead.
|
|
4898
|
-
*/
|
|
4899
|
-
a(this, "_startTime");
|
|
4900
|
-
/**
|
|
4901
|
-
* A flag indicating whether the game loop is currently running or not.
|
|
4902
|
-
*
|
|
4903
|
-
* This protected property is the only one that can be modified directly by the derived classes.
|
|
4904
|
-
* If you're looking for the public and readonly property, use the {@link GameLoop.isRunning} getter instead.
|
|
4905
|
-
*/
|
|
4906
|
-
a(this, "_isRunning");
|
|
4907
|
-
/**
|
|
4908
|
-
* The {@link Publisher} object that will be used to publish the events of the game loop.
|
|
4909
|
-
*/
|
|
4910
|
-
a(this, "_publisher");
|
|
4911
|
-
/**
|
|
4912
|
-
* The internal method actually responsible for starting the game loop.
|
|
4913
|
-
*
|
|
4914
|
-
* Depending on the current environment, it could use the
|
|
4915
|
-
* {@link requestAnimationFrame} or the {@link setInterval} function.
|
|
4916
|
-
*/
|
|
4917
|
-
a(this, "_start");
|
|
4918
|
-
/**
|
|
4919
|
-
* The internal method actually responsible for stopping the game loop.
|
|
4920
|
-
*
|
|
4921
|
-
* Depending on the current environment, it could use the
|
|
4922
|
-
* {@link cancelAnimationFrame} or the {@link clearInterval} function.
|
|
4923
|
-
*/
|
|
4924
|
-
a(this, "_stop");
|
|
4925
|
-
a(this, Oe, "GameLoop");
|
|
4926
|
-
this._startTime = 0, this._isRunning = !1, Ye ? (this._start = () => {
|
|
4927
|
-
n(this.elapsedTime), this._handle = window.requestAnimationFrame(this._start);
|
|
4928
|
-
}, this._stop = () => window.cancelAnimationFrame(this._handle)) : (console.warn(
|
|
4929
|
-
`Not a browser environment detected. Using setInterval@${e}ms instead of requestAnimationFrame...`
|
|
4930
|
-
), this._start = () => {
|
|
4931
|
-
this._handle = setInterval(() => n(this.elapsedTime), e);
|
|
4932
|
-
}, this._stop = () => clearInterval(this._handle)), this._publisher = new v();
|
|
4933
|
-
}
|
|
4836
|
+
_startTime;
|
|
4934
4837
|
/**
|
|
4935
4838
|
* The time when the game loop has started.
|
|
4936
4839
|
* In addition to indicating the {@link https://en.wikipedia.org/wiki/Unix_time|Unix timestamp}
|
|
@@ -4939,6 +4842,13 @@ class Ge {
|
|
|
4939
4842
|
get startTime() {
|
|
4940
4843
|
return this._startTime;
|
|
4941
4844
|
}
|
|
4845
|
+
/**
|
|
4846
|
+
* A flag indicating whether the game loop is currently running or not.
|
|
4847
|
+
*
|
|
4848
|
+
* This protected property is the only one that can be modified directly by the derived classes.
|
|
4849
|
+
* If you're looking for the public and readonly property, use the {@link GameLoop.isRunning} getter instead.
|
|
4850
|
+
*/
|
|
4851
|
+
_isRunning;
|
|
4942
4852
|
/**
|
|
4943
4853
|
* A flag indicating whether the game loop is currently running or not.
|
|
4944
4854
|
*/
|
|
@@ -4952,6 +4862,49 @@ class Ge {
|
|
|
4952
4862
|
get elapsedTime() {
|
|
4953
4863
|
return performance.now() - this._startTime;
|
|
4954
4864
|
}
|
|
4865
|
+
/**
|
|
4866
|
+
* The {@link Publisher} object that will be used to publish the events of the game loop.
|
|
4867
|
+
*/
|
|
4868
|
+
_publisher;
|
|
4869
|
+
/**
|
|
4870
|
+
* The internal method actually responsible for starting the game loop.
|
|
4871
|
+
*
|
|
4872
|
+
* Depending on the current environment, it could use the
|
|
4873
|
+
* {@link requestAnimationFrame} or the {@link setInterval} function.
|
|
4874
|
+
*/
|
|
4875
|
+
_start;
|
|
4876
|
+
/**
|
|
4877
|
+
* The internal method actually responsible for stopping the game loop.
|
|
4878
|
+
*
|
|
4879
|
+
* Depending on the current environment, it could use the
|
|
4880
|
+
* {@link cancelAnimationFrame} or the {@link clearInterval} function.
|
|
4881
|
+
*/
|
|
4882
|
+
_stop;
|
|
4883
|
+
/**
|
|
4884
|
+
* Initializes a new instance of the {@link GameLoop} class.
|
|
4885
|
+
*
|
|
4886
|
+
* ---
|
|
4887
|
+
*
|
|
4888
|
+
* @example
|
|
4889
|
+
* ```ts
|
|
4890
|
+
* const loop = new GameLoop((elapsedTime: number) => { [...] });
|
|
4891
|
+
* ```
|
|
4892
|
+
*
|
|
4893
|
+
* ---
|
|
4894
|
+
*
|
|
4895
|
+
* @param callback The function that will be executed at each iteration of the game loop.
|
|
4896
|
+
* @param msIfNotBrowser
|
|
4897
|
+
* The interval in milliseconds that will be used if the current environment isn't a browser. Default is `40`.
|
|
4898
|
+
*/
|
|
4899
|
+
constructor(e, t = 40) {
|
|
4900
|
+
this._startTime = 0, this._isRunning = !1, T ? (this._start = () => {
|
|
4901
|
+
e(this.elapsedTime), this._handle = window.requestAnimationFrame(this._start);
|
|
4902
|
+
}, this._stop = () => window.cancelAnimationFrame(this._handle)) : (console.warn(
|
|
4903
|
+
`Not a browser environment detected. Using setInterval@${t}ms instead of requestAnimationFrame...`
|
|
4904
|
+
), this._start = () => {
|
|
4905
|
+
this._handle = setInterval(() => e(this.elapsedTime), t);
|
|
4906
|
+
}, this._stop = () => clearInterval(this._handle)), this._publisher = new g();
|
|
4907
|
+
}
|
|
4955
4908
|
/**
|
|
4956
4909
|
* Starts the execution of the game loop.
|
|
4957
4910
|
*
|
|
@@ -4969,10 +4922,10 @@ class Ge {
|
|
|
4969
4922
|
*
|
|
4970
4923
|
* @param elapsedTime The elapsed time to set as default when the game loop starts. Default is `0`.
|
|
4971
4924
|
*/
|
|
4972
|
-
start(
|
|
4925
|
+
start(e = 0) {
|
|
4973
4926
|
if (this._isRunning)
|
|
4974
4927
|
throw new p("The game loop has already been started.");
|
|
4975
|
-
this._startTime = performance.now() -
|
|
4928
|
+
this._startTime = performance.now() - e, this._start(), this._isRunning = !0, this._publisher.publish("start");
|
|
4976
4929
|
}
|
|
4977
4930
|
/**
|
|
4978
4931
|
* Stops the execution of the game loop.
|
|
@@ -4991,7 +4944,7 @@ class Ge {
|
|
|
4991
4944
|
if (!this._isRunning)
|
|
4992
4945
|
throw new p("The game loop had already stopped or hadn't yet started.");
|
|
4993
4946
|
if (!this._handle)
|
|
4994
|
-
throw new
|
|
4947
|
+
throw new x();
|
|
4995
4948
|
this._stop(), this._handle = void 0, this._isRunning = !1, this._publisher.publish("stop");
|
|
4996
4949
|
}
|
|
4997
4950
|
/**
|
|
@@ -5010,8 +4963,8 @@ class Ge {
|
|
|
5010
4963
|
*
|
|
5011
4964
|
* @returns A function that can be used to unsubscribe from the event.
|
|
5012
4965
|
*/
|
|
5013
|
-
onStart(
|
|
5014
|
-
return this._publisher.subscribe("start",
|
|
4966
|
+
onStart(e) {
|
|
4967
|
+
return this._publisher.subscribe("start", e);
|
|
5015
4968
|
}
|
|
5016
4969
|
/**
|
|
5017
4970
|
* Subscribes to the `stop` event of the game loop.
|
|
@@ -5029,12 +4982,12 @@ class Ge {
|
|
|
5029
4982
|
*
|
|
5030
4983
|
* @returns A function that can be used to unsubscribe from the event.
|
|
5031
4984
|
*/
|
|
5032
|
-
onStop(
|
|
5033
|
-
return this._publisher.subscribe("stop",
|
|
4985
|
+
onStop(e) {
|
|
4986
|
+
return this._publisher.subscribe("stop", e);
|
|
5034
4987
|
}
|
|
4988
|
+
[Symbol.toStringTag] = "GameLoop";
|
|
5035
4989
|
}
|
|
5036
|
-
|
|
5037
|
-
class xt extends ($e = Ge, qe = Symbol.toStringTag, $e) {
|
|
4990
|
+
class te extends R {
|
|
5038
4991
|
/**
|
|
5039
4992
|
* Initializes a new instance of the {@link Clock} class.
|
|
5040
4993
|
*
|
|
@@ -5051,9 +5004,8 @@ class xt extends ($e = Ge, qe = Symbol.toStringTag, $e) {
|
|
|
5051
5004
|
* The interval in milliseconds at which the clock will tick if the environment is not a browser.
|
|
5052
5005
|
* `TimeUnit.Second` by default.
|
|
5053
5006
|
*/
|
|
5054
|
-
constructor(e =
|
|
5007
|
+
constructor(e = k.Second) {
|
|
5055
5008
|
super((t) => this._publisher.publish("tick", t), e);
|
|
5056
|
-
a(this, qe, "Clock");
|
|
5057
5009
|
}
|
|
5058
5010
|
/**
|
|
5059
5011
|
* Starts the execution of the clock.
|
|
@@ -5094,7 +5046,7 @@ class xt extends ($e = Ge, qe = Symbol.toStringTag, $e) {
|
|
|
5094
5046
|
if (!this._isRunning)
|
|
5095
5047
|
throw new p("The clock had already stopped or hadn't yet started.");
|
|
5096
5048
|
if (!this._handle)
|
|
5097
|
-
throw new
|
|
5049
|
+
throw new x();
|
|
5098
5050
|
this._stop(), this._handle = void 0, this._isRunning = !1, this._publisher.publish("stop");
|
|
5099
5051
|
}
|
|
5100
5052
|
/**
|
|
@@ -5126,14 +5078,38 @@ class xt extends ($e = Ge, qe = Symbol.toStringTag, $e) {
|
|
|
5126
5078
|
throw new b("The tick step must be a non-negative number.");
|
|
5127
5079
|
if (t === 0)
|
|
5128
5080
|
return this._publisher.subscribe("tick", e);
|
|
5129
|
-
let
|
|
5130
|
-
return this._publisher.subscribe("tick", (
|
|
5131
|
-
|
|
5081
|
+
let n = 0;
|
|
5082
|
+
return this._publisher.subscribe("tick", (s) => {
|
|
5083
|
+
s - n < t || (e(s), n = s);
|
|
5132
5084
|
});
|
|
5133
5085
|
}
|
|
5086
|
+
[Symbol.toStringTag] = "Clock";
|
|
5134
5087
|
}
|
|
5135
|
-
|
|
5136
|
-
|
|
5088
|
+
class ne extends R {
|
|
5089
|
+
/**
|
|
5090
|
+
* The total duration of the countdown in milliseconds.
|
|
5091
|
+
*
|
|
5092
|
+
* This protected property is the only one that can be modified directly by the derived classes.
|
|
5093
|
+
* If you're looking for the public and readonly property, use the {@link Countdown.duration} getter instead.
|
|
5094
|
+
*/
|
|
5095
|
+
_duration;
|
|
5096
|
+
/**
|
|
5097
|
+
* The total duration of the countdown in milliseconds.
|
|
5098
|
+
*/
|
|
5099
|
+
get duration() {
|
|
5100
|
+
return this._duration;
|
|
5101
|
+
}
|
|
5102
|
+
/**
|
|
5103
|
+
* The remaining time of the countdown in milliseconds.
|
|
5104
|
+
* It's calculated as the difference between the total duration and the elapsed time.
|
|
5105
|
+
*/
|
|
5106
|
+
get remainingTime() {
|
|
5107
|
+
return this._duration - this.elapsedTime;
|
|
5108
|
+
}
|
|
5109
|
+
/**
|
|
5110
|
+
* The {@link DeferredPromise} that will be resolved or rejected when the countdown expires or stops.
|
|
5111
|
+
*/
|
|
5112
|
+
_deferrer;
|
|
5137
5113
|
/**
|
|
5138
5114
|
* Initializes a new instance of the {@link Countdown} class.
|
|
5139
5115
|
*
|
|
@@ -5153,37 +5129,12 @@ class vt extends (De = Ge, ze = Symbol.toStringTag, De) {
|
|
|
5153
5129
|
* The interval in milliseconds at which the countdown will tick if the environment is not a browser.
|
|
5154
5130
|
* `TimeUnit.Second` by default.
|
|
5155
5131
|
*/
|
|
5156
|
-
constructor(e, t =
|
|
5157
|
-
|
|
5158
|
-
const
|
|
5159
|
-
|
|
5160
|
-
}
|
|
5161
|
-
|
|
5162
|
-
* The total duration of the countdown in milliseconds.
|
|
5163
|
-
*
|
|
5164
|
-
* This protected property is the only one that can be modified directly by the derived classes.
|
|
5165
|
-
* If you're looking for the public and readonly property, use the {@link Countdown.duration} getter instead.
|
|
5166
|
-
*/
|
|
5167
|
-
a(this, "_duration");
|
|
5168
|
-
/**
|
|
5169
|
-
* The {@link DeferredPromise} that will be resolved or rejected when the countdown expires or stops.
|
|
5170
|
-
*/
|
|
5171
|
-
a(this, "_deferrer");
|
|
5172
|
-
a(this, ze, "Countdown");
|
|
5173
|
-
this._duration = e;
|
|
5174
|
-
}
|
|
5175
|
-
/**
|
|
5176
|
-
* The total duration of the countdown in milliseconds.
|
|
5177
|
-
*/
|
|
5178
|
-
get duration() {
|
|
5179
|
-
return this._duration;
|
|
5180
|
-
}
|
|
5181
|
-
/**
|
|
5182
|
-
* The remaining time of the countdown in milliseconds.
|
|
5183
|
-
* It's calculated as the difference between the total duration and the elapsed time.
|
|
5184
|
-
*/
|
|
5185
|
-
get remainingTime() {
|
|
5186
|
-
return this._duration - this.elapsedTime;
|
|
5132
|
+
constructor(e, t = k.Second) {
|
|
5133
|
+
const n = () => {
|
|
5134
|
+
const s = this.remainingTime;
|
|
5135
|
+
s <= 0 ? (this._deferrerStop(), this._publisher.publish("tick", 0), this._publisher.publish("expire")) : this._publisher.publish("tick", s);
|
|
5136
|
+
};
|
|
5137
|
+
super(n, t), this._duration = e;
|
|
5187
5138
|
}
|
|
5188
5139
|
/**
|
|
5189
5140
|
* The internal method actually responsible for stopping the
|
|
@@ -5201,7 +5152,7 @@ class vt extends (De = Ge, ze = Symbol.toStringTag, De) {
|
|
|
5201
5152
|
if (!this._isRunning)
|
|
5202
5153
|
throw new p("The countdown hadn't yet started.");
|
|
5203
5154
|
if (!this._deferrer)
|
|
5204
|
-
throw new
|
|
5155
|
+
throw new x();
|
|
5205
5156
|
this._stop(), this._handle = void 0, this._isRunning = !1, e !== void 0 ? this._deferrer.reject(e) : this._deferrer.resolve(), this._deferrer = void 0;
|
|
5206
5157
|
}
|
|
5207
5158
|
/**
|
|
@@ -5229,8 +5180,8 @@ class vt extends (De = Ge, ze = Symbol.toStringTag, De) {
|
|
|
5229
5180
|
if (this._isRunning)
|
|
5230
5181
|
throw new p("The countdown had already stopped or hadn't yet started.");
|
|
5231
5182
|
if (this._deferrer)
|
|
5232
|
-
throw new
|
|
5233
|
-
return this._deferrer = new
|
|
5183
|
+
throw new x();
|
|
5184
|
+
return this._deferrer = new M(), super.start(this.duration - e), this._publisher.publish("start"), this._deferrer;
|
|
5234
5185
|
}
|
|
5235
5186
|
/**
|
|
5236
5187
|
* Stops the execution of the countdown.
|
|
@@ -5256,26 +5207,6 @@ class vt extends (De = Ge, ze = Symbol.toStringTag, De) {
|
|
|
5256
5207
|
stop(e) {
|
|
5257
5208
|
this._deferrerStop(e), this._publisher.publish("stop", e);
|
|
5258
5209
|
}
|
|
5259
|
-
/**
|
|
5260
|
-
* Subscribes to the `expire` event of the countdown.
|
|
5261
|
-
*
|
|
5262
|
-
* ---
|
|
5263
|
-
*
|
|
5264
|
-
* @example
|
|
5265
|
-
* ```ts
|
|
5266
|
-
* countdown.onExpire(() => { [...] }); // This callback will be executed once the countdown has expired.
|
|
5267
|
-
* countdown.start();
|
|
5268
|
-
* ```
|
|
5269
|
-
*
|
|
5270
|
-
* ---
|
|
5271
|
-
*
|
|
5272
|
-
* @param callback The callback that will be executed when the countdown expires.
|
|
5273
|
-
*
|
|
5274
|
-
* @returns A function that can be used to unsubscribe from the event.
|
|
5275
|
-
*/
|
|
5276
|
-
onExpire(e) {
|
|
5277
|
-
return this._publisher.subscribe("expire", e);
|
|
5278
|
-
}
|
|
5279
5210
|
/**
|
|
5280
5211
|
* Subscribes to the `tick` event of the countdown.
|
|
5281
5212
|
*
|
|
@@ -5305,18 +5236,34 @@ class vt extends (De = Ge, ze = Symbol.toStringTag, De) {
|
|
|
5305
5236
|
throw new b("The tick step must be a non-negative number.");
|
|
5306
5237
|
if (t === 0)
|
|
5307
5238
|
return this._publisher.subscribe("tick", e);
|
|
5308
|
-
let
|
|
5309
|
-
return this._publisher.subscribe("tick", (
|
|
5310
|
-
|
|
5239
|
+
let n = this.remainingTime;
|
|
5240
|
+
return this._publisher.subscribe("tick", (s) => {
|
|
5241
|
+
n - s < t || (e(s), n = s);
|
|
5311
5242
|
});
|
|
5312
5243
|
}
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5244
|
+
/**
|
|
5245
|
+
* Subscribes to the `expire` event of the countdown.
|
|
5246
|
+
*
|
|
5247
|
+
* ---
|
|
5248
|
+
*
|
|
5249
|
+
* @example
|
|
5250
|
+
* ```ts
|
|
5251
|
+
* countdown.onExpire(() => { [...] }); // This callback will be executed once the countdown has expired.
|
|
5252
|
+
* countdown.start();
|
|
5253
|
+
* ```
|
|
5254
|
+
*
|
|
5255
|
+
* ---
|
|
5256
|
+
*
|
|
5257
|
+
* @param callback The callback that will be executed when the countdown expires.
|
|
5258
|
+
*
|
|
5259
|
+
* @returns A function that can be used to unsubscribe from the event.
|
|
5260
|
+
*/
|
|
5261
|
+
onExpire(e) {
|
|
5262
|
+
return this._publisher.subscribe("expire", e);
|
|
5319
5263
|
}
|
|
5264
|
+
[Symbol.toStringTag] = "Countdown";
|
|
5265
|
+
}
|
|
5266
|
+
class se {
|
|
5320
5267
|
/**
|
|
5321
5268
|
* Generates a given number of values following a linear curve.
|
|
5322
5269
|
* The values are equally spaced and normalized between 0 and 1.
|
|
@@ -5337,11 +5284,11 @@ class St {
|
|
|
5337
5284
|
*
|
|
5338
5285
|
* @returns A {@link SmartIterator} object that generates the values following a linear curve.
|
|
5339
5286
|
*/
|
|
5340
|
-
static Linear(
|
|
5341
|
-
const
|
|
5342
|
-
return new
|
|
5343
|
-
for (let
|
|
5344
|
-
yield
|
|
5287
|
+
static Linear(e) {
|
|
5288
|
+
const t = e - 1;
|
|
5289
|
+
return new l(function* () {
|
|
5290
|
+
for (let n = 0; n < e; n += 1)
|
|
5291
|
+
yield n / t;
|
|
5345
5292
|
});
|
|
5346
5293
|
}
|
|
5347
5294
|
/**
|
|
@@ -5372,22 +5319,20 @@ class St {
|
|
|
5372
5319
|
*
|
|
5373
5320
|
* @returns A {@link SmartIterator} object that generates the values following an exponential curve.
|
|
5374
5321
|
*/
|
|
5375
|
-
static Exponential(
|
|
5376
|
-
if (
|
|
5322
|
+
static Exponential(e, t = 2) {
|
|
5323
|
+
if (t < 0)
|
|
5377
5324
|
throw new f("The base of the exponential curve cannot be negative.");
|
|
5378
|
-
const
|
|
5379
|
-
return new
|
|
5380
|
-
for (let s = 0; s <
|
|
5381
|
-
yield Math.pow(s /
|
|
5325
|
+
const n = e - 1;
|
|
5326
|
+
return new l(function* () {
|
|
5327
|
+
for (let s = 0; s < e; s += 1)
|
|
5328
|
+
yield Math.pow(s / n, t);
|
|
5382
5329
|
});
|
|
5383
5330
|
}
|
|
5384
|
-
}
|
|
5385
|
-
var Je;
|
|
5386
|
-
Je = Symbol.toStringTag;
|
|
5387
|
-
const j = class j {
|
|
5388
5331
|
constructor() {
|
|
5389
|
-
a(this, Je, "Random");
|
|
5390
5332
|
}
|
|
5333
|
+
[Symbol.toStringTag] = "Curve";
|
|
5334
|
+
}
|
|
5335
|
+
class F {
|
|
5391
5336
|
/**
|
|
5392
5337
|
* Generates a random boolean value.
|
|
5393
5338
|
*
|
|
@@ -5410,14 +5355,14 @@ const j = class j {
|
|
|
5410
5355
|
*
|
|
5411
5356
|
* @returns A random boolean value.
|
|
5412
5357
|
*/
|
|
5413
|
-
static Boolean(
|
|
5414
|
-
return Math.random() <
|
|
5358
|
+
static Boolean(e = 0.5) {
|
|
5359
|
+
return Math.random() < e;
|
|
5415
5360
|
}
|
|
5416
|
-
static Integer(
|
|
5417
|
-
return Math.floor(
|
|
5361
|
+
static Integer(e, t) {
|
|
5362
|
+
return Math.floor(t === void 0 ? Math.random() * e : Math.random() * (t - e) + e);
|
|
5418
5363
|
}
|
|
5419
|
-
static Decimal(
|
|
5420
|
-
return
|
|
5364
|
+
static Decimal(e, t) {
|
|
5365
|
+
return e === void 0 ? Math.random() : t === void 0 ? Math.random() * e : Math.random() * (t - e) + e;
|
|
5421
5366
|
}
|
|
5422
5367
|
/**
|
|
5423
5368
|
* Picks a random valid index from a given array of elements.
|
|
@@ -5433,10 +5378,10 @@ const j = class j {
|
|
|
5433
5378
|
*
|
|
5434
5379
|
* @returns A valid random index from the given array.
|
|
5435
5380
|
*/
|
|
5436
|
-
static Index(
|
|
5437
|
-
if (
|
|
5381
|
+
static Index(e) {
|
|
5382
|
+
if (e.length === 0)
|
|
5438
5383
|
throw new f("You must provide at least one element.");
|
|
5439
|
-
return this.Integer(
|
|
5384
|
+
return this.Integer(e.length);
|
|
5440
5385
|
}
|
|
5441
5386
|
/**
|
|
5442
5387
|
* Picks a random element from a given array of elements.
|
|
@@ -5452,187 +5397,189 @@ const j = class j {
|
|
|
5452
5397
|
*
|
|
5453
5398
|
* @returns A random element from the given array.
|
|
5454
5399
|
*/
|
|
5455
|
-
static Choice(
|
|
5456
|
-
return
|
|
5400
|
+
static Choice(e) {
|
|
5401
|
+
return e[F.Index(e)];
|
|
5457
5402
|
}
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5403
|
+
constructor() {
|
|
5404
|
+
}
|
|
5405
|
+
[Symbol.toStringTag] = "Random";
|
|
5406
|
+
}
|
|
5407
|
+
function re(i) {
|
|
5408
|
+
return new w((e) => setTimeout(e, i));
|
|
5462
5409
|
}
|
|
5463
|
-
function
|
|
5464
|
-
return new
|
|
5410
|
+
function ie() {
|
|
5411
|
+
return new w((i) => requestAnimationFrame(() => i()));
|
|
5465
5412
|
}
|
|
5466
|
-
function
|
|
5467
|
-
return new
|
|
5413
|
+
function oe() {
|
|
5414
|
+
return new w((i) => setTimeout(i));
|
|
5468
5415
|
}
|
|
5469
|
-
function
|
|
5470
|
-
return new
|
|
5416
|
+
function ae(i, e = "text/javascript") {
|
|
5417
|
+
return new w((t, n) => {
|
|
5471
5418
|
const s = document.createElement("script");
|
|
5472
|
-
s.async = !0, s.defer = !0, s.src = i, s.type =
|
|
5419
|
+
s.async = !0, s.defer = !0, s.src = i, s.type = e, s.onload = (r) => t(), s.onerror = (r) => n(r), document.body.appendChild(s);
|
|
5473
5420
|
});
|
|
5474
5421
|
}
|
|
5475
|
-
function
|
|
5476
|
-
return new
|
|
5477
|
-
for (const
|
|
5478
|
-
for (const
|
|
5479
|
-
yield
|
|
5422
|
+
function le(...i) {
|
|
5423
|
+
return new l(function* () {
|
|
5424
|
+
for (const e of i)
|
|
5425
|
+
for (const t of e)
|
|
5426
|
+
yield t;
|
|
5480
5427
|
});
|
|
5481
5428
|
}
|
|
5482
|
-
function
|
|
5429
|
+
function ue(i) {
|
|
5483
5430
|
if (i instanceof Array)
|
|
5484
5431
|
return i.length;
|
|
5485
|
-
let
|
|
5486
|
-
for (const
|
|
5487
|
-
|
|
5488
|
-
return
|
|
5432
|
+
let e = 0;
|
|
5433
|
+
for (const t of i)
|
|
5434
|
+
e += 1;
|
|
5435
|
+
return e;
|
|
5489
5436
|
}
|
|
5490
|
-
function
|
|
5491
|
-
return new
|
|
5492
|
-
let
|
|
5493
|
-
for (const
|
|
5494
|
-
yield [
|
|
5437
|
+
function ce(i) {
|
|
5438
|
+
return new l(function* () {
|
|
5439
|
+
let e = 0;
|
|
5440
|
+
for (const t of i)
|
|
5441
|
+
yield [e, t], e += 1;
|
|
5495
5442
|
});
|
|
5496
5443
|
}
|
|
5497
|
-
function
|
|
5498
|
-
if (
|
|
5444
|
+
function he(i, e, t = 1) {
|
|
5445
|
+
if (t <= 0)
|
|
5499
5446
|
throw new b(
|
|
5500
5447
|
"Step must be always a positive number, even when generating numbers in reverse order."
|
|
5501
5448
|
);
|
|
5502
|
-
return
|
|
5503
|
-
for (let
|
|
5504
|
-
yield
|
|
5505
|
-
}) : new
|
|
5506
|
-
for (let
|
|
5507
|
-
yield
|
|
5449
|
+
return e === void 0 && (e = i, i = 0), i > e ? new l(function* () {
|
|
5450
|
+
for (let n = i; n > e; n -= t)
|
|
5451
|
+
yield n;
|
|
5452
|
+
}) : new l(function* () {
|
|
5453
|
+
for (let n = i; n < e; n += t)
|
|
5454
|
+
yield n;
|
|
5508
5455
|
});
|
|
5509
5456
|
}
|
|
5510
|
-
function
|
|
5511
|
-
const
|
|
5512
|
-
for (let
|
|
5513
|
-
const
|
|
5514
|
-
[
|
|
5457
|
+
function fe(i) {
|
|
5458
|
+
const e = Array.from(i);
|
|
5459
|
+
for (let t = e.length - 1; t > 0; t -= 1) {
|
|
5460
|
+
const n = Math.floor(Math.random() * (t + 1));
|
|
5461
|
+
[e[t], e[n]] = [e[n], e[t]];
|
|
5515
5462
|
}
|
|
5516
|
-
return
|
|
5463
|
+
return e;
|
|
5517
5464
|
}
|
|
5518
|
-
function
|
|
5519
|
-
return new
|
|
5520
|
-
const
|
|
5521
|
-
for (const
|
|
5522
|
-
|
|
5465
|
+
function de(i) {
|
|
5466
|
+
return new l(function* () {
|
|
5467
|
+
const e = /* @__PURE__ */ new Set();
|
|
5468
|
+
for (const t of i)
|
|
5469
|
+
e.has(t) || (e.add(t), yield t);
|
|
5523
5470
|
});
|
|
5524
5471
|
}
|
|
5525
|
-
function
|
|
5526
|
-
const
|
|
5527
|
-
return new
|
|
5472
|
+
function A(i, e) {
|
|
5473
|
+
const t = i[Symbol.iterator](), n = e[Symbol.iterator]();
|
|
5474
|
+
return new l(function* () {
|
|
5528
5475
|
for (; ; ) {
|
|
5529
|
-
const s =
|
|
5476
|
+
const s = t.next(), r = n.next();
|
|
5530
5477
|
if (s.done || r.done)
|
|
5531
5478
|
break;
|
|
5532
5479
|
yield [s.value, r.value];
|
|
5533
5480
|
}
|
|
5534
5481
|
});
|
|
5535
5482
|
}
|
|
5536
|
-
function
|
|
5537
|
-
if (
|
|
5483
|
+
function we(i, e) {
|
|
5484
|
+
if (e === void 0) {
|
|
5538
5485
|
let r = 0, o = 0;
|
|
5539
|
-
for (const
|
|
5540
|
-
r +=
|
|
5486
|
+
for (const a of i)
|
|
5487
|
+
r += a, o += 1;
|
|
5541
5488
|
if (o === 0)
|
|
5542
5489
|
throw new f("You must provide at least one value.");
|
|
5543
5490
|
return r / o;
|
|
5544
5491
|
}
|
|
5545
|
-
let
|
|
5546
|
-
for (const [r, o] of
|
|
5492
|
+
let t = 0, n = 0, s = 0;
|
|
5493
|
+
for (const [r, o] of A(i, e)) {
|
|
5547
5494
|
if (o <= 0)
|
|
5548
5495
|
throw new f(`The weight for the value #${s} must be greater than zero.`);
|
|
5549
|
-
|
|
5496
|
+
t += r * o, n += o, s += 1;
|
|
5550
5497
|
}
|
|
5551
5498
|
if (s === 0)
|
|
5552
5499
|
throw new f("You must provide at least one value and weight.");
|
|
5553
|
-
if (
|
|
5500
|
+
if (n <= 0)
|
|
5554
5501
|
throw new f("The sum of weights must be greater than zero.");
|
|
5555
|
-
return
|
|
5502
|
+
return t / n;
|
|
5556
5503
|
}
|
|
5557
|
-
function
|
|
5558
|
-
let
|
|
5559
|
-
for (let
|
|
5560
|
-
const
|
|
5561
|
-
|
|
5504
|
+
function me(i) {
|
|
5505
|
+
let e = 0;
|
|
5506
|
+
for (let t = 0; t < i.length; t += 1) {
|
|
5507
|
+
const n = i.charCodeAt(t);
|
|
5508
|
+
e = (e << 5) - e + n, e |= 0;
|
|
5562
5509
|
}
|
|
5563
|
-
return
|
|
5510
|
+
return e;
|
|
5564
5511
|
}
|
|
5565
|
-
function
|
|
5566
|
-
let
|
|
5567
|
-
for (const
|
|
5568
|
-
|
|
5569
|
-
return
|
|
5512
|
+
function pe(i) {
|
|
5513
|
+
let e = 0;
|
|
5514
|
+
for (const t of i)
|
|
5515
|
+
e += t;
|
|
5516
|
+
return e;
|
|
5570
5517
|
}
|
|
5571
|
-
function
|
|
5518
|
+
function _e(i) {
|
|
5572
5519
|
return `${i.charAt(0).toUpperCase()}${i.slice(1)}`;
|
|
5573
5520
|
}
|
|
5574
|
-
const
|
|
5521
|
+
const ye = "2.2.0";
|
|
5575
5522
|
export {
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5523
|
+
m as AggregatedAsyncIterator,
|
|
5524
|
+
h as AggregatedIterator,
|
|
5525
|
+
O as CallableObject,
|
|
5526
|
+
te as Clock,
|
|
5527
|
+
ne as Countdown,
|
|
5528
|
+
se as Curve,
|
|
5529
|
+
M as DeferredPromise,
|
|
5530
|
+
P as EnvironmentException,
|
|
5584
5531
|
c as Exception,
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5532
|
+
x as FatalErrorException,
|
|
5533
|
+
E as FileException,
|
|
5534
|
+
J as FileExistsException,
|
|
5535
|
+
Y as FileNotFoundException,
|
|
5536
|
+
R as GameLoop,
|
|
5537
|
+
X as JSONStorage,
|
|
5591
5538
|
_ as KeyException,
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5539
|
+
Q as MapView,
|
|
5540
|
+
L as NetworkException,
|
|
5541
|
+
C as NotImplementedException,
|
|
5542
|
+
V as PermissionException,
|
|
5543
|
+
Z as PromiseQueue,
|
|
5544
|
+
g as Publisher,
|
|
5545
|
+
F as Random,
|
|
5599
5546
|
b as RangeException,
|
|
5600
|
-
|
|
5601
|
-
|
|
5547
|
+
u as ReducedIterator,
|
|
5548
|
+
S as ReferenceException,
|
|
5602
5549
|
p as RuntimeException,
|
|
5603
|
-
|
|
5550
|
+
H as SetView,
|
|
5604
5551
|
d as SmartAsyncIterator,
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5552
|
+
l as SmartIterator,
|
|
5553
|
+
w as SmartPromise,
|
|
5554
|
+
K as SwitchableCallback,
|
|
5555
|
+
k as TimeUnit,
|
|
5556
|
+
$ as TimedPromise,
|
|
5557
|
+
j as TimeoutException,
|
|
5558
|
+
G as TypeException,
|
|
5559
|
+
ye as VERSION,
|
|
5613
5560
|
f as ValueException,
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5561
|
+
z as WeekDay,
|
|
5562
|
+
we as average,
|
|
5563
|
+
_e as capitalize,
|
|
5564
|
+
le as chain,
|
|
5565
|
+
ue as count,
|
|
5566
|
+
W as dateDifference,
|
|
5567
|
+
U as dateRange,
|
|
5568
|
+
I as dateRound,
|
|
5569
|
+
re as delay,
|
|
5570
|
+
ce as enumerate,
|
|
5571
|
+
ee as getWeek,
|
|
5572
|
+
me as hash,
|
|
5573
|
+
T as isBrowser,
|
|
5574
|
+
D as isNode,
|
|
5575
|
+
B as isWorker,
|
|
5576
|
+
ae as loadScript,
|
|
5577
|
+
ie as nextAnimationFrame,
|
|
5578
|
+
he as range,
|
|
5579
|
+
fe as shuffle,
|
|
5580
|
+
pe as sum,
|
|
5581
|
+
de as unique,
|
|
5582
|
+
oe as yieldToEventLoop,
|
|
5583
|
+
A as zip
|
|
5637
5584
|
};
|
|
5638
5585
|
//# sourceMappingURL=core.esm.js.map
|