@byloth/core 2.2.2 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.esm.js +550 -232
- package/dist/core.esm.js.map +1 -1
- package/dist/core.global.js +1 -1
- package/dist/core.global.js.map +1 -1
- package/dist/core.umd.cjs +1 -1
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +3 -1
- package/src/models/aggregators/index.ts +3 -5
- package/src/models/callbacks/callback-chain.ts +8 -1
- package/src/models/callbacks/index.ts +4 -6
- package/src/models/callbacks/publisher.ts +8 -2
- package/src/models/collections/array-view.ts +348 -0
- package/src/models/collections/index.ts +3 -4
- package/src/models/collections/map-view.ts +5 -3
- package/src/models/collections/set-view.ts +6 -4
- package/src/models/exceptions/index.ts +51 -10
- package/src/models/index.ts +2 -1
- package/src/models/iterators/index.ts +2 -4
- package/src/models/json/index.ts +1 -3
- package/src/models/promises/index.ts +4 -6
- package/src/models/timers/index.ts +3 -5
- package/src/utils/index.ts +2 -4
- package/src/utils/random.ts +246 -0
package/dist/core.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
class
|
|
1
|
+
const E = typeof window < "u" && typeof window.document < "u", B = typeof process < "u" && !!process.versions?.node, V = typeof self == "object" && self.constructor?.name === "DedicatedWorkerGlobalScope";
|
|
2
|
+
class f extends Error {
|
|
3
3
|
/**
|
|
4
4
|
* A static method to convert a generic caught error, ensuring it's an instance of the {@link Exception} class.
|
|
5
5
|
*
|
|
@@ -23,13 +23,13 @@ class c extends Error {
|
|
|
23
23
|
* @returns An instance of the {@link Exception} class.
|
|
24
24
|
*/
|
|
25
25
|
static FromUnknown(e) {
|
|
26
|
-
if (e instanceof
|
|
26
|
+
if (e instanceof f)
|
|
27
27
|
return e;
|
|
28
28
|
if (e instanceof Error) {
|
|
29
|
-
const t = new
|
|
29
|
+
const t = new f(e.message);
|
|
30
30
|
return t.stack = e.stack, t.cause = e.cause, t.name = e.name, t;
|
|
31
31
|
}
|
|
32
|
-
return new
|
|
32
|
+
return new f(`${e}`);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Initializes a new instance of the {@link Exception} class.
|
|
@@ -52,7 +52,7 @@ class c extends Error {
|
|
|
52
52
|
}
|
|
53
53
|
[Symbol.toStringTag] = "Exception";
|
|
54
54
|
}
|
|
55
|
-
class
|
|
55
|
+
class v extends f {
|
|
56
56
|
/**
|
|
57
57
|
* Initializes a new instance of the {@link FatalErrorException} class.
|
|
58
58
|
*
|
|
@@ -74,7 +74,7 @@ class x extends c {
|
|
|
74
74
|
}
|
|
75
75
|
[Symbol.toStringTag] = "FatalErrorException";
|
|
76
76
|
}
|
|
77
|
-
class
|
|
77
|
+
class j extends v {
|
|
78
78
|
/**
|
|
79
79
|
* Initializes a new instance of the {@link NotImplementedException} class.
|
|
80
80
|
*
|
|
@@ -96,7 +96,7 @@ class P extends x {
|
|
|
96
96
|
}
|
|
97
97
|
[Symbol.toStringTag] = "NotImplementedException";
|
|
98
98
|
}
|
|
99
|
-
class
|
|
99
|
+
class M extends f {
|
|
100
100
|
/**
|
|
101
101
|
* Initializes a new instance of the {@link FileException} class.
|
|
102
102
|
*
|
|
@@ -118,7 +118,7 @@ class E extends c {
|
|
|
118
118
|
}
|
|
119
119
|
[Symbol.toStringTag] = "FileException";
|
|
120
120
|
}
|
|
121
|
-
class J extends
|
|
121
|
+
class J extends M {
|
|
122
122
|
/**
|
|
123
123
|
* Initializes a new instance of the {@link FileExistsException} class.
|
|
124
124
|
*
|
|
@@ -140,7 +140,7 @@ class J extends E {
|
|
|
140
140
|
}
|
|
141
141
|
[Symbol.toStringTag] = "FileExistsException";
|
|
142
142
|
}
|
|
143
|
-
class
|
|
143
|
+
class L extends M {
|
|
144
144
|
/**
|
|
145
145
|
* Initializes a new instance of the {@link FileNotFoundException} class.
|
|
146
146
|
*
|
|
@@ -162,7 +162,7 @@ class Y extends E {
|
|
|
162
162
|
}
|
|
163
163
|
[Symbol.toStringTag] = "FileNotFoundException";
|
|
164
164
|
}
|
|
165
|
-
class
|
|
165
|
+
class y extends f {
|
|
166
166
|
/**
|
|
167
167
|
* Initializes a new instance of the {@link KeyException} class.
|
|
168
168
|
*
|
|
@@ -184,7 +184,7 @@ class p extends c {
|
|
|
184
184
|
}
|
|
185
185
|
[Symbol.toStringTag] = "KeyException";
|
|
186
186
|
}
|
|
187
|
-
class
|
|
187
|
+
class A extends f {
|
|
188
188
|
/**
|
|
189
189
|
* Initializes a new instance of the {@link NetworkException} class.
|
|
190
190
|
*
|
|
@@ -206,7 +206,30 @@ class L extends c {
|
|
|
206
206
|
}
|
|
207
207
|
[Symbol.toStringTag] = "NetworkException";
|
|
208
208
|
}
|
|
209
|
-
class
|
|
209
|
+
class G extends A {
|
|
210
|
+
response;
|
|
211
|
+
/**
|
|
212
|
+
* Initializes a new instance of the {@link ResponseException} class.
|
|
213
|
+
*
|
|
214
|
+
* ---
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* throw new ResponseException(response);
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* ---
|
|
222
|
+
*
|
|
223
|
+
* @param response The response that caused the error.
|
|
224
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
225
|
+
* @param name The name of the exception. Default is `"ResponseException"`.
|
|
226
|
+
*/
|
|
227
|
+
constructor(e, t, n = "ResponseException") {
|
|
228
|
+
super(`The request failed with the status code ${e.status} (${e.statusText}).`, t, n), this.response = e;
|
|
229
|
+
}
|
|
230
|
+
[Symbol.toStringTag] = "ResponseException";
|
|
231
|
+
}
|
|
232
|
+
class K extends f {
|
|
210
233
|
/**
|
|
211
234
|
* Initializes a new instance of the {@link PermissionException} class.
|
|
212
235
|
*
|
|
@@ -228,7 +251,7 @@ class V extends c {
|
|
|
228
251
|
}
|
|
229
252
|
[Symbol.toStringTag] = "PermissionException";
|
|
230
253
|
}
|
|
231
|
-
class
|
|
254
|
+
class S extends f {
|
|
232
255
|
/**
|
|
233
256
|
* Initializes a new instance of the {@link ReferenceException} class.
|
|
234
257
|
*
|
|
@@ -250,7 +273,7 @@ class k extends c {
|
|
|
250
273
|
}
|
|
251
274
|
[Symbol.toStringTag] = "ReferenceException";
|
|
252
275
|
}
|
|
253
|
-
class
|
|
276
|
+
class b extends f {
|
|
254
277
|
/**
|
|
255
278
|
* Initializes a new instance of the {@link RuntimeException} class.
|
|
256
279
|
*
|
|
@@ -272,7 +295,7 @@ class _ extends c {
|
|
|
272
295
|
}
|
|
273
296
|
[Symbol.toStringTag] = "RuntimeException";
|
|
274
297
|
}
|
|
275
|
-
class
|
|
298
|
+
class z extends b {
|
|
276
299
|
/**
|
|
277
300
|
* Initializes a new instance of the {@link EnvironmentException} class.
|
|
278
301
|
*
|
|
@@ -294,7 +317,7 @@ class j extends _ {
|
|
|
294
317
|
}
|
|
295
318
|
[Symbol.toStringTag] = "EnvironmentException";
|
|
296
319
|
}
|
|
297
|
-
class
|
|
320
|
+
class N extends f {
|
|
298
321
|
/**
|
|
299
322
|
* Initializes a new instance of the {@link TimeoutException} class.
|
|
300
323
|
*
|
|
@@ -316,7 +339,7 @@ class O extends c {
|
|
|
316
339
|
}
|
|
317
340
|
[Symbol.toStringTag] = "TimeoutException";
|
|
318
341
|
}
|
|
319
|
-
class
|
|
342
|
+
class Q extends f {
|
|
320
343
|
/**
|
|
321
344
|
* Initializes a new instance of the {@link TypeException} class.
|
|
322
345
|
*
|
|
@@ -338,7 +361,7 @@ class G extends c {
|
|
|
338
361
|
}
|
|
339
362
|
[Symbol.toStringTag] = "TypeException";
|
|
340
363
|
}
|
|
341
|
-
class
|
|
364
|
+
class c extends f {
|
|
342
365
|
/**
|
|
343
366
|
* Initializes a new instance of the {@link ValueException} class.
|
|
344
367
|
*
|
|
@@ -360,7 +383,7 @@ class f extends c {
|
|
|
360
383
|
}
|
|
361
384
|
[Symbol.toStringTag] = "ValueException";
|
|
362
385
|
}
|
|
363
|
-
class
|
|
386
|
+
class x extends c {
|
|
364
387
|
/**
|
|
365
388
|
* Initializes a new instance of the {@link RangeException} class.
|
|
366
389
|
*
|
|
@@ -530,7 +553,7 @@ class l {
|
|
|
530
553
|
if (s === void 0) {
|
|
531
554
|
const r = this._iterator.next();
|
|
532
555
|
if (r.done)
|
|
533
|
-
throw new
|
|
556
|
+
throw new c("Cannot reduce an empty iterator without an initial value.");
|
|
534
557
|
s = r.value, n += 1;
|
|
535
558
|
}
|
|
536
559
|
for (; ; ) {
|
|
@@ -960,7 +983,7 @@ class l {
|
|
|
960
983
|
* @returns A new instance of the {@link AggregatedIterator} class containing the grouped elements.
|
|
961
984
|
*/
|
|
962
985
|
groupBy(e) {
|
|
963
|
-
return new
|
|
986
|
+
return new d(this.map((t, n) => [e(t, n), t]));
|
|
964
987
|
}
|
|
965
988
|
/**
|
|
966
989
|
* Materializes the iterator into an array.
|
|
@@ -993,7 +1016,7 @@ class l {
|
|
|
993
1016
|
return this;
|
|
994
1017
|
}
|
|
995
1018
|
}
|
|
996
|
-
class
|
|
1019
|
+
class h {
|
|
997
1020
|
/**
|
|
998
1021
|
* The internal {@link SmartIterator} object that holds the reduced elements.
|
|
999
1022
|
*/
|
|
@@ -1077,7 +1100,7 @@ class u {
|
|
|
1077
1100
|
}
|
|
1078
1101
|
filter(e) {
|
|
1079
1102
|
const t = this._elements.enumerate();
|
|
1080
|
-
return new
|
|
1103
|
+
return new h(function* () {
|
|
1081
1104
|
for (const [n, [s, r]] of t)
|
|
1082
1105
|
e(s, r, n) && (yield [s, r]);
|
|
1083
1106
|
});
|
|
@@ -1117,7 +1140,7 @@ class u {
|
|
|
1117
1140
|
*/
|
|
1118
1141
|
map(e) {
|
|
1119
1142
|
const t = this._elements.enumerate();
|
|
1120
|
-
return new
|
|
1143
|
+
return new h(function* () {
|
|
1121
1144
|
for (const [n, [s, r]] of t)
|
|
1122
1145
|
yield [s, e(s, r, n)];
|
|
1123
1146
|
});
|
|
@@ -1127,7 +1150,7 @@ class u {
|
|
|
1127
1150
|
if (s === void 0) {
|
|
1128
1151
|
const r = this._elements.next();
|
|
1129
1152
|
if (r.done)
|
|
1130
|
-
throw new
|
|
1153
|
+
throw new c("Cannot reduce an empty iterator without an initial value.");
|
|
1131
1154
|
s = r.value[1], n += 1;
|
|
1132
1155
|
}
|
|
1133
1156
|
for (const [r, o] of this._elements)
|
|
@@ -1169,7 +1192,7 @@ class u {
|
|
|
1169
1192
|
*/
|
|
1170
1193
|
flatMap(e) {
|
|
1171
1194
|
const t = this._elements.enumerate();
|
|
1172
|
-
return new
|
|
1195
|
+
return new d(function* () {
|
|
1173
1196
|
for (const [n, [s, r]] of t) {
|
|
1174
1197
|
const o = e(s, r, n);
|
|
1175
1198
|
if (o instanceof Array)
|
|
@@ -1215,7 +1238,7 @@ class u {
|
|
|
1215
1238
|
*/
|
|
1216
1239
|
drop(e) {
|
|
1217
1240
|
const t = this._elements.enumerate();
|
|
1218
|
-
return new
|
|
1241
|
+
return new h(function* () {
|
|
1219
1242
|
for (const [n, [s, r]] of t)
|
|
1220
1243
|
n >= e && (yield [s, r]);
|
|
1221
1244
|
});
|
|
@@ -1257,7 +1280,7 @@ class u {
|
|
|
1257
1280
|
*/
|
|
1258
1281
|
take(e) {
|
|
1259
1282
|
const t = this._elements.enumerate();
|
|
1260
|
-
return new
|
|
1283
|
+
return new h(function* () {
|
|
1261
1284
|
for (const [n, [s, r]] of t) {
|
|
1262
1285
|
if (n >= e)
|
|
1263
1286
|
break;
|
|
@@ -1327,7 +1350,7 @@ class u {
|
|
|
1327
1350
|
*/
|
|
1328
1351
|
unique() {
|
|
1329
1352
|
const e = this._elements;
|
|
1330
|
-
return new
|
|
1353
|
+
return new h(function* () {
|
|
1331
1354
|
const t = /* @__PURE__ */ new Set();
|
|
1332
1355
|
for (const [n, s] of e)
|
|
1333
1356
|
t.has(s) || (t.add(s), yield [n, s]);
|
|
@@ -1423,7 +1446,7 @@ class u {
|
|
|
1423
1446
|
*/
|
|
1424
1447
|
reorganizeBy(e) {
|
|
1425
1448
|
const t = this._elements.enumerate();
|
|
1426
|
-
return new
|
|
1449
|
+
return new d(function* () {
|
|
1427
1450
|
for (const [n, [s, r]] of t)
|
|
1428
1451
|
yield [e(s, r, n), r];
|
|
1429
1452
|
});
|
|
@@ -1601,13 +1624,13 @@ class u {
|
|
|
1601
1624
|
}
|
|
1602
1625
|
[Symbol.toStringTag] = "ReducedIterator";
|
|
1603
1626
|
}
|
|
1604
|
-
class
|
|
1627
|
+
class _ {
|
|
1605
1628
|
/**
|
|
1606
1629
|
* The internal {@link SmartAsyncIterator} object that holds the elements to aggregate.
|
|
1607
1630
|
*/
|
|
1608
1631
|
_elements;
|
|
1609
1632
|
constructor(e) {
|
|
1610
|
-
this._elements = new
|
|
1633
|
+
this._elements = new m(e);
|
|
1611
1634
|
}
|
|
1612
1635
|
/**
|
|
1613
1636
|
* Determines whether all elements of each group of the iterator satisfy a given condition.
|
|
@@ -1646,7 +1669,7 @@ class w {
|
|
|
1646
1669
|
const [r, o] = t.get(n) ?? [0, !0];
|
|
1647
1670
|
o && t.set(n, [r + 1, await e(n, s, r)]);
|
|
1648
1671
|
}
|
|
1649
|
-
return new
|
|
1672
|
+
return new h(function* () {
|
|
1650
1673
|
for (const [n, [s, r]] of t)
|
|
1651
1674
|
yield [n, r];
|
|
1652
1675
|
});
|
|
@@ -1688,14 +1711,14 @@ class w {
|
|
|
1688
1711
|
const [r, o] = t.get(n) ?? [0, !1];
|
|
1689
1712
|
o || t.set(n, [r + 1, await e(n, s, r)]);
|
|
1690
1713
|
}
|
|
1691
|
-
return new
|
|
1714
|
+
return new h(function* () {
|
|
1692
1715
|
for (const [n, [s, r]] of t)
|
|
1693
1716
|
yield [n, r];
|
|
1694
1717
|
});
|
|
1695
1718
|
}
|
|
1696
1719
|
filter(e) {
|
|
1697
1720
|
const t = this._elements;
|
|
1698
|
-
return new
|
|
1721
|
+
return new _(async function* () {
|
|
1699
1722
|
const n = /* @__PURE__ */ new Map();
|
|
1700
1723
|
for await (const [s, r] of t) {
|
|
1701
1724
|
const o = n.get(s) ?? 0;
|
|
@@ -1737,7 +1760,7 @@ class w {
|
|
|
1737
1760
|
*/
|
|
1738
1761
|
map(e) {
|
|
1739
1762
|
const t = this._elements;
|
|
1740
|
-
return new
|
|
1763
|
+
return new _(async function* () {
|
|
1741
1764
|
const n = /* @__PURE__ */ new Map();
|
|
1742
1765
|
for await (const [s, r] of t) {
|
|
1743
1766
|
const o = n.get(s) ?? 0;
|
|
@@ -1759,7 +1782,7 @@ class w {
|
|
|
1759
1782
|
}
|
|
1760
1783
|
n.set(s, [o + 1, await e(s, a, r, o)]);
|
|
1761
1784
|
}
|
|
1762
|
-
return new
|
|
1785
|
+
return new h(function* () {
|
|
1763
1786
|
for (const [s, [r, o]] of n)
|
|
1764
1787
|
yield [s, o];
|
|
1765
1788
|
});
|
|
@@ -1802,13 +1825,13 @@ class w {
|
|
|
1802
1825
|
*/
|
|
1803
1826
|
flatMap(e) {
|
|
1804
1827
|
const t = this._elements;
|
|
1805
|
-
return new
|
|
1828
|
+
return new _(async function* () {
|
|
1806
1829
|
const n = /* @__PURE__ */ new Map();
|
|
1807
1830
|
for await (const [s, r] of t) {
|
|
1808
1831
|
const o = n.get(s) ?? 0, a = await e(s, r, o);
|
|
1809
1832
|
if (a instanceof Array)
|
|
1810
|
-
for (const
|
|
1811
|
-
yield [s,
|
|
1833
|
+
for (const u of a)
|
|
1834
|
+
yield [s, u];
|
|
1812
1835
|
else
|
|
1813
1836
|
yield [s, a];
|
|
1814
1837
|
n.set(s, o + 1);
|
|
@@ -1846,7 +1869,7 @@ class w {
|
|
|
1846
1869
|
*/
|
|
1847
1870
|
drop(e) {
|
|
1848
1871
|
const t = this._elements;
|
|
1849
|
-
return new
|
|
1872
|
+
return new _(async function* () {
|
|
1850
1873
|
const n = /* @__PURE__ */ new Map();
|
|
1851
1874
|
for await (const [s, r] of t) {
|
|
1852
1875
|
const o = n.get(s) ?? 0;
|
|
@@ -1889,7 +1912,7 @@ class w {
|
|
|
1889
1912
|
*/
|
|
1890
1913
|
take(e) {
|
|
1891
1914
|
const t = this._elements;
|
|
1892
|
-
return new
|
|
1915
|
+
return new _(async function* () {
|
|
1893
1916
|
const n = /* @__PURE__ */ new Map();
|
|
1894
1917
|
for await (const [s, r] of t) {
|
|
1895
1918
|
const o = n.get(s) ?? 0;
|
|
@@ -1903,7 +1926,7 @@ class w {
|
|
|
1903
1926
|
let [r, o] = t.get(n) ?? [0, void 0];
|
|
1904
1927
|
o === void 0 && (await e(n, s, r) && (o = s), t.set(n, [r + 1, o]));
|
|
1905
1928
|
}
|
|
1906
|
-
return new
|
|
1929
|
+
return new h(function* () {
|
|
1907
1930
|
for (const [n, [s, r]] of t)
|
|
1908
1931
|
yield [n, r];
|
|
1909
1932
|
});
|
|
@@ -1965,7 +1988,7 @@ class w {
|
|
|
1965
1988
|
*/
|
|
1966
1989
|
unique() {
|
|
1967
1990
|
const e = this._elements;
|
|
1968
|
-
return new
|
|
1991
|
+
return new _(async function* () {
|
|
1969
1992
|
const t = /* @__PURE__ */ new Map();
|
|
1970
1993
|
for await (const [n, s] of e) {
|
|
1971
1994
|
const r = t.get(n) ?? /* @__PURE__ */ new Set();
|
|
@@ -2001,7 +2024,7 @@ class w {
|
|
|
2001
2024
|
const n = e.get(t) ?? 0;
|
|
2002
2025
|
e.set(t, n + 1);
|
|
2003
2026
|
}
|
|
2004
|
-
return new
|
|
2027
|
+
return new h(function* () {
|
|
2005
2028
|
for (const [t, n] of e)
|
|
2006
2029
|
yield [t, n];
|
|
2007
2030
|
});
|
|
@@ -2072,7 +2095,7 @@ class w {
|
|
|
2072
2095
|
*/
|
|
2073
2096
|
reorganizeBy(e) {
|
|
2074
2097
|
const t = this._elements;
|
|
2075
|
-
return new
|
|
2098
|
+
return new _(async function* () {
|
|
2076
2099
|
const n = /* @__PURE__ */ new Map();
|
|
2077
2100
|
for await (const [s, r] of t) {
|
|
2078
2101
|
const o = n.get(s) ?? 0;
|
|
@@ -2108,7 +2131,7 @@ class w {
|
|
|
2108
2131
|
*/
|
|
2109
2132
|
keys() {
|
|
2110
2133
|
const e = this._elements;
|
|
2111
|
-
return new
|
|
2134
|
+
return new m(async function* () {
|
|
2112
2135
|
const t = /* @__PURE__ */ new Set();
|
|
2113
2136
|
for await (const [n] of e)
|
|
2114
2137
|
t.has(n) || (t.add(n), yield n);
|
|
@@ -2172,7 +2195,7 @@ class w {
|
|
|
2172
2195
|
*/
|
|
2173
2196
|
values() {
|
|
2174
2197
|
const e = this._elements;
|
|
2175
|
-
return new
|
|
2198
|
+
return new m(async function* () {
|
|
2176
2199
|
for await (const [t, n] of e)
|
|
2177
2200
|
yield n;
|
|
2178
2201
|
});
|
|
@@ -2259,7 +2282,7 @@ class w {
|
|
|
2259
2282
|
}
|
|
2260
2283
|
[Symbol.toStringTag] = "AggregatedAsyncIterator";
|
|
2261
2284
|
}
|
|
2262
|
-
class
|
|
2285
|
+
class m {
|
|
2263
2286
|
/**
|
|
2264
2287
|
* The native {@link AsyncIterator} object that is being wrapped by this instance.
|
|
2265
2288
|
*/
|
|
@@ -2383,7 +2406,7 @@ class d {
|
|
|
2383
2406
|
}
|
|
2384
2407
|
filter(e) {
|
|
2385
2408
|
const t = this._iterator;
|
|
2386
|
-
return new
|
|
2409
|
+
return new m(async function* () {
|
|
2387
2410
|
let n = 0;
|
|
2388
2411
|
for (; ; ) {
|
|
2389
2412
|
const s = await t.next();
|
|
@@ -2426,7 +2449,7 @@ class d {
|
|
|
2426
2449
|
*/
|
|
2427
2450
|
map(e) {
|
|
2428
2451
|
const t = this._iterator;
|
|
2429
|
-
return new
|
|
2452
|
+
return new m(async function* () {
|
|
2430
2453
|
let n = 0;
|
|
2431
2454
|
for (; ; ) {
|
|
2432
2455
|
const s = await t.next();
|
|
@@ -2441,7 +2464,7 @@ class d {
|
|
|
2441
2464
|
if (s === void 0) {
|
|
2442
2465
|
const r = await this._iterator.next();
|
|
2443
2466
|
if (r.done)
|
|
2444
|
-
throw new
|
|
2467
|
+
throw new c("Cannot reduce an empty iterator without an initial value.");
|
|
2445
2468
|
s = r.value, n += 1;
|
|
2446
2469
|
}
|
|
2447
2470
|
for (; ; ) {
|
|
@@ -2484,7 +2507,7 @@ class d {
|
|
|
2484
2507
|
*/
|
|
2485
2508
|
flatMap(e) {
|
|
2486
2509
|
const t = this._iterator;
|
|
2487
|
-
return new
|
|
2510
|
+
return new m(async function* () {
|
|
2488
2511
|
let n = 0;
|
|
2489
2512
|
for (; ; ) {
|
|
2490
2513
|
const s = await t.next();
|
|
@@ -2533,7 +2556,7 @@ class d {
|
|
|
2533
2556
|
*/
|
|
2534
2557
|
drop(e) {
|
|
2535
2558
|
const t = this._iterator;
|
|
2536
|
-
return new
|
|
2559
|
+
return new m(async function* () {
|
|
2537
2560
|
let n = 0;
|
|
2538
2561
|
for (; n < e; ) {
|
|
2539
2562
|
if ((await t.next()).done)
|
|
@@ -2582,7 +2605,7 @@ class d {
|
|
|
2582
2605
|
*/
|
|
2583
2606
|
take(e) {
|
|
2584
2607
|
const t = this._iterator;
|
|
2585
|
-
return new
|
|
2608
|
+
return new m(async function* () {
|
|
2586
2609
|
let n = 0;
|
|
2587
2610
|
for (; n < e; ) {
|
|
2588
2611
|
const s = await t.next();
|
|
@@ -2661,7 +2684,7 @@ class d {
|
|
|
2661
2684
|
*/
|
|
2662
2685
|
unique() {
|
|
2663
2686
|
const e = this._iterator;
|
|
2664
|
-
return new
|
|
2687
|
+
return new m(async function* () {
|
|
2665
2688
|
const t = /* @__PURE__ */ new Set();
|
|
2666
2689
|
for (; ; ) {
|
|
2667
2690
|
const n = await e.next();
|
|
@@ -2878,7 +2901,7 @@ class d {
|
|
|
2878
2901
|
* @returns A new instance of the {@link AggregatedAsyncIterator} class containing the grouped elements.
|
|
2879
2902
|
*/
|
|
2880
2903
|
groupBy(e) {
|
|
2881
|
-
return new
|
|
2904
|
+
return new _(this.map(async (t, n) => [await e(t, n), t]));
|
|
2882
2905
|
}
|
|
2883
2906
|
/**
|
|
2884
2907
|
* Materializes the iterator into an array.
|
|
@@ -2911,7 +2934,7 @@ class d {
|
|
|
2911
2934
|
return this;
|
|
2912
2935
|
}
|
|
2913
2936
|
}
|
|
2914
|
-
class
|
|
2937
|
+
class d {
|
|
2915
2938
|
/**
|
|
2916
2939
|
* The internal {@link SmartIterator} object that holds the elements to aggregate.
|
|
2917
2940
|
*/
|
|
@@ -2955,7 +2978,7 @@ class h {
|
|
|
2955
2978
|
const [r, o] = t.get(n) ?? [0, !0];
|
|
2956
2979
|
o && t.set(n, [r + 1, e(n, s, r)]);
|
|
2957
2980
|
}
|
|
2958
|
-
return new
|
|
2981
|
+
return new h(function* () {
|
|
2959
2982
|
for (const [n, [s, r]] of t)
|
|
2960
2983
|
yield [n, r];
|
|
2961
2984
|
});
|
|
@@ -2996,14 +3019,14 @@ class h {
|
|
|
2996
3019
|
const [r, o] = t.get(n) ?? [0, !1];
|
|
2997
3020
|
o || t.set(n, [r + 1, e(n, s, r)]);
|
|
2998
3021
|
}
|
|
2999
|
-
return new
|
|
3022
|
+
return new h(function* () {
|
|
3000
3023
|
for (const [n, [s, r]] of t)
|
|
3001
3024
|
yield [n, r];
|
|
3002
3025
|
});
|
|
3003
3026
|
}
|
|
3004
3027
|
filter(e) {
|
|
3005
3028
|
const t = this._elements;
|
|
3006
|
-
return new
|
|
3029
|
+
return new d(function* () {
|
|
3007
3030
|
const n = /* @__PURE__ */ new Map();
|
|
3008
3031
|
for (const [s, r] of t) {
|
|
3009
3032
|
const o = n.get(s) ?? 0;
|
|
@@ -3045,7 +3068,7 @@ class h {
|
|
|
3045
3068
|
*/
|
|
3046
3069
|
map(e) {
|
|
3047
3070
|
const t = this._elements;
|
|
3048
|
-
return new
|
|
3071
|
+
return new d(function* () {
|
|
3049
3072
|
const n = /* @__PURE__ */ new Map();
|
|
3050
3073
|
for (const [s, r] of t) {
|
|
3051
3074
|
const o = n.get(s) ?? 0;
|
|
@@ -3067,7 +3090,7 @@ class h {
|
|
|
3067
3090
|
}
|
|
3068
3091
|
n.set(s, [o + 1, e(s, a, r, o)]);
|
|
3069
3092
|
}
|
|
3070
|
-
return new
|
|
3093
|
+
return new h(function* () {
|
|
3071
3094
|
for (const [s, [r, o]] of n)
|
|
3072
3095
|
yield [s, o];
|
|
3073
3096
|
});
|
|
@@ -3110,13 +3133,13 @@ class h {
|
|
|
3110
3133
|
*/
|
|
3111
3134
|
flatMap(e) {
|
|
3112
3135
|
const t = this._elements;
|
|
3113
|
-
return new
|
|
3136
|
+
return new d(function* () {
|
|
3114
3137
|
const n = /* @__PURE__ */ new Map();
|
|
3115
3138
|
for (const [s, r] of t) {
|
|
3116
3139
|
const o = n.get(s) ?? 0, a = e(s, r, o);
|
|
3117
3140
|
if (a instanceof Array)
|
|
3118
|
-
for (const
|
|
3119
|
-
yield [s,
|
|
3141
|
+
for (const u of a)
|
|
3142
|
+
yield [s, u];
|
|
3120
3143
|
else
|
|
3121
3144
|
yield [s, a];
|
|
3122
3145
|
n.set(s, o + 1);
|
|
@@ -3154,7 +3177,7 @@ class h {
|
|
|
3154
3177
|
*/
|
|
3155
3178
|
drop(e) {
|
|
3156
3179
|
const t = this._elements;
|
|
3157
|
-
return new
|
|
3180
|
+
return new d(function* () {
|
|
3158
3181
|
const n = /* @__PURE__ */ new Map();
|
|
3159
3182
|
for (const [s, r] of t) {
|
|
3160
3183
|
const o = n.get(s) ?? 0;
|
|
@@ -3197,7 +3220,7 @@ class h {
|
|
|
3197
3220
|
*/
|
|
3198
3221
|
take(e) {
|
|
3199
3222
|
const t = this._elements;
|
|
3200
|
-
return new
|
|
3223
|
+
return new d(function* () {
|
|
3201
3224
|
const n = /* @__PURE__ */ new Map();
|
|
3202
3225
|
for (const [s, r] of t) {
|
|
3203
3226
|
const o = n.get(s) ?? 0;
|
|
@@ -3211,7 +3234,7 @@ class h {
|
|
|
3211
3234
|
let [r, o] = t.get(n) ?? [0, void 0];
|
|
3212
3235
|
o === void 0 && (e(n, s, r) && (o = s), t.set(n, [r + 1, o]));
|
|
3213
3236
|
}
|
|
3214
|
-
return new
|
|
3237
|
+
return new h(function* () {
|
|
3215
3238
|
for (const [n, [s, r]] of t)
|
|
3216
3239
|
yield [n, r];
|
|
3217
3240
|
});
|
|
@@ -3273,7 +3296,7 @@ class h {
|
|
|
3273
3296
|
*/
|
|
3274
3297
|
unique() {
|
|
3275
3298
|
const e = this._elements;
|
|
3276
|
-
return new
|
|
3299
|
+
return new d(function* () {
|
|
3277
3300
|
const t = /* @__PURE__ */ new Map();
|
|
3278
3301
|
for (const [n, s] of e) {
|
|
3279
3302
|
const r = t.get(n) ?? /* @__PURE__ */ new Set();
|
|
@@ -3308,7 +3331,7 @@ class h {
|
|
|
3308
3331
|
const n = e.get(t) ?? 0;
|
|
3309
3332
|
e.set(t, n + 1);
|
|
3310
3333
|
}
|
|
3311
|
-
return new
|
|
3334
|
+
return new h(function* () {
|
|
3312
3335
|
for (const [t, n] of e)
|
|
3313
3336
|
yield [t, n];
|
|
3314
3337
|
});
|
|
@@ -3377,7 +3400,7 @@ class h {
|
|
|
3377
3400
|
*/
|
|
3378
3401
|
reorganizeBy(e) {
|
|
3379
3402
|
const t = this._elements;
|
|
3380
|
-
return new
|
|
3403
|
+
return new d(function* () {
|
|
3381
3404
|
const n = /* @__PURE__ */ new Map();
|
|
3382
3405
|
for (const [s, r] of t) {
|
|
3383
3406
|
const o = n.get(s) ?? 0;
|
|
@@ -3564,8 +3587,8 @@ class h {
|
|
|
3564
3587
|
}
|
|
3565
3588
|
[Symbol.toStringTag] = "AggregatedIterator";
|
|
3566
3589
|
}
|
|
3567
|
-
const
|
|
3568
|
-
class
|
|
3590
|
+
const q = Function;
|
|
3591
|
+
class R extends q {
|
|
3569
3592
|
/**
|
|
3570
3593
|
* Initializes a new instance of the {@link CallableObject} class.
|
|
3571
3594
|
*/
|
|
@@ -3576,7 +3599,7 @@ class M extends N {
|
|
|
3576
3599
|
}
|
|
3577
3600
|
[Symbol.toStringTag] = "CallableObject";
|
|
3578
3601
|
}
|
|
3579
|
-
class
|
|
3602
|
+
class H extends R {
|
|
3580
3603
|
/**
|
|
3581
3604
|
* The array containing all the functions in the chain.
|
|
3582
3605
|
*/
|
|
@@ -3614,7 +3637,10 @@ class K extends M {
|
|
|
3614
3637
|
* @returns An array containing the return values of all functions.
|
|
3615
3638
|
*/
|
|
3616
3639
|
_invoke(...e) {
|
|
3617
|
-
|
|
3640
|
+
const t = this._callbacks.length, n = new Array(t);
|
|
3641
|
+
for (let s = 0; s < t; s += 1)
|
|
3642
|
+
n[s] = this._callbacks[s](...e);
|
|
3643
|
+
return n;
|
|
3618
3644
|
}
|
|
3619
3645
|
/**
|
|
3620
3646
|
* Adds a function to the chain.
|
|
@@ -3746,24 +3772,31 @@ class g {
|
|
|
3746
3772
|
}
|
|
3747
3773
|
publish(e, ...t) {
|
|
3748
3774
|
let n, s = this._subscribers.get(e);
|
|
3749
|
-
|
|
3775
|
+
if (s) {
|
|
3776
|
+
const r = s.slice(), o = r.length;
|
|
3777
|
+
n = new Array(o);
|
|
3778
|
+
for (let a = 0; a < o; a += 1)
|
|
3779
|
+
n[a] = r[a](...t);
|
|
3780
|
+
} else
|
|
3781
|
+
n = [];
|
|
3782
|
+
return e.startsWith("__") || (s = this._subscribers.get("*"), s && s.slice().forEach((r) => r(e, ...t))), n;
|
|
3750
3783
|
}
|
|
3751
3784
|
subscribe(e, t) {
|
|
3752
3785
|
const n = this._subscribers.get(e) ?? [];
|
|
3753
3786
|
return n.push(t), this._subscribers.set(e, n), () => {
|
|
3754
3787
|
const s = n.indexOf(t);
|
|
3755
3788
|
if (s < 0)
|
|
3756
|
-
throw new
|
|
3789
|
+
throw new S("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed.");
|
|
3757
3790
|
n.splice(s, 1);
|
|
3758
3791
|
};
|
|
3759
3792
|
}
|
|
3760
3793
|
unsubscribe(e, t) {
|
|
3761
3794
|
const n = this._subscribers.get(e);
|
|
3762
3795
|
if (!n)
|
|
3763
|
-
throw new
|
|
3796
|
+
throw new S("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed or was never subscribed.");
|
|
3764
3797
|
const s = n.indexOf(t);
|
|
3765
3798
|
if (s < 0)
|
|
3766
|
-
throw new
|
|
3799
|
+
throw new S("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed or was never subscribed.");
|
|
3767
3800
|
n.splice(s, 1), n.length === 0 && this._subscribers.delete(e);
|
|
3768
3801
|
}
|
|
3769
3802
|
unsubscribeAll(e) {
|
|
@@ -3794,9 +3827,9 @@ class g {
|
|
|
3794
3827
|
}
|
|
3795
3828
|
[Symbol.toStringTag] = "Publisher";
|
|
3796
3829
|
}
|
|
3797
|
-
const
|
|
3830
|
+
const I = () => {
|
|
3798
3831
|
};
|
|
3799
|
-
class
|
|
3832
|
+
class X extends R {
|
|
3800
3833
|
/**
|
|
3801
3834
|
* The currently selected implementation of the callback.
|
|
3802
3835
|
*/
|
|
@@ -3844,7 +3877,7 @@ class Q extends M {
|
|
|
3844
3877
|
_invoke;
|
|
3845
3878
|
constructor(e, t = "default") {
|
|
3846
3879
|
super(), this._callbacks = /* @__PURE__ */ new Map(), this._isEnabled = !0, e ? this._callbacks.set(t, e) : (t = "", e = (() => {
|
|
3847
|
-
throw new
|
|
3880
|
+
throw new j(
|
|
3848
3881
|
"The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
|
|
3849
3882
|
);
|
|
3850
3883
|
})), this._key = t, this._callback = e, this._invoke = (...n) => this._callback(...n);
|
|
@@ -3874,16 +3907,16 @@ class Q extends M {
|
|
|
3874
3907
|
enable(e) {
|
|
3875
3908
|
if (e === void 0) {
|
|
3876
3909
|
if (!this._key)
|
|
3877
|
-
throw new
|
|
3910
|
+
throw new y(
|
|
3878
3911
|
"The `SwitchableCallback` has no callback defined yet. Did you forget to call the `register` method?"
|
|
3879
3912
|
);
|
|
3880
3913
|
e = this._key;
|
|
3881
3914
|
} else if (e) {
|
|
3882
3915
|
if (!this._callbacks.has(e))
|
|
3883
|
-
throw new
|
|
3884
|
-
} else throw new
|
|
3916
|
+
throw new y(`The key '${e}' doesn't yet have any associated callback.`);
|
|
3917
|
+
} else throw new y("The key must be a non-empty string.");
|
|
3885
3918
|
if (this._isEnabled)
|
|
3886
|
-
throw new
|
|
3919
|
+
throw new b("The `SwitchableCallback` is already enabled.");
|
|
3887
3920
|
this._callback = this._callbacks.get(e), this._isEnabled = !0;
|
|
3888
3921
|
}
|
|
3889
3922
|
/**
|
|
@@ -3901,8 +3934,8 @@ class Q extends M {
|
|
|
3901
3934
|
*/
|
|
3902
3935
|
disable() {
|
|
3903
3936
|
if (!this._isEnabled)
|
|
3904
|
-
throw new
|
|
3905
|
-
this._callback =
|
|
3937
|
+
throw new b("The `SwitchableCallback` is already disabled.");
|
|
3938
|
+
this._callback = I, this._isEnabled = !1;
|
|
3906
3939
|
}
|
|
3907
3940
|
/**
|
|
3908
3941
|
* Registers a new implementation for the callback.
|
|
@@ -3928,7 +3961,7 @@ class Q extends M {
|
|
|
3928
3961
|
if (this._callbacks.size === 0)
|
|
3929
3962
|
this._key = e, this._callback = t;
|
|
3930
3963
|
else if (this._callbacks.has(e))
|
|
3931
|
-
throw new
|
|
3964
|
+
throw new y(`The key '${e}' has already been used for another callback.`);
|
|
3932
3965
|
this._callbacks.set(e, t);
|
|
3933
3966
|
}
|
|
3934
3967
|
/**
|
|
@@ -3951,9 +3984,9 @@ class Q extends M {
|
|
|
3951
3984
|
*/
|
|
3952
3985
|
unregister(e) {
|
|
3953
3986
|
if (this._key === e)
|
|
3954
|
-
throw new
|
|
3987
|
+
throw new y("Unable to unregister the currently selected callback.");
|
|
3955
3988
|
if (!this._callbacks.has(e))
|
|
3956
|
-
throw new
|
|
3989
|
+
throw new y(`The key '${e}' doesn't yet have any associated callback.`);
|
|
3957
3990
|
this._callbacks.delete(e);
|
|
3958
3991
|
}
|
|
3959
3992
|
/**
|
|
@@ -3976,12 +4009,231 @@ class Q extends M {
|
|
|
3976
4009
|
*/
|
|
3977
4010
|
switch(e) {
|
|
3978
4011
|
if (!this._callbacks.has(e))
|
|
3979
|
-
throw new
|
|
4012
|
+
throw new y(`The key '${e}' doesn't yet have any associated callback.`);
|
|
3980
4013
|
this._key !== e && (this._key = e, this._isEnabled && (this._callback = this._callbacks.get(e)));
|
|
3981
4014
|
}
|
|
3982
4015
|
[Symbol.toStringTag] = "SwitchableCallback";
|
|
3983
4016
|
}
|
|
3984
|
-
class
|
|
4017
|
+
class Z extends Array {
|
|
4018
|
+
/**
|
|
4019
|
+
* The internal {@link Publisher} instance used to publish events.
|
|
4020
|
+
*/
|
|
4021
|
+
_publisher;
|
|
4022
|
+
constructor(...e) {
|
|
4023
|
+
super(...e), this._publisher = new g();
|
|
4024
|
+
}
|
|
4025
|
+
/**
|
|
4026
|
+
* Appends new elements to the end of the {@link Array} and returns the new length of the array.
|
|
4027
|
+
*
|
|
4028
|
+
* ---
|
|
4029
|
+
*
|
|
4030
|
+
* @example
|
|
4031
|
+
* ```ts
|
|
4032
|
+
* const array = new ArrayView<number>();
|
|
4033
|
+
* array.push(2, 4, 8);
|
|
4034
|
+
*
|
|
4035
|
+
* console.log(array); // ArrayView(3) [2, 4, 8]
|
|
4036
|
+
* ```
|
|
4037
|
+
*
|
|
4038
|
+
* ---
|
|
4039
|
+
*
|
|
4040
|
+
* @param items New elements to add to the array.
|
|
4041
|
+
*
|
|
4042
|
+
* @returns The new length of the array.
|
|
4043
|
+
*/
|
|
4044
|
+
push(...e) {
|
|
4045
|
+
const t = this.length, n = super.push(...e);
|
|
4046
|
+
for (let s = 0; s < e.length; s += 1)
|
|
4047
|
+
this._publisher.publish("add", e[s], t + s);
|
|
4048
|
+
return n;
|
|
4049
|
+
}
|
|
4050
|
+
/**
|
|
4051
|
+
* Removes the last element from the {@link Array} and returns it.
|
|
4052
|
+
*
|
|
4053
|
+
* ---
|
|
4054
|
+
*
|
|
4055
|
+
* @example
|
|
4056
|
+
* ```ts
|
|
4057
|
+
* const array = new ArrayView<number>(2, 4, 8);
|
|
4058
|
+
* array.pop(); // 8
|
|
4059
|
+
*
|
|
4060
|
+
* console.log(array); // ArrayView(2) [2, 4]
|
|
4061
|
+
* ```
|
|
4062
|
+
*
|
|
4063
|
+
* ---
|
|
4064
|
+
*
|
|
4065
|
+
* @returns The removed element, or `undefined` if the array is empty.
|
|
4066
|
+
*/
|
|
4067
|
+
pop() {
|
|
4068
|
+
const e = this.length - 1;
|
|
4069
|
+
if (e < 0)
|
|
4070
|
+
return;
|
|
4071
|
+
const t = super.pop();
|
|
4072
|
+
return this._publisher.publish("remove", t, e), t;
|
|
4073
|
+
}
|
|
4074
|
+
/**
|
|
4075
|
+
* Removes the first element from the {@link Array} and returns it.
|
|
4076
|
+
*
|
|
4077
|
+
* ---
|
|
4078
|
+
*
|
|
4079
|
+
* @example
|
|
4080
|
+
* ```ts
|
|
4081
|
+
* const array = new ArrayView<number>(2, 4, 8);
|
|
4082
|
+
* array.shift(); // 2
|
|
4083
|
+
*
|
|
4084
|
+
* console.log(array); // ArrayView(2) [4, 8]
|
|
4085
|
+
* ```
|
|
4086
|
+
*
|
|
4087
|
+
* ---
|
|
4088
|
+
*
|
|
4089
|
+
* @returns The removed element, or `undefined` if the array is empty.
|
|
4090
|
+
*/
|
|
4091
|
+
shift() {
|
|
4092
|
+
if (this.length === 0)
|
|
4093
|
+
return;
|
|
4094
|
+
const e = super.shift();
|
|
4095
|
+
return this._publisher.publish("remove", e, 0), e;
|
|
4096
|
+
}
|
|
4097
|
+
/**
|
|
4098
|
+
* Inserts new elements at the start of the {@link Array} and returns the new length of the array.
|
|
4099
|
+
*
|
|
4100
|
+
* ---
|
|
4101
|
+
*
|
|
4102
|
+
* @example
|
|
4103
|
+
* ```ts
|
|
4104
|
+
* const array = new ArrayView<number>(4, 8);
|
|
4105
|
+
* array.unshift(2);
|
|
4106
|
+
*
|
|
4107
|
+
* console.log(array); // ArrayView(3) [2, 4, 8]
|
|
4108
|
+
* ```
|
|
4109
|
+
*
|
|
4110
|
+
* ---
|
|
4111
|
+
*
|
|
4112
|
+
* @param items Elements to insert at the start of the array.
|
|
4113
|
+
*
|
|
4114
|
+
* @returns The new length of the array.
|
|
4115
|
+
*/
|
|
4116
|
+
unshift(...e) {
|
|
4117
|
+
const t = super.unshift(...e);
|
|
4118
|
+
for (let n = 0; n < e.length; n += 1)
|
|
4119
|
+
this._publisher.publish("add", e[n], n);
|
|
4120
|
+
return t;
|
|
4121
|
+
}
|
|
4122
|
+
/**
|
|
4123
|
+
* Removes elements from the {@link Array} and, if necessary, inserts new elements in their place,
|
|
4124
|
+
* returning the deleted elements.
|
|
4125
|
+
*
|
|
4126
|
+
* ---
|
|
4127
|
+
*
|
|
4128
|
+
* @example
|
|
4129
|
+
* ```ts
|
|
4130
|
+
* const array = new ArrayView<number>(2, 4, 8, 16);
|
|
4131
|
+
* array.splice(1, 2, 32, 64); // [4, 8]
|
|
4132
|
+
*
|
|
4133
|
+
* console.log(array); // ArrayView(4) [2, 32, 64, 16]
|
|
4134
|
+
* ```
|
|
4135
|
+
*
|
|
4136
|
+
* ---
|
|
4137
|
+
*
|
|
4138
|
+
* @param start The zero-based location in the array from which to start removing elements.
|
|
4139
|
+
* @param deleteCount The number of elements to remove.
|
|
4140
|
+
* @param items Elements to insert into the array in place of the deleted elements.
|
|
4141
|
+
*
|
|
4142
|
+
* @returns An array containing the elements that were deleted.
|
|
4143
|
+
*/
|
|
4144
|
+
splice(e, t, ...n) {
|
|
4145
|
+
const s = e < 0 ? Math.max(this.length + e, 0) : Math.min(e, this.length), r = t === void 0 ? this.length - s : Math.min(Math.max(t, 0), this.length - s), o = super.splice(e, r, ...n);
|
|
4146
|
+
for (let a = 0; a < o.length; a += 1)
|
|
4147
|
+
this._publisher.publish("remove", o[a], s + a);
|
|
4148
|
+
for (let a = 0; a < n.length; a += 1)
|
|
4149
|
+
this._publisher.publish("add", n[a], s + a);
|
|
4150
|
+
return o;
|
|
4151
|
+
}
|
|
4152
|
+
/**
|
|
4153
|
+
* Removes all elements from the {@link Array}.
|
|
4154
|
+
*
|
|
4155
|
+
* ---
|
|
4156
|
+
*
|
|
4157
|
+
* @example
|
|
4158
|
+
* ```ts
|
|
4159
|
+
* const array = new ArrayView<number>(2, 4, 8);
|
|
4160
|
+
* array.clear();
|
|
4161
|
+
*
|
|
4162
|
+
* console.log(array); // ArrayView(0) []
|
|
4163
|
+
* ```
|
|
4164
|
+
*/
|
|
4165
|
+
clear() {
|
|
4166
|
+
const e = this.length;
|
|
4167
|
+
this.length = 0, e > 0 && this._publisher.publish("clear");
|
|
4168
|
+
}
|
|
4169
|
+
/**
|
|
4170
|
+
* Subscribes to the `add` event of the array with a callback that will be executed when an element is added.
|
|
4171
|
+
*
|
|
4172
|
+
* ---
|
|
4173
|
+
*
|
|
4174
|
+
* @example
|
|
4175
|
+
* ```ts
|
|
4176
|
+
* array.onAdd((value, index) => console.log(`Added ${value} at index ${index}`));
|
|
4177
|
+
*
|
|
4178
|
+
* array.push(2); // "Added 2 at index 0"
|
|
4179
|
+
* array.push(42); // "Added 42 at index 1"
|
|
4180
|
+
* ```
|
|
4181
|
+
*
|
|
4182
|
+
* ---
|
|
4183
|
+
*
|
|
4184
|
+
* @param callback The callback that will be executed when an element is added to the array.
|
|
4185
|
+
*
|
|
4186
|
+
* @returns A function that can be used to unsubscribe from the event.
|
|
4187
|
+
*/
|
|
4188
|
+
onAdd(e) {
|
|
4189
|
+
return this._publisher.subscribe("add", e);
|
|
4190
|
+
}
|
|
4191
|
+
/**
|
|
4192
|
+
* Subscribes to the `remove` event of the array with a callback that will be executed when an element is removed.
|
|
4193
|
+
*
|
|
4194
|
+
* ---
|
|
4195
|
+
*
|
|
4196
|
+
* @example
|
|
4197
|
+
* ```ts
|
|
4198
|
+
* array.onRemove((value, index) => console.log(`Removed ${value} at index ${index}`));
|
|
4199
|
+
*
|
|
4200
|
+
* array.pop(); // "Removed 8 at index 2"
|
|
4201
|
+
* array.shift(); // "Removed 2 at index 0"
|
|
4202
|
+
* ```
|
|
4203
|
+
*
|
|
4204
|
+
* ---
|
|
4205
|
+
*
|
|
4206
|
+
* @param callback The callback that will be executed when an element is removed from the array.
|
|
4207
|
+
*
|
|
4208
|
+
* @returns A function that can be used to unsubscribe from the event.
|
|
4209
|
+
*/
|
|
4210
|
+
onRemove(e) {
|
|
4211
|
+
return this._publisher.subscribe("remove", e);
|
|
4212
|
+
}
|
|
4213
|
+
/**
|
|
4214
|
+
* Subscribes to the `clear` event of the array with a callback that will be executed when the array is cleared.
|
|
4215
|
+
*
|
|
4216
|
+
* ---
|
|
4217
|
+
*
|
|
4218
|
+
* @example
|
|
4219
|
+
* ```ts
|
|
4220
|
+
* array.onClear(() => console.log("The array has been cleared."));
|
|
4221
|
+
* array.clear(); // "The array has been cleared."
|
|
4222
|
+
* ```
|
|
4223
|
+
*
|
|
4224
|
+
* ---
|
|
4225
|
+
*
|
|
4226
|
+
* @param callback The callback that will be executed when the array is cleared.
|
|
4227
|
+
*
|
|
4228
|
+
* @returns A function that can be used to unsubscribe from the event.
|
|
4229
|
+
*/
|
|
4230
|
+
onClear(e) {
|
|
4231
|
+
return this._publisher.subscribe("clear", e);
|
|
4232
|
+
}
|
|
4233
|
+
[Symbol.toStringTag] = "ArrayView";
|
|
4234
|
+
static [Symbol.species] = Array;
|
|
4235
|
+
}
|
|
4236
|
+
class W extends Map {
|
|
3985
4237
|
/**
|
|
3986
4238
|
* The internal {@link Publisher} instance used to publish events.
|
|
3987
4239
|
*/
|
|
@@ -4003,7 +4255,7 @@ class H extends Map {
|
|
|
4003
4255
|
constructor(e) {
|
|
4004
4256
|
if (super(), this._publisher = new g(), e)
|
|
4005
4257
|
for (const [t, n] of e)
|
|
4006
|
-
|
|
4258
|
+
super.set(t, n);
|
|
4007
4259
|
}
|
|
4008
4260
|
/**
|
|
4009
4261
|
* Adds a new entry with a specified key and value to the {@link Map}.
|
|
@@ -4138,7 +4390,7 @@ class H extends Map {
|
|
|
4138
4390
|
}
|
|
4139
4391
|
[Symbol.toStringTag] = "MapView";
|
|
4140
4392
|
}
|
|
4141
|
-
class
|
|
4393
|
+
class U extends Set {
|
|
4142
4394
|
/**
|
|
4143
4395
|
* The internal {@link Publisher} instance used to publish events.
|
|
4144
4396
|
*/
|
|
@@ -4160,7 +4412,7 @@ class X extends Set {
|
|
|
4160
4412
|
constructor(e) {
|
|
4161
4413
|
if (super(), this._publisher = new g(), e)
|
|
4162
4414
|
for (const t of e)
|
|
4163
|
-
|
|
4415
|
+
super.add(t);
|
|
4164
4416
|
}
|
|
4165
4417
|
/**
|
|
4166
4418
|
* Appends a new element with a specified value to the end of the {@link Set}.
|
|
@@ -4175,7 +4427,7 @@ class X extends Set {
|
|
|
4175
4427
|
* .add(4)
|
|
4176
4428
|
* .add(8);
|
|
4177
4429
|
*
|
|
4178
|
-
* console.log(set); // SetView(
|
|
4430
|
+
* console.log(set); // SetView(3) { 2, 4, 8 }
|
|
4179
4431
|
* ```
|
|
4180
4432
|
*
|
|
4181
4433
|
* ---
|
|
@@ -4294,7 +4546,7 @@ class X extends Set {
|
|
|
4294
4546
|
}
|
|
4295
4547
|
[Symbol.toStringTag] = "SetView";
|
|
4296
4548
|
}
|
|
4297
|
-
class
|
|
4549
|
+
class ee {
|
|
4298
4550
|
/**
|
|
4299
4551
|
* Whether to prefer the {@link localStorage} over the {@link sessionStorage} when calling an ambivalent method.
|
|
4300
4552
|
*
|
|
@@ -4328,8 +4580,8 @@ class Z {
|
|
|
4328
4580
|
* If omitted, it defaults to `true` to prefer the persistent storage.
|
|
4329
4581
|
*/
|
|
4330
4582
|
constructor(e = !0) {
|
|
4331
|
-
if (!
|
|
4332
|
-
throw new
|
|
4583
|
+
if (!E)
|
|
4584
|
+
throw new z(
|
|
4333
4585
|
"The `JSONStorage` class can only be instantiated within a browser environment."
|
|
4334
4586
|
);
|
|
4335
4587
|
this._preferPersistence = e, this._volatile = window.sessionStorage, this._persistent = window.localStorage;
|
|
@@ -4602,7 +4854,7 @@ class Z {
|
|
|
4602
4854
|
}
|
|
4603
4855
|
[Symbol.toStringTag] = "JSONStorage";
|
|
4604
4856
|
}
|
|
4605
|
-
class
|
|
4857
|
+
class w {
|
|
4606
4858
|
/**
|
|
4607
4859
|
* Wraps a new {@link SmartPromise} object around an existing native {@link Promise} object.
|
|
4608
4860
|
*
|
|
@@ -4627,7 +4879,7 @@ class m {
|
|
|
4627
4879
|
* @returns A new {@link SmartPromise} object that wraps the provided promise.
|
|
4628
4880
|
*/
|
|
4629
4881
|
static FromPromise(e) {
|
|
4630
|
-
return new
|
|
4882
|
+
return new w((t, n) => e.then(t, n));
|
|
4631
4883
|
}
|
|
4632
4884
|
/**
|
|
4633
4885
|
* A flag indicating whether the promise is still pending or not.
|
|
@@ -4735,7 +4987,7 @@ class m {
|
|
|
4735
4987
|
}
|
|
4736
4988
|
[Symbol.toStringTag] = "SmartPromise";
|
|
4737
4989
|
}
|
|
4738
|
-
class
|
|
4990
|
+
class F extends w {
|
|
4739
4991
|
/**
|
|
4740
4992
|
* The exposed function that allows to resolve the promise.
|
|
4741
4993
|
*
|
|
@@ -4808,7 +5060,7 @@ class R extends m {
|
|
|
4808
5060
|
}
|
|
4809
5061
|
[Symbol.toStringTag] = "DeferredPromise";
|
|
4810
5062
|
}
|
|
4811
|
-
class
|
|
5063
|
+
class O extends w {
|
|
4812
5064
|
/**
|
|
4813
5065
|
* Initializes a new instance of the {@link TimedPromise} class.
|
|
4814
5066
|
*
|
|
@@ -4833,17 +5085,17 @@ class z extends m {
|
|
|
4833
5085
|
*/
|
|
4834
5086
|
constructor(e, t) {
|
|
4835
5087
|
super((n, s) => {
|
|
4836
|
-
const r = (
|
|
4837
|
-
clearTimeout(
|
|
4838
|
-
}, o = (
|
|
4839
|
-
clearTimeout(
|
|
4840
|
-
},
|
|
5088
|
+
const r = (p) => {
|
|
5089
|
+
clearTimeout(u), n(p);
|
|
5090
|
+
}, o = (p) => {
|
|
5091
|
+
clearTimeout(u), s(p);
|
|
5092
|
+
}, u = setTimeout(() => o(new N("The operation has timed out.")), t);
|
|
4841
5093
|
e(r, o);
|
|
4842
5094
|
});
|
|
4843
5095
|
}
|
|
4844
5096
|
[Symbol.toStringTag] = "TimedPromise";
|
|
4845
5097
|
}
|
|
4846
|
-
class
|
|
5098
|
+
class te extends w {
|
|
4847
5099
|
/**
|
|
4848
5100
|
* The number of promises currently in the queue.
|
|
4849
5101
|
*/
|
|
@@ -4867,7 +5119,7 @@ class W extends m {
|
|
|
4867
5119
|
* Accessing this property will always result in a {@link ValueException}.
|
|
4868
5120
|
*/
|
|
4869
5121
|
get isRejected() {
|
|
4870
|
-
throw new
|
|
5122
|
+
throw new c("`PromiseQueue` doesn't support rejection states.");
|
|
4871
5123
|
}
|
|
4872
5124
|
/**
|
|
4873
5125
|
* Initializes a new instance of the {@link PromiseQueue} class.
|
|
@@ -4876,7 +5128,7 @@ class W extends m {
|
|
|
4876
5128
|
super((e) => e()), this._count = 0, this._isPending = !1, this._isFulfilled = !1, this._isRejected = !1;
|
|
4877
5129
|
}
|
|
4878
5130
|
enqueue(e, t) {
|
|
4879
|
-
if (this._count += 1, e instanceof
|
|
5131
|
+
if (this._count += 1, e instanceof F) {
|
|
4880
5132
|
const s = e;
|
|
4881
5133
|
e = () => (s.resolve(), s);
|
|
4882
5134
|
}
|
|
@@ -4887,18 +5139,18 @@ class W extends m {
|
|
|
4887
5139
|
this._count -= 1, r(o);
|
|
4888
5140
|
});
|
|
4889
5141
|
};
|
|
4890
|
-
return t ? new
|
|
5142
|
+
return t ? new O(n, t) : new w(n);
|
|
4891
5143
|
}
|
|
4892
5144
|
[Symbol.toStringTag] = "PromiseQueue";
|
|
4893
5145
|
}
|
|
4894
|
-
var
|
|
4895
|
-
function
|
|
5146
|
+
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 || {}), $ = /* @__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))($ || {});
|
|
5147
|
+
function ne(i, e, t = 864e5) {
|
|
4896
5148
|
let n;
|
|
4897
5149
|
return i = new Date(i), e = new Date(e), i < e ? n = Math.floor : n = Math.ceil, n((e.getTime() - i.getTime()) / t);
|
|
4898
5150
|
}
|
|
4899
|
-
function
|
|
5151
|
+
function se(i, e, t = 864e5) {
|
|
4900
5152
|
if (i = new Date(i), e = new Date(e), i >= e)
|
|
4901
|
-
throw new
|
|
5153
|
+
throw new x("The end date must be greater than the start date.");
|
|
4902
5154
|
return new l(function* () {
|
|
4903
5155
|
const n = e.getTime();
|
|
4904
5156
|
let s = i.getTime();
|
|
@@ -4906,23 +5158,23 @@ function ee(i, e, t = 864e5) {
|
|
|
4906
5158
|
yield new Date(s), s += t;
|
|
4907
5159
|
});
|
|
4908
5160
|
}
|
|
4909
|
-
function
|
|
5161
|
+
function D(i, e = 864e5) {
|
|
4910
5162
|
if (e <= 1)
|
|
4911
|
-
throw new
|
|
5163
|
+
throw new x(
|
|
4912
5164
|
"Rounding a timestamp by milliseconds or less makes no sense.Use the timestamp value directly instead."
|
|
4913
5165
|
);
|
|
4914
5166
|
if (e > 864e5)
|
|
4915
|
-
throw new
|
|
5167
|
+
throw new x(
|
|
4916
5168
|
"Rounding by more than a day leads to unexpected results. Consider using other methods to round dates by weeks, months or years."
|
|
4917
5169
|
);
|
|
4918
5170
|
return i = new Date(i), new Date(Math.floor(i.getTime() / e) * e);
|
|
4919
5171
|
}
|
|
4920
|
-
function
|
|
5172
|
+
function re(i, e = 0) {
|
|
4921
5173
|
i = new Date(i);
|
|
4922
5174
|
const t = 7 - e, n = (i.getUTCDay() + t) % 7, s = i.getTime() - 864e5 * n;
|
|
4923
|
-
return
|
|
5175
|
+
return D(new Date(s));
|
|
4924
5176
|
}
|
|
4925
|
-
class
|
|
5177
|
+
class C {
|
|
4926
5178
|
/**
|
|
4927
5179
|
* The handle of the interval or the animation frame, depending on the environment.
|
|
4928
5180
|
* It's used to stop the game loop when the {@link GameLoop._stop} method is called.
|
|
@@ -5000,7 +5252,7 @@ class F {
|
|
|
5000
5252
|
* The interval in milliseconds that will be used if the current environment isn't a browser. Default is `40`.
|
|
5001
5253
|
*/
|
|
5002
5254
|
constructor(e, t = 40) {
|
|
5003
|
-
this._startTime = 0, this._isRunning = !1,
|
|
5255
|
+
this._startTime = 0, this._isRunning = !1, E ? (this._start = () => {
|
|
5004
5256
|
e(this.elapsedTime), this._handle = window.requestAnimationFrame(this._start);
|
|
5005
5257
|
}, this._stop = () => window.cancelAnimationFrame(this._handle)) : (console.warn(
|
|
5006
5258
|
`Not a browser environment detected. Using setInterval@${t}ms instead of requestAnimationFrame...`
|
|
@@ -5027,7 +5279,7 @@ class F {
|
|
|
5027
5279
|
*/
|
|
5028
5280
|
start(e = 0) {
|
|
5029
5281
|
if (this._isRunning)
|
|
5030
|
-
throw new
|
|
5282
|
+
throw new b("The game loop has already been started.");
|
|
5031
5283
|
this._startTime = performance.now() - e, this._start(), this._isRunning = !0, this._publisher.publish("start");
|
|
5032
5284
|
}
|
|
5033
5285
|
/**
|
|
@@ -5045,9 +5297,9 @@ class F {
|
|
|
5045
5297
|
*/
|
|
5046
5298
|
stop() {
|
|
5047
5299
|
if (!this._isRunning)
|
|
5048
|
-
throw new
|
|
5300
|
+
throw new b("The game loop had already stopped or hadn't yet started.");
|
|
5049
5301
|
if (!this._handle)
|
|
5050
|
-
throw new
|
|
5302
|
+
throw new v();
|
|
5051
5303
|
this._stop(), this._handle = void 0, this._isRunning = !1, this._publisher.publish("stop");
|
|
5052
5304
|
}
|
|
5053
5305
|
/**
|
|
@@ -5090,7 +5342,7 @@ class F {
|
|
|
5090
5342
|
}
|
|
5091
5343
|
[Symbol.toStringTag] = "GameLoop";
|
|
5092
5344
|
}
|
|
5093
|
-
class
|
|
5345
|
+
class ie extends C {
|
|
5094
5346
|
/**
|
|
5095
5347
|
* Initializes a new instance of the {@link Clock} class.
|
|
5096
5348
|
*
|
|
@@ -5107,7 +5359,7 @@ class ne extends F {
|
|
|
5107
5359
|
* The interval in milliseconds at which the clock will tick if the environment is not a browser.
|
|
5108
5360
|
* `TimeUnit.Second` by default.
|
|
5109
5361
|
*/
|
|
5110
|
-
constructor(e =
|
|
5362
|
+
constructor(e = k.Second) {
|
|
5111
5363
|
super((t) => this._publisher.publish("tick", t), e);
|
|
5112
5364
|
}
|
|
5113
5365
|
/**
|
|
@@ -5129,7 +5381,7 @@ class ne extends F {
|
|
|
5129
5381
|
*/
|
|
5130
5382
|
start(e = 0) {
|
|
5131
5383
|
if (this._isRunning)
|
|
5132
|
-
throw new
|
|
5384
|
+
throw new b("The clock has already been started.");
|
|
5133
5385
|
this._startTime = performance.now() - e, this._start(), this._isRunning = !0, this._publisher.publish("start");
|
|
5134
5386
|
}
|
|
5135
5387
|
/**
|
|
@@ -5147,9 +5399,9 @@ class ne extends F {
|
|
|
5147
5399
|
*/
|
|
5148
5400
|
stop() {
|
|
5149
5401
|
if (!this._isRunning)
|
|
5150
|
-
throw new
|
|
5402
|
+
throw new b("The clock had already stopped or hadn't yet started.");
|
|
5151
5403
|
if (!this._handle)
|
|
5152
|
-
throw new
|
|
5404
|
+
throw new v();
|
|
5153
5405
|
this._stop(), this._handle = void 0, this._isRunning = !1, this._publisher.publish("stop");
|
|
5154
5406
|
}
|
|
5155
5407
|
/**
|
|
@@ -5178,7 +5430,7 @@ class ne extends F {
|
|
|
5178
5430
|
*/
|
|
5179
5431
|
onTick(e, t = 0) {
|
|
5180
5432
|
if (t < 0)
|
|
5181
|
-
throw new
|
|
5433
|
+
throw new x("The tick step must be a non-negative number.");
|
|
5182
5434
|
if (t === 0)
|
|
5183
5435
|
return this._publisher.subscribe("tick", e);
|
|
5184
5436
|
let n = 0;
|
|
@@ -5188,7 +5440,7 @@ class ne extends F {
|
|
|
5188
5440
|
}
|
|
5189
5441
|
[Symbol.toStringTag] = "Clock";
|
|
5190
5442
|
}
|
|
5191
|
-
class
|
|
5443
|
+
class oe extends C {
|
|
5192
5444
|
/**
|
|
5193
5445
|
* The total duration of the countdown in milliseconds.
|
|
5194
5446
|
*
|
|
@@ -5232,7 +5484,7 @@ class se extends F {
|
|
|
5232
5484
|
* The interval in milliseconds at which the countdown will tick if the environment is not a browser.
|
|
5233
5485
|
* `TimeUnit.Second` by default.
|
|
5234
5486
|
*/
|
|
5235
|
-
constructor(e, t =
|
|
5487
|
+
constructor(e, t = k.Second) {
|
|
5236
5488
|
const n = () => {
|
|
5237
5489
|
const s = this.remainingTime;
|
|
5238
5490
|
s <= 0 ? (this._deferrerStop(), this._publisher.publish("tick", 0), this._publisher.publish("expire")) : this._publisher.publish("tick", s);
|
|
@@ -5253,9 +5505,9 @@ class se extends F {
|
|
|
5253
5505
|
*/
|
|
5254
5506
|
_deferrerStop(e) {
|
|
5255
5507
|
if (!this._isRunning)
|
|
5256
|
-
throw new
|
|
5508
|
+
throw new b("The countdown hadn't yet started.");
|
|
5257
5509
|
if (!this._deferrer)
|
|
5258
|
-
throw new
|
|
5510
|
+
throw new v();
|
|
5259
5511
|
this._stop(), this._handle = void 0, this._isRunning = !1, e !== void 0 ? this._deferrer.reject(e) : this._deferrer.resolve(), this._deferrer = void 0;
|
|
5260
5512
|
}
|
|
5261
5513
|
/**
|
|
@@ -5281,10 +5533,10 @@ class se extends F {
|
|
|
5281
5533
|
*/
|
|
5282
5534
|
start(e = this.duration) {
|
|
5283
5535
|
if (this._isRunning)
|
|
5284
|
-
throw new
|
|
5536
|
+
throw new b("The countdown had already stopped or hadn't yet started.");
|
|
5285
5537
|
if (this._deferrer)
|
|
5286
|
-
throw new
|
|
5287
|
-
return this._deferrer = new
|
|
5538
|
+
throw new v();
|
|
5539
|
+
return this._deferrer = new F(), super.start(this.duration - e), this._publisher.publish("start"), this._deferrer;
|
|
5288
5540
|
}
|
|
5289
5541
|
/**
|
|
5290
5542
|
* Stops the execution of the countdown.
|
|
@@ -5336,7 +5588,7 @@ class se extends F {
|
|
|
5336
5588
|
*/
|
|
5337
5589
|
onTick(e, t = 0) {
|
|
5338
5590
|
if (t < 0)
|
|
5339
|
-
throw new
|
|
5591
|
+
throw new x("The tick step must be a non-negative number.");
|
|
5340
5592
|
if (t === 0)
|
|
5341
5593
|
return this._publisher.subscribe("tick", e);
|
|
5342
5594
|
let n = this.remainingTime;
|
|
@@ -5366,7 +5618,7 @@ class se extends F {
|
|
|
5366
5618
|
}
|
|
5367
5619
|
[Symbol.toStringTag] = "Countdown";
|
|
5368
5620
|
}
|
|
5369
|
-
class
|
|
5621
|
+
class ae {
|
|
5370
5622
|
/**
|
|
5371
5623
|
* Generates a given number of values following a linear curve.
|
|
5372
5624
|
* The values are equally spaced and normalized between 0 and 1.
|
|
@@ -5424,7 +5676,7 @@ class re {
|
|
|
5424
5676
|
*/
|
|
5425
5677
|
static Exponential(e, t = 2) {
|
|
5426
5678
|
if (t < 0)
|
|
5427
|
-
throw new
|
|
5679
|
+
throw new c("The base of the exponential curve cannot be negative.");
|
|
5428
5680
|
const n = e - 1;
|
|
5429
5681
|
return new l(function* () {
|
|
5430
5682
|
for (let s = 0; s < e; s += 1)
|
|
@@ -5435,7 +5687,7 @@ class re {
|
|
|
5435
5687
|
}
|
|
5436
5688
|
[Symbol.toStringTag] = "Curve";
|
|
5437
5689
|
}
|
|
5438
|
-
class
|
|
5690
|
+
class P {
|
|
5439
5691
|
/**
|
|
5440
5692
|
* Generates a random boolean value.
|
|
5441
5693
|
*
|
|
@@ -5483,7 +5735,7 @@ class C {
|
|
|
5483
5735
|
*/
|
|
5484
5736
|
static Index(e) {
|
|
5485
5737
|
if (e.length === 0)
|
|
5486
|
-
throw new
|
|
5738
|
+
throw new c("You must provide at least one element.");
|
|
5487
5739
|
return this.Integer(e.length);
|
|
5488
5740
|
}
|
|
5489
5741
|
/**
|
|
@@ -5501,35 +5753,99 @@ class C {
|
|
|
5501
5753
|
* @returns A random element from the given array.
|
|
5502
5754
|
*/
|
|
5503
5755
|
static Choice(e) {
|
|
5504
|
-
return e[
|
|
5756
|
+
return e[P.Index(e)];
|
|
5757
|
+
}
|
|
5758
|
+
static Sample(e, t, n) {
|
|
5759
|
+
const s = e.length;
|
|
5760
|
+
if (s === 0)
|
|
5761
|
+
throw new c("You must provide at least one element.");
|
|
5762
|
+
if (t < 0)
|
|
5763
|
+
throw new c("Count must be non-negative.");
|
|
5764
|
+
if (t > s)
|
|
5765
|
+
throw new c("Count cannot exceed the number of elements.");
|
|
5766
|
+
if (t === 0)
|
|
5767
|
+
return [];
|
|
5768
|
+
if (n === void 0) {
|
|
5769
|
+
const a = Array.from(e), u = new Array(t);
|
|
5770
|
+
for (let p = 0; p < t; p += 1) {
|
|
5771
|
+
const T = this.Integer(p, s);
|
|
5772
|
+
u[p] = a[T], a[T] = a[p];
|
|
5773
|
+
}
|
|
5774
|
+
return u;
|
|
5775
|
+
}
|
|
5776
|
+
if (n.length !== s)
|
|
5777
|
+
throw new c("Weights array must have the same length as elements array.");
|
|
5778
|
+
const r = new Array(s);
|
|
5779
|
+
for (let a = 0; a < s; a += 1) {
|
|
5780
|
+
if (n[a] <= 0)
|
|
5781
|
+
throw new c(`Weight for element #${a} must be greater than zero.`);
|
|
5782
|
+
r[a] = { index: a, key: Math.pow(Math.random(), 1 / n[a]) };
|
|
5783
|
+
}
|
|
5784
|
+
r.sort((a, u) => u.key - a.key);
|
|
5785
|
+
const o = new Array(t);
|
|
5786
|
+
for (let a = 0; a < t; a += 1)
|
|
5787
|
+
o[a] = e[r[a].index];
|
|
5788
|
+
return o;
|
|
5789
|
+
}
|
|
5790
|
+
static #e(e, t) {
|
|
5791
|
+
const n = new Array(t - 1);
|
|
5792
|
+
for (let a = 0; a < n.length; a += 1)
|
|
5793
|
+
n[a] = Math.random() * e;
|
|
5794
|
+
n.sort((a, u) => a - u);
|
|
5795
|
+
const s = [0, ...n, e], r = new Array(t);
|
|
5796
|
+
for (let a = 0; a < t; a += 1)
|
|
5797
|
+
r[a] = Math.floor(s[a + 1] - s[a]);
|
|
5798
|
+
let o = e - r.reduce((a, u) => a + u, 0);
|
|
5799
|
+
for (; o > 0; )
|
|
5800
|
+
r[this.Integer(t)] += 1, o -= 1;
|
|
5801
|
+
return r;
|
|
5802
|
+
}
|
|
5803
|
+
static Split(e, t) {
|
|
5804
|
+
if (t < 1)
|
|
5805
|
+
throw new c("The number of splits must be greater than zero.");
|
|
5806
|
+
if (typeof e == "number") {
|
|
5807
|
+
if (e < 0)
|
|
5808
|
+
throw new c("The total must be a non-negative number.");
|
|
5809
|
+
return this.#e(e, t);
|
|
5810
|
+
}
|
|
5811
|
+
const n = Array.from(e), s = n.length;
|
|
5812
|
+
if (s === 0)
|
|
5813
|
+
throw new c("You must provide at least one element.");
|
|
5814
|
+
if (t > s)
|
|
5815
|
+
throw new c("The number of splits cannot exceed the number of elements.");
|
|
5816
|
+
const r = this.#e(s, t), o = new Array(t);
|
|
5817
|
+
let a = 0;
|
|
5818
|
+
for (let u = 0; u < t; u += 1)
|
|
5819
|
+
o[u] = n.slice(a, a + r[u]), a += r[u];
|
|
5820
|
+
return o;
|
|
5505
5821
|
}
|
|
5506
5822
|
constructor() {
|
|
5507
5823
|
}
|
|
5508
5824
|
[Symbol.toStringTag] = "Random";
|
|
5509
5825
|
}
|
|
5510
|
-
function
|
|
5511
|
-
return new
|
|
5826
|
+
function le(i) {
|
|
5827
|
+
return new w((e) => setTimeout(e, i));
|
|
5512
5828
|
}
|
|
5513
|
-
function
|
|
5514
|
-
return new
|
|
5829
|
+
function ue() {
|
|
5830
|
+
return new w((i) => requestAnimationFrame(() => i()));
|
|
5515
5831
|
}
|
|
5516
|
-
function
|
|
5517
|
-
return new
|
|
5832
|
+
function ce() {
|
|
5833
|
+
return new w((i) => setTimeout(i));
|
|
5518
5834
|
}
|
|
5519
|
-
function
|
|
5520
|
-
return new
|
|
5835
|
+
function he(i, e = "text/javascript") {
|
|
5836
|
+
return new w((t, n) => {
|
|
5521
5837
|
const s = document.createElement("script");
|
|
5522
5838
|
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);
|
|
5523
5839
|
});
|
|
5524
5840
|
}
|
|
5525
|
-
function
|
|
5841
|
+
function fe(...i) {
|
|
5526
5842
|
return new l(function* () {
|
|
5527
5843
|
for (const e of i)
|
|
5528
5844
|
for (const t of e)
|
|
5529
5845
|
yield t;
|
|
5530
5846
|
});
|
|
5531
5847
|
}
|
|
5532
|
-
function
|
|
5848
|
+
function de(i) {
|
|
5533
5849
|
if (i instanceof Array)
|
|
5534
5850
|
return i.length;
|
|
5535
5851
|
let e = 0;
|
|
@@ -5537,16 +5853,16 @@ function ce(i) {
|
|
|
5537
5853
|
e += 1;
|
|
5538
5854
|
return e;
|
|
5539
5855
|
}
|
|
5540
|
-
function
|
|
5856
|
+
function me(i) {
|
|
5541
5857
|
return new l(function* () {
|
|
5542
5858
|
let e = 0;
|
|
5543
5859
|
for (const t of i)
|
|
5544
5860
|
yield [e, t], e += 1;
|
|
5545
5861
|
});
|
|
5546
5862
|
}
|
|
5547
|
-
function
|
|
5863
|
+
function we(i, e, t = 1) {
|
|
5548
5864
|
if (t <= 0)
|
|
5549
|
-
throw new
|
|
5865
|
+
throw new x(
|
|
5550
5866
|
"Step must be always a positive number, even when generating numbers in reverse order."
|
|
5551
5867
|
);
|
|
5552
5868
|
return e === void 0 && (e = i, i = 0), i > e ? new l(function* () {
|
|
@@ -5557,7 +5873,7 @@ function fe(i, e, t = 1) {
|
|
|
5557
5873
|
yield n;
|
|
5558
5874
|
});
|
|
5559
5875
|
}
|
|
5560
|
-
function
|
|
5876
|
+
function pe(i) {
|
|
5561
5877
|
const e = Array.from(i);
|
|
5562
5878
|
for (let t = e.length - 1; t > 0; t -= 1) {
|
|
5563
5879
|
const n = Math.floor(Math.random() * (t + 1));
|
|
@@ -5565,14 +5881,14 @@ function de(i) {
|
|
|
5565
5881
|
}
|
|
5566
5882
|
return e;
|
|
5567
5883
|
}
|
|
5568
|
-
function
|
|
5884
|
+
function _e(i) {
|
|
5569
5885
|
return new l(function* () {
|
|
5570
5886
|
const e = /* @__PURE__ */ new Set();
|
|
5571
5887
|
for (const t of i)
|
|
5572
5888
|
e.has(t) || (e.add(t), yield t);
|
|
5573
5889
|
});
|
|
5574
5890
|
}
|
|
5575
|
-
function
|
|
5891
|
+
function Y(i, e) {
|
|
5576
5892
|
const t = i[Symbol.iterator](), n = e[Symbol.iterator]();
|
|
5577
5893
|
return new l(function* () {
|
|
5578
5894
|
for (; ; ) {
|
|
@@ -5583,28 +5899,28 @@ function A(i, e) {
|
|
|
5583
5899
|
}
|
|
5584
5900
|
});
|
|
5585
5901
|
}
|
|
5586
|
-
function
|
|
5902
|
+
function be(i, e) {
|
|
5587
5903
|
if (e === void 0) {
|
|
5588
5904
|
let r = 0, o = 0;
|
|
5589
5905
|
for (const a of i)
|
|
5590
5906
|
r += a, o += 1;
|
|
5591
5907
|
if (o === 0)
|
|
5592
|
-
throw new
|
|
5908
|
+
throw new c("You must provide at least one value.");
|
|
5593
5909
|
return r / o;
|
|
5594
5910
|
}
|
|
5595
5911
|
let t = 0, n = 0, s = 0;
|
|
5596
|
-
for (const [r, o] of
|
|
5912
|
+
for (const [r, o] of Y(i, e)) {
|
|
5597
5913
|
if (o <= 0)
|
|
5598
|
-
throw new
|
|
5914
|
+
throw new c(`The weight for the value #${s} must be greater than zero.`);
|
|
5599
5915
|
t += r * o, n += o, s += 1;
|
|
5600
5916
|
}
|
|
5601
5917
|
if (s === 0)
|
|
5602
|
-
throw new
|
|
5918
|
+
throw new c("You must provide at least one value and weight.");
|
|
5603
5919
|
if (n <= 0)
|
|
5604
|
-
throw new
|
|
5920
|
+
throw new c("The sum of weights must be greater than zero.");
|
|
5605
5921
|
return t / n;
|
|
5606
5922
|
}
|
|
5607
|
-
function
|
|
5923
|
+
function ye(i) {
|
|
5608
5924
|
let e = 0;
|
|
5609
5925
|
for (let t = 0; t < i.length; t += 1) {
|
|
5610
5926
|
const n = i.charCodeAt(t);
|
|
@@ -5612,78 +5928,80 @@ function _e(i) {
|
|
|
5612
5928
|
}
|
|
5613
5929
|
return e;
|
|
5614
5930
|
}
|
|
5615
|
-
function
|
|
5931
|
+
function xe(i) {
|
|
5616
5932
|
let e = 0;
|
|
5617
5933
|
for (const t of i)
|
|
5618
5934
|
e += t;
|
|
5619
5935
|
return e;
|
|
5620
5936
|
}
|
|
5621
|
-
function
|
|
5937
|
+
function ge(i) {
|
|
5622
5938
|
return `${i.charAt(0).toUpperCase()}${i.slice(1)}`;
|
|
5623
5939
|
}
|
|
5624
|
-
const
|
|
5940
|
+
const ve = "2.2.4";
|
|
5625
5941
|
export {
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
|
|
5942
|
+
_ as AggregatedAsyncIterator,
|
|
5943
|
+
d as AggregatedIterator,
|
|
5944
|
+
Z as ArrayView,
|
|
5945
|
+
R as CallableObject,
|
|
5946
|
+
H as CallbackChain,
|
|
5947
|
+
ie as Clock,
|
|
5948
|
+
oe as Countdown,
|
|
5949
|
+
ae as Curve,
|
|
5950
|
+
F as DeferredPromise,
|
|
5951
|
+
z as EnvironmentException,
|
|
5952
|
+
f as Exception,
|
|
5953
|
+
v as FatalErrorException,
|
|
5954
|
+
M as FileException,
|
|
5638
5955
|
J as FileExistsException,
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5956
|
+
L as FileNotFoundException,
|
|
5957
|
+
C as GameLoop,
|
|
5958
|
+
ee as JSONStorage,
|
|
5959
|
+
y as KeyException,
|
|
5960
|
+
W as MapView,
|
|
5961
|
+
A as NetworkException,
|
|
5962
|
+
j as NotImplementedException,
|
|
5963
|
+
K as PermissionException,
|
|
5964
|
+
te as PromiseQueue,
|
|
5648
5965
|
g as Publisher,
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5966
|
+
P as Random,
|
|
5967
|
+
x as RangeException,
|
|
5968
|
+
h as ReducedIterator,
|
|
5969
|
+
S as ReferenceException,
|
|
5970
|
+
G as ResponseException,
|
|
5971
|
+
b as RuntimeException,
|
|
5972
|
+
U as SetView,
|
|
5973
|
+
m as SmartAsyncIterator,
|
|
5656
5974
|
l as SmartIterator,
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5975
|
+
w as SmartPromise,
|
|
5976
|
+
X as SwitchableCallback,
|
|
5977
|
+
k as TimeUnit,
|
|
5978
|
+
O as TimedPromise,
|
|
5979
|
+
N as TimeoutException,
|
|
5980
|
+
Q as TypeException,
|
|
5981
|
+
ve as VERSION,
|
|
5982
|
+
c as ValueException,
|
|
5665
5983
|
$ as WeekDay,
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5984
|
+
be as average,
|
|
5985
|
+
ge as capitalize,
|
|
5986
|
+
fe as chain,
|
|
5987
|
+
de as count,
|
|
5988
|
+
ne as dateDifference,
|
|
5989
|
+
se as dateRange,
|
|
5990
|
+
D as dateRound,
|
|
5991
|
+
le as delay,
|
|
5992
|
+
me as enumerate,
|
|
5993
|
+
re as getWeek,
|
|
5994
|
+
ye as hash,
|
|
5995
|
+
E as isBrowser,
|
|
5996
|
+
B as isNode,
|
|
5997
|
+
V as isWorker,
|
|
5998
|
+
he as loadScript,
|
|
5999
|
+
ue as nextAnimationFrame,
|
|
6000
|
+
we as range,
|
|
6001
|
+
pe as shuffle,
|
|
6002
|
+
xe as sum,
|
|
6003
|
+
_e as unique,
|
|
6004
|
+
ce as yieldToEventLoop,
|
|
6005
|
+
Y as zip
|
|
5688
6006
|
};
|
|
5689
6007
|
//# sourceMappingURL=core.esm.js.map
|