@byloth/core 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -1,38 +1,38 @@
1
1
  var w = Object.defineProperty;
2
2
  var y = (s, e, t) => e in s ? w(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var u = (s, e, t) => (y(s, typeof e != "symbol" ? e + "" : e, t), t);
4
- class f extends Error {
3
+ var l = (s, e, t) => (y(s, typeof e != "symbol" ? e + "" : e, t), t);
4
+ class h extends Error {
5
5
  static FromUnknown(e) {
6
- if (e instanceof f)
6
+ if (e instanceof h)
7
7
  return e;
8
8
  if (e instanceof Error) {
9
- const t = new f(e.message);
9
+ const t = new h(e.message);
10
10
  return t.stack = e.stack, t.name = e.name, t;
11
11
  }
12
- return new f(`${e}`);
12
+ return new h(`${e}`);
13
13
  }
14
- constructor(e, t, r = "Exception") {
15
- super(e), this.cause = t, this.name = r, t && (t instanceof Error ? this.stack += `
14
+ constructor(e, t, n = "Exception") {
15
+ super(e), this.cause = t, this.name = n, t && (t instanceof Error ? this.stack += `
16
16
 
17
17
  Caused by ${t.stack}` : this.stack += `
18
18
 
19
19
  Caused by ${t}`);
20
20
  }
21
21
  }
22
- class l {
22
+ class u {
23
23
  constructor(e) {
24
- u(this, "_iterator");
25
- u(this, "return");
26
- u(this, "throw");
24
+ l(this, "_iterator");
25
+ l(this, "return");
26
+ l(this, "throw");
27
27
  e instanceof Function ? this._iterator = e() : Symbol.iterator in e ? this._iterator = e[Symbol.iterator]() : this._iterator = e, this._iterator.return && (this.return = (t) => this._iterator.return(t)), this._iterator.throw && (this.throw = (t) => this._iterator.throw(t));
28
28
  }
29
29
  every(e) {
30
30
  let t = 0;
31
31
  for (; ; ) {
32
- const r = this._iterator.next();
33
- if (r.done)
32
+ const n = this._iterator.next();
33
+ if (n.done)
34
34
  return !0;
35
- if (!e(r.value, t))
35
+ if (!e(n.value, t))
36
36
  return !1;
37
37
  t += 1;
38
38
  }
@@ -40,51 +40,51 @@ class l {
40
40
  some(e) {
41
41
  let t = 0;
42
42
  for (; ; ) {
43
- const r = this._iterator.next();
44
- if (r.done)
43
+ const n = this._iterator.next();
44
+ if (n.done)
45
45
  return !1;
46
- if (e(r.value, t))
46
+ if (e(n.value, t))
47
47
  return !0;
48
48
  t += 1;
49
49
  }
50
50
  }
51
51
  filter(e) {
52
52
  const t = this._iterator;
53
- return new l(function* () {
54
- let r = 0;
53
+ return new u(function* () {
54
+ let n = 0;
55
55
  for (; ; ) {
56
- const n = t.next();
57
- if (n.done)
58
- return n.value;
59
- e(n.value, r) && (yield n.value), r += 1;
56
+ const r = t.next();
57
+ if (r.done)
58
+ return r.value;
59
+ e(r.value, n) && (yield r.value), n += 1;
60
60
  }
61
61
  });
62
62
  }
63
63
  map(e) {
64
64
  const t = this._iterator;
65
- return new l(function* () {
66
- let r = 0;
65
+ return new u(function* () {
66
+ let n = 0;
67
67
  for (; ; ) {
68
- const n = t.next();
69
- if (n.done)
70
- return n.value;
71
- yield e(n.value, r), r += 1;
68
+ const r = t.next();
69
+ if (r.done)
70
+ return r.value;
71
+ yield e(r.value, n), n += 1;
72
72
  }
73
73
  });
74
74
  }
75
75
  reduce(e, t) {
76
- let r = 0, n = t;
77
- if (n === void 0) {
76
+ let n = 0, r = t;
77
+ if (r === void 0) {
78
78
  const i = this._iterator.next();
79
79
  if (i.done)
80
80
  throw new TypeError("Reduce of empty iterator with no initial value");
81
- n = i.value, r += 1;
81
+ r = i.value, n += 1;
82
82
  }
83
83
  for (; ; ) {
84
84
  const i = this._iterator.next();
85
85
  if (i.done)
86
- return n;
87
- n = e(n, i.value, r), r += 1;
86
+ return r;
87
+ r = e(r, i.value, n), n += 1;
88
88
  }
89
89
  }
90
90
  enumerate() {
@@ -92,13 +92,13 @@ class l {
92
92
  }
93
93
  unique() {
94
94
  const e = this._iterator;
95
- return new l(function* () {
95
+ return new u(function* () {
96
96
  const t = /* @__PURE__ */ new Set();
97
97
  for (; ; ) {
98
- const r = e.next();
99
- if (r.done)
100
- return r.value;
101
- t.has(r.value) || (t.add(r.value), yield r.value);
98
+ const n = e.next();
99
+ if (n.done)
100
+ return n.value;
101
+ t.has(n.value) || (t.add(n.value), yield n.value);
102
102
  }
103
103
  });
104
104
  }
@@ -113,10 +113,10 @@ class l {
113
113
  forEach(e) {
114
114
  let t = 0;
115
115
  for (; ; ) {
116
- const r = this._iterator.next();
117
- if (r.done)
116
+ const n = this._iterator.next();
117
+ if (n.done)
118
118
  return;
119
- e(r.value, t), t += 1;
119
+ e(n.value, t), t += 1;
120
120
  }
121
121
  }
122
122
  next(...e) {
@@ -129,23 +129,23 @@ class l {
129
129
  return this;
130
130
  }
131
131
  }
132
- class h {
132
+ class f {
133
133
  constructor(e) {
134
- u(this, "_elements");
135
- this._elements = new l(e);
134
+ l(this, "_elements");
135
+ this._elements = new u(e);
136
136
  }
137
137
  filter(e) {
138
138
  const t = this._elements;
139
- return new h(function* () {
140
- for (const [r, [n, i]] of t.enumerate())
141
- e(n, i, r) && (yield [n, i]);
139
+ return new f(function* () {
140
+ for (const [n, [r, i]] of t.enumerate())
141
+ e(r, i, n) && (yield [r, i]);
142
142
  });
143
143
  }
144
144
  map(e) {
145
145
  const t = this._elements;
146
- return new h(function* () {
147
- for (const [r, [n, i]] of t.enumerate())
148
- yield [n, e(n, i, r)];
146
+ return new f(function* () {
147
+ for (const [n, [r, i]] of t.enumerate())
148
+ yield [r, e(r, i, n)];
149
149
  });
150
150
  }
151
151
  toArray() {
@@ -160,89 +160,107 @@ class h {
160
160
  }
161
161
  class d {
162
162
  constructor(e) {
163
- u(this, "_elements");
164
- this._elements = new l(e);
163
+ l(this, "_elements");
164
+ this._elements = new u(e);
165
165
  }
166
166
  every(e) {
167
167
  const t = /* @__PURE__ */ new Map();
168
- for (const [r, n] of this._elements) {
169
- const [i, o] = t.get(r) ?? [0, !0];
170
- o && t.set(r, [i + 1, e(r, n, i)]);
168
+ for (const [n, r] of this._elements) {
169
+ const [i, o] = t.get(n) ?? [0, !0];
170
+ o && t.set(n, [i + 1, e(n, r, i)]);
171
171
  }
172
- return new h(function* () {
173
- for (const [r, [n, i]] of t)
174
- yield [r, i];
172
+ return new f(function* () {
173
+ for (const [n, [r, i]] of t)
174
+ yield [n, i];
175
175
  });
176
176
  }
177
177
  some(e) {
178
178
  const t = /* @__PURE__ */ new Map();
179
- for (const [r, n] of this._elements) {
180
- const [i, o] = t.get(r) ?? [0, !1];
181
- o || t.set(r, [i + 1, e(r, n, i)]);
179
+ for (const [n, r] of this._elements) {
180
+ const [i, o] = t.get(n) ?? [0, !1];
181
+ o || t.set(n, [i + 1, e(n, r, i)]);
182
182
  }
183
- return new h(function* () {
184
- for (const [r, [n, i]] of t)
185
- yield [r, i];
183
+ return new f(function* () {
184
+ for (const [n, [r, i]] of t)
185
+ yield [n, i];
186
186
  });
187
187
  }
188
188
  filter(e) {
189
189
  const t = this._elements;
190
190
  return new d(function* () {
191
- const r = /* @__PURE__ */ new Map();
192
- for (const [n, i] of t) {
193
- const o = r.get(n) ?? 0;
194
- r.set(n, o + 1), e(n, i, o) && (yield [n, i]);
191
+ const n = /* @__PURE__ */ new Map();
192
+ for (const [r, i] of t) {
193
+ const o = n.get(r) ?? 0;
194
+ n.set(r, o + 1), e(r, i, o) && (yield [r, i]);
195
195
  }
196
196
  });
197
197
  }
198
198
  map(e) {
199
199
  const t = this._elements;
200
200
  return new d(function* () {
201
- const r = /* @__PURE__ */ new Map();
202
- for (const [n, i] of t) {
203
- const o = r.get(n) ?? 0;
204
- r.set(n, o + 1), yield [n, e(n, i, o)];
201
+ const n = /* @__PURE__ */ new Map();
202
+ for (const [r, i] of t) {
203
+ const o = n.get(r) ?? 0;
204
+ n.set(r, o + 1), yield [r, e(r, i, o)];
205
205
  }
206
206
  });
207
207
  }
208
208
  reduce(e, t) {
209
- const r = /* @__PURE__ */ new Map();
210
- for (const [n, i] of this._elements) {
209
+ const n = /* @__PURE__ */ new Map();
210
+ for (const [r, i] of this._elements) {
211
211
  let o, c;
212
- if (r.has(n))
213
- [o, c] = r.get(n), o += 1;
212
+ if (n.has(r))
213
+ [o, c] = n.get(r), o += 1;
214
214
  else if (t !== void 0)
215
215
  o = 0, c = t;
216
216
  else {
217
- r.set(n, [0, i]);
217
+ n.set(r, [0, i]);
218
218
  continue;
219
219
  }
220
- c = e(n, c, i, o), r.set(n, [o, c]);
220
+ c = e(r, c, i, o), n.set(r, [o, c]);
221
221
  }
222
- return new h(function* () {
223
- for (const [n, [i, o]] of r)
224
- yield [n, o];
222
+ return new f(function* () {
223
+ for (const [r, [i, o]] of n)
224
+ yield [r, o];
225
225
  });
226
226
  }
227
227
  unique() {
228
228
  const e = this._elements;
229
229
  return new d(function* () {
230
230
  const t = /* @__PURE__ */ new Map();
231
- for (const [r, n] of e) {
232
- const i = t.get(r) ?? /* @__PURE__ */ new Set();
233
- i.has(n) || (i.add(n), t.set(r, i), yield [r, n]);
231
+ for (const [n, r] of e) {
232
+ const i = t.get(n) ?? /* @__PURE__ */ new Set();
233
+ i.has(r) || (i.add(r), t.set(n, i), yield [n, r]);
234
234
  }
235
235
  });
236
236
  }
237
237
  count() {
238
238
  const e = /* @__PURE__ */ new Map();
239
239
  for (const [t] of this._elements) {
240
- const r = e.get(t) ?? 0;
241
- e.set(t, r + 1);
240
+ const n = e.get(t) ?? 0;
241
+ e.set(t, n + 1);
242
242
  }
243
- return new h(function* () {
244
- for (const [t, r] of e)
245
- yield [t, r];
243
+ return new f(function* () {
244
+ for (const [t, n] of e)
245
+ yield [t, n];
246
+ });
247
+ }
248
+ first() {
249
+ const e = /* @__PURE__ */ new Map();
250
+ for (const [t, n] of this._elements)
251
+ e.has(t) || e.set(t, n);
252
+ return new f(function* () {
253
+ for (const [t, n] of e)
254
+ yield [t, n];
255
+ });
256
+ }
257
+ last() {
258
+ const e = /* @__PURE__ */ new Map();
259
+ for (const [t, n] of this._elements)
260
+ e.set(t, n);
261
+ return new f(function* () {
262
+ for (const [t, n] of e)
263
+ yield [t, n];
246
264
  });
247
265
  }
248
266
  toArray() {
@@ -250,25 +268,25 @@ class d {
250
268
  }
251
269
  toMap() {
252
270
  const e = /* @__PURE__ */ new Map();
253
- for (const [t, r] of this._elements) {
254
- const n = e.get(t) ?? [];
255
- n.push(r), e.set(t, n);
271
+ for (const [t, n] of this._elements) {
272
+ const r = e.get(t) ?? [];
273
+ r.push(n), e.set(t, r);
256
274
  }
257
275
  return e;
258
276
  }
259
277
  toObject() {
260
278
  const e = {};
261
- for (const [t, r] of this._elements) {
262
- const n = e[t] ?? [];
263
- n.push(r), e[t] = n;
279
+ for (const [t, n] of this._elements) {
280
+ const r = e[t] ?? [];
281
+ r.push(n), e[t] = r;
264
282
  }
265
283
  return e;
266
284
  }
267
285
  }
268
286
  class _ {
269
287
  constructor(e) {
270
- u(this, "_elements");
271
- this._elements = new l(e);
288
+ l(this, "_elements");
289
+ this._elements = new u(e);
272
290
  }
273
291
  filter(e) {
274
292
  return new _(this._elements.filter(e));
@@ -280,35 +298,35 @@ class _ {
280
298
  return new _(this._elements.unique());
281
299
  }
282
300
  byKey(e) {
283
- return new d(this._elements.map((t, r) => [e(t, r), t]));
301
+ return new d(this._elements.map((t, n) => [e(t, n), t]));
284
302
  }
285
303
  }
286
304
  class x {
287
305
  constructor(e = !0) {
288
- u(this, "_preferPersistence");
289
- u(this, "_volatile");
290
- u(this, "_persistent");
306
+ l(this, "_preferPersistence");
307
+ l(this, "_volatile");
308
+ l(this, "_persistent");
291
309
  this._preferPersistence = e, this._volatile = window.sessionStorage, this._persistent = window.localStorage;
292
310
  }
293
- _get(e, t, r) {
294
- const n = e.getItem(t);
295
- if (n)
311
+ _get(e, t, n) {
312
+ const r = e.getItem(t);
313
+ if (r)
296
314
  try {
297
- return JSON.parse(n);
315
+ return JSON.parse(r);
298
316
  } catch {
299
317
  console.warn(
300
- `The "${n}" value for "${t}" property cannot be parsed. Clearing the storage...`
318
+ `The "${r}" value for "${t}" property cannot be parsed. Clearing the storage...`
301
319
  ), e.removeItem(t);
302
320
  }
303
- return r;
321
+ return n;
304
322
  }
305
- _set(e, t, r) {
306
- const n = JSON.stringify(r);
307
- n ? e.setItem(t, n) : e.removeItem(t);
323
+ _set(e, t, n) {
324
+ const r = JSON.stringify(n);
325
+ r ? e.setItem(t, r) : e.removeItem(t);
308
326
  }
309
- get(e, t, r = this._preferPersistence) {
310
- const n = r ? this._persistent : this._volatile;
311
- return this._get(n, e, t);
327
+ get(e, t, n = this._preferPersistence) {
328
+ const r = n ? this._persistent : this._volatile;
329
+ return this._get(r, e, t);
312
330
  }
313
331
  recall(e, t) {
314
332
  return this._get(this._volatile, e, t);
@@ -369,9 +387,9 @@ class x {
369
387
  * @param newValue The new value to set.
370
388
  * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.
371
389
  */
372
- set(e, t, r = this._preferPersistence) {
373
- const n = r ? this._persistent : this._volatile;
374
- this._set(n, e, t);
390
+ set(e, t, n = this._preferPersistence) {
391
+ const r = n ? this._persistent : this._volatile;
392
+ this._set(r, e, t);
375
393
  }
376
394
  /**
377
395
  * Sets the value with the specified name in the volatile `sessionStorage`.
@@ -420,7 +438,7 @@ class x {
420
438
  }
421
439
  class b {
422
440
  constructor() {
423
- u(this, "_subscribers");
441
+ l(this, "_subscribers");
424
442
  this._subscribers = [];
425
443
  }
426
444
  add(e) {
@@ -429,7 +447,7 @@ class b {
429
447
  remove(e) {
430
448
  const t = this._subscribers.indexOf(e);
431
449
  if (t < 0)
432
- throw new f("Unable to remove the requested subscriber. It was not found.");
450
+ throw new h("Unable to remove the requested subscriber. It was not found.");
433
451
  this._subscribers.splice(t, 1);
434
452
  }
435
453
  call(...e) {
@@ -438,21 +456,21 @@ class b {
438
456
  }
439
457
  class k {
440
458
  constructor(e, t) {
441
- u(this, "_isPending");
442
- u(this, "_isFulfilled");
443
- u(this, "_isRejected");
444
- u(this, "_resolve");
445
- u(this, "_reject");
446
- u(this, "_promise");
459
+ l(this, "_isPending");
460
+ l(this, "_isFulfilled");
461
+ l(this, "_isRejected");
462
+ l(this, "_resolve");
463
+ l(this, "_reject");
464
+ l(this, "_promise");
447
465
  this._isPending = !0, this._isFulfilled = !1, this._isRejected = !1;
448
- let r, n;
466
+ let n, r;
449
467
  const i = (a, m) => {
450
- r = a, n = m;
468
+ n = a, r = m;
451
469
  };
452
470
  let o;
453
471
  e ? o = (a) => (this._isPending = !1, this._isFulfilled = !0, e(a)) : o = (a) => (this._isPending = !1, this._isFulfilled = !0, a);
454
472
  let c;
455
- t ? c = (a) => (this._isPending = !1, this._isRejected = !0, t(a)) : c = (a) => (this._isPending = !1, this._isRejected = !0, a), this._promise = new Promise(i).then(o, c), this._resolve = r, this._reject = n;
473
+ t ? c = (a) => (this._isPending = !1, this._isRejected = !0, t(a)) : c = (a) => (this._isPending = !1, this._isRejected = !0, a), this._promise = new Promise(i).then(o, c), this._resolve = n, this._reject = r;
456
474
  }
457
475
  get isPending() {
458
476
  return this._isPending;
@@ -487,13 +505,13 @@ class k {
487
505
  }
488
506
  class M {
489
507
  constructor(e) {
490
- u(this, "_isPending");
491
- u(this, "_isFulfilled");
492
- u(this, "_isRejected");
493
- u(this, "_promise");
508
+ l(this, "_isPending");
509
+ l(this, "_isFulfilled");
510
+ l(this, "_isRejected");
511
+ l(this, "_promise");
494
512
  this._isPending = !0, this._isFulfilled = !1, this._isRejected = !1;
495
- const t = (n) => (this._isPending = !1, this._isFulfilled = !0, n), r = (n) => (this._isPending = !1, this._isRejected = !0, n);
496
- this._promise = new Promise(e).then(t, r);
513
+ const t = (r) => (this._isPending = !1, this._isFulfilled = !0, r), n = (r) => (this._isPending = !1, this._isRejected = !0, r);
514
+ this._promise = new Promise(e).then(t, n);
497
515
  }
498
516
  get isPending() {
499
517
  return this._isPending;
@@ -545,20 +563,20 @@ function R(s, e, t = 864e5) {
545
563
  return Math.floor((e.getTime() - s.getTime()) / t);
546
564
  }
547
565
  function F(s, e, t = 864e5) {
548
- return new l(function* () {
549
- const r = e.getTime();
550
- let n = s.getTime();
551
- for (; n < r; )
552
- yield new Date(n), n += t;
566
+ return new u(function* () {
567
+ const n = e.getTime();
568
+ let r = s.getTime();
569
+ for (; r < n; )
570
+ yield new Date(r), r += t;
553
571
  });
554
572
  }
555
573
  function I(s, e = 864e5) {
556
574
  return new Date(Math.floor(s.getTime() / e) * e);
557
575
  }
558
576
  async function T(s, e = "text/javascript") {
559
- return new Promise((t, r) => {
560
- const n = document.createElement("script");
561
- n.async = !0, n.defer = !0, n.src = s, n.type = e, n.onload = () => t(), n.onerror = () => r(), document.body.appendChild(n);
577
+ return new Promise((t, n) => {
578
+ const r = document.createElement("script");
579
+ r.async = !0, r.defer = !0, r.src = s, r.type = e, r.onload = () => t(), r.onerror = () => n(), document.body.appendChild(r);
562
580
  });
563
581
  }
564
582
  function A(s) {
@@ -570,55 +588,55 @@ function A(s) {
570
588
  return e;
571
589
  }
572
590
  function q(s, e, t = 1) {
573
- return new l(function* () {
591
+ return new u(function* () {
574
592
  e === void 0 && (e = s, s = 0), s > e && (t = t ?? -1);
575
- for (let r = s; r < e; r += t)
576
- yield r;
593
+ for (let n = s; n < e; n += t)
594
+ yield n;
577
595
  });
578
596
  }
579
597
  function C(s) {
580
598
  const e = Array.from(s);
581
599
  for (let t = e.length - 1; t > 0; t -= 1) {
582
- const r = Math.floor(Math.random() * (t + 1));
583
- [e[t], e[r]] = [e[r], e[t]];
600
+ const n = Math.floor(Math.random() * (t + 1));
601
+ [e[t], e[n]] = [e[n], e[t]];
584
602
  }
585
603
  return e;
586
604
  }
587
605
  function E(s) {
588
- return new l(function* () {
606
+ return new u(function* () {
589
607
  const e = /* @__PURE__ */ new Set();
590
608
  for (const t of s)
591
609
  e.has(t) || (e.add(t), yield t);
592
610
  });
593
611
  }
594
612
  function p(s, e) {
595
- return new l(function* () {
596
- const t = s[Symbol.iterator](), r = e[Symbol.iterator]();
613
+ return new u(function* () {
614
+ const t = s[Symbol.iterator](), n = e[Symbol.iterator]();
597
615
  for (; ; ) {
598
- const n = t.next(), i = r.next();
599
- if (n.done || i.done)
616
+ const r = t.next(), i = n.next();
617
+ if (r.done || i.done)
600
618
  break;
601
- yield [n.value, i.value];
619
+ yield [r.value, i.value];
602
620
  }
603
621
  });
604
622
  }
605
623
  function O(s, e) {
606
624
  if (e === void 0) {
607
- let n = 0, i = 0;
625
+ let r = 0, i = 0;
608
626
  for (const o of s)
609
- n += o, i += 1;
610
- return n / i;
627
+ r += o, i += 1;
628
+ return r / i;
611
629
  }
612
- let t = 0, r = 0;
613
- for (const [n, i] of p(s, e))
614
- t += n * i, r += i;
615
- return t / r;
630
+ let t = 0, n = 0;
631
+ for (const [r, i] of p(s, e))
632
+ t += r * i, n += i;
633
+ return t / n;
616
634
  }
617
635
  function $(s) {
618
636
  let e = 0;
619
637
  for (let t = 0; t < s.length; t += 1) {
620
- const r = s.charCodeAt(t);
621
- e = (e << 5) - e + r, e |= 0;
638
+ const n = s.charCodeAt(t);
639
+ e = (e << 5) - e + n, e |= 0;
622
640
  }
623
641
  return e;
624
642
  }
@@ -631,17 +649,17 @@ function J(s) {
631
649
  function V(s) {
632
650
  return `${s.charAt(0).toUpperCase()}${s.slice(1)}`;
633
651
  }
634
- const z = "1.3.1";
652
+ const z = "1.3.3";
635
653
  export {
636
654
  d as AggregatedIterator,
637
655
  _ as Aggregator,
638
656
  v as DateUnit,
639
657
  k as DeferredPromise,
640
- f as Exception,
658
+ h as Exception,
641
659
  x as JsonStorage,
642
660
  P as Random,
643
- h as ReducedIterator,
644
- l as SmartIterator,
661
+ f as ReducedIterator,
662
+ u as SmartIterator,
645
663
  M as SmartPromise,
646
664
  b as Subscribers,
647
665
  z as VERSION,