@byloth/core 1.4.1 → 1.5.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -1,32 +1,11 @@
1
- var y = Object.defineProperty;
2
- var g = (s, e, t) => e in s ? y(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var l = (s, e, t) => (g(s, typeof e != "symbol" ? e + "" : e, t), t);
4
- class h extends Error {
5
- static FromUnknown(e) {
6
- if (e instanceof h)
7
- return e;
8
- if (e instanceof Error) {
9
- const t = new h(e.message);
10
- return t.stack = e.stack, t.name = e.name, t;
11
- }
12
- return new h(`${e}`);
13
- }
14
- constructor(e, t, n = "Exception") {
15
- super(e), this.cause = t, this.name = n, t && (t instanceof Error ? this.stack += `
16
-
17
- Caused by ${t.stack}` : this.stack += `
18
-
19
- Caused by ${t}`);
20
- }
21
- get [Symbol.toStringTag]() {
22
- return "Exception";
23
- }
24
- }
1
+ var _ = Object.defineProperty;
2
+ var g = (s, e, t) => e in s ? _(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var o = (s, e, t) => (g(s, typeof e != "symbol" ? e + "" : e, t), t);
25
4
  class u {
26
5
  constructor(e) {
27
- l(this, "_iterator");
28
- l(this, "return");
29
- l(this, "throw");
6
+ o(this, "_iterator");
7
+ o(this, "return");
8
+ o(this, "throw");
30
9
  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));
31
10
  }
32
11
  every(e) {
@@ -137,7 +116,7 @@ class u {
137
116
  }
138
117
  class f {
139
118
  constructor(e) {
140
- l(this, "_elements");
119
+ o(this, "_elements");
141
120
  this._elements = new u(e);
142
121
  }
143
122
  filter(e) {
@@ -184,16 +163,16 @@ class f {
184
163
  return "ReducedIterator";
185
164
  }
186
165
  }
187
- class m {
166
+ class d {
188
167
  constructor(e) {
189
- l(this, "_elements");
168
+ o(this, "_elements");
190
169
  this._elements = new u(e);
191
170
  }
192
171
  every(e) {
193
172
  const t = /* @__PURE__ */ new Map();
194
173
  for (const [n, r] of this._elements) {
195
- const [i, o] = t.get(n) ?? [0, !0];
196
- o && t.set(n, [i + 1, e(n, r, i)]);
174
+ const [i, l] = t.get(n) ?? [0, !0];
175
+ l && t.set(n, [i + 1, e(n, r, i)]);
197
176
  }
198
177
  return new f(function* () {
199
178
  for (const [n, [r, i]] of t)
@@ -203,8 +182,8 @@ class m {
203
182
  some(e) {
204
183
  const t = /* @__PURE__ */ new Map();
205
184
  for (const [n, r] of this._elements) {
206
- const [i, o] = t.get(n) ?? [0, !1];
207
- o || t.set(n, [i + 1, e(n, r, i)]);
185
+ const [i, l] = t.get(n) ?? [0, !1];
186
+ l || t.set(n, [i + 1, e(n, r, i)]);
208
187
  }
209
188
  return new f(function* () {
210
189
  for (const [n, [r, i]] of t)
@@ -213,46 +192,46 @@ class m {
213
192
  }
214
193
  filter(e) {
215
194
  const t = this._elements;
216
- return new m(function* () {
195
+ return new d(function* () {
217
196
  const n = /* @__PURE__ */ new Map();
218
197
  for (const [r, i] of t) {
219
- const o = n.get(r) ?? 0;
220
- n.set(r, o + 1), e(r, i, o) && (yield [r, i]);
198
+ const l = n.get(r) ?? 0;
199
+ n.set(r, l + 1), e(r, i, l) && (yield [r, i]);
221
200
  }
222
201
  });
223
202
  }
224
203
  map(e) {
225
204
  const t = this._elements;
226
- return new m(function* () {
205
+ return new d(function* () {
227
206
  const n = /* @__PURE__ */ new Map();
228
207
  for (const [r, i] of t) {
229
- const o = n.get(r) ?? 0;
230
- n.set(r, o + 1), yield [r, e(r, i, o)];
208
+ const l = n.get(r) ?? 0;
209
+ n.set(r, l + 1), yield [r, e(r, i, l)];
231
210
  }
232
211
  });
233
212
  }
234
213
  reduce(e, t) {
235
214
  const n = /* @__PURE__ */ new Map();
236
215
  for (const [r, i] of this._elements) {
237
- let o, c;
216
+ let l, c;
238
217
  if (n.has(r))
239
- [o, c] = n.get(r), o += 1;
218
+ [l, c] = n.get(r), l += 1;
240
219
  else if (t !== void 0)
241
- o = 0, c = t(r);
220
+ l = 0, c = t(r);
242
221
  else {
243
222
  n.set(r, [0, i]);
244
223
  continue;
245
224
  }
246
- c = e(r, c, i, o), n.set(r, [o, c]);
225
+ c = e(r, c, i, l), n.set(r, [l, c]);
247
226
  }
248
227
  return new f(function* () {
249
- for (const [r, [i, o]] of n)
250
- yield [r, o];
228
+ for (const [r, [i, l]] of n)
229
+ yield [r, l];
251
230
  });
252
231
  }
253
232
  unique() {
254
233
  const e = this._elements;
255
- return new m(function* () {
234
+ return new d(function* () {
256
235
  const t = /* @__PURE__ */ new Map();
257
236
  for (const [n, r] of e) {
258
237
  const i = t.get(n) ?? /* @__PURE__ */ new Set();
@@ -329,32 +308,69 @@ class m {
329
308
  return "AggregatedIterator";
330
309
  }
331
310
  }
332
- class d {
311
+ class m {
333
312
  constructor(e) {
334
- l(this, "_elements");
313
+ o(this, "_elements");
335
314
  this._elements = new u(e);
336
315
  }
337
316
  filter(e) {
338
- return new d(this._elements.filter(e));
317
+ return new m(this._elements.filter(e));
339
318
  }
340
319
  map(e) {
341
- return new d(this._elements.map(e));
320
+ return new m(this._elements.map(e));
342
321
  }
343
322
  unique() {
344
- return new d(this._elements.unique());
323
+ return new m(this._elements.unique());
345
324
  }
346
325
  groupBy(e) {
347
- return new m(this._elements.map((t, n) => [e(t, n), t]));
326
+ return new d(this._elements.map((t, n) => [e(t, n), t]));
348
327
  }
349
328
  get [Symbol.toStringTag]() {
350
329
  return "Aggregator";
351
330
  }
352
331
  }
353
- class x {
332
+ class h extends Error {
333
+ static FromUnknown(e) {
334
+ if (e instanceof h)
335
+ return e;
336
+ if (e instanceof Error) {
337
+ const t = new h(e.message);
338
+ return t.stack = e.stack, t.name = e.name, t;
339
+ }
340
+ return new h(`${e}`);
341
+ }
342
+ constructor(e, t, n = "Exception") {
343
+ super(e), this.cause = t, this.name = n, t && (t instanceof Error ? this.stack += `
344
+
345
+ Caused by ${t.stack}` : this.stack += `
346
+
347
+ Caused by ${t}`);
348
+ }
349
+ get [Symbol.toStringTag]() {
350
+ return "Exception";
351
+ }
352
+ }
353
+ class y extends h {
354
+ constructor(e, t, n = "ReferenceException") {
355
+ super(e, t, n);
356
+ }
357
+ get [Symbol.toStringTag]() {
358
+ return "ReferenceException";
359
+ }
360
+ }
361
+ class w extends h {
362
+ constructor(e, t, n = "TimeoutException") {
363
+ super(e, t, n);
364
+ }
365
+ get [Symbol.toStringTag]() {
366
+ return "TimeoutException";
367
+ }
368
+ }
369
+ class b {
354
370
  constructor(e = !0) {
355
- l(this, "_preferPersistence");
356
- l(this, "_volatile");
357
- l(this, "_persistent");
371
+ o(this, "_preferPersistence");
372
+ o(this, "_volatile");
373
+ o(this, "_persistent");
358
374
  this._preferPersistence = e, this._volatile = window.sessionStorage, this._persistent = window.localStorage;
359
375
  }
360
376
  _get(e, t, n) {
@@ -488,9 +504,9 @@ class x {
488
504
  return "JsonStorage";
489
505
  }
490
506
  }
491
- class b {
507
+ class S {
492
508
  constructor() {
493
- l(this, "_subscribers");
509
+ o(this, "_subscribers");
494
510
  this._subscribers = [];
495
511
  }
496
512
  add(e) {
@@ -499,7 +515,7 @@ class b {
499
515
  remove(e) {
500
516
  const t = this._subscribers.indexOf(e);
501
517
  if (t < 0)
502
- throw new h("Unable to remove the requested subscriber. It was not found.");
518
+ throw new y("Unable to remove the requested subscriber. It was not found.");
503
519
  this._subscribers.splice(t, 1);
504
520
  }
505
521
  call(...e) {
@@ -509,23 +525,21 @@ class b {
509
525
  return "Subscribers";
510
526
  }
511
527
  }
512
- class S {
528
+ class P {
513
529
  constructor(e, t) {
514
- l(this, "_isPending");
515
- l(this, "_isFulfilled");
516
- l(this, "_isRejected");
517
- l(this, "_resolve");
518
- l(this, "_reject");
519
- l(this, "_promise");
530
+ o(this, "_isPending");
531
+ o(this, "_isFulfilled");
532
+ o(this, "_isRejected");
533
+ o(this, "_resolve");
534
+ o(this, "_reject");
535
+ o(this, "_promise");
520
536
  this._isPending = !0, this._isFulfilled = !1, this._isRejected = !1;
521
- let n, r;
522
- const i = (a, _) => {
523
- n = a, r = _;
524
- };
525
- let o;
526
- e ? o = (a) => (this._isPending = !1, this._isFulfilled = !0, e(a)) : o = (a) => (this._isPending = !1, this._isFulfilled = !0, a);
527
- let c;
528
- 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;
537
+ let n;
538
+ e ? n = (a) => (this._isPending = !1, this._isFulfilled = !0, e(a)) : n = (a) => (this._isPending = !1, this._isFulfilled = !0, a);
539
+ let r;
540
+ t ? r = (a) => (this._isPending = !1, this._isRejected = !0, t(a)) : r = (a) => (this._isPending = !1, this._isRejected = !0, a);
541
+ const { promise: i, resolve: l, reject: c } = Promise.withResolvers();
542
+ this._promise = i.then(n, r), this._resolve = l, this._reject = c;
529
543
  }
530
544
  get isPending() {
531
545
  return this._isPending;
@@ -560,10 +574,10 @@ class S {
560
574
  }
561
575
  class k {
562
576
  constructor(e) {
563
- l(this, "_isPending");
564
- l(this, "_isFulfilled");
565
- l(this, "_isRejected");
566
- l(this, "_promise");
577
+ o(this, "_isPending");
578
+ o(this, "_isFulfilled");
579
+ o(this, "_isRejected");
580
+ o(this, "_promise");
567
581
  this._isPending = !0, this._isFulfilled = !1, this._isRejected = !1;
568
582
  const t = (r) => (this._isPending = !1, this._isFulfilled = !0, r), n = (r) => (this._isPending = !1, this._isRejected = !0, r);
569
583
  this._promise = new Promise(e).then(t, n);
@@ -590,6 +604,40 @@ class k {
590
604
  return "SmartPromise";
591
605
  }
592
606
  }
607
+ class j {
608
+ constructor(e, t) {
609
+ o(this, "_isPending");
610
+ o(this, "_isFulfilled");
611
+ o(this, "_isRejected");
612
+ o(this, "_promise");
613
+ this._isPending = !0, this._isFulfilled = !1, this._isRejected = !1;
614
+ const n = (c) => (this._isPending = !1, this._isFulfilled = !0, c), r = (c) => (this._isPending = !1, this._isRejected = !0, c), i = new Promise(e), l = new Promise((c, a) => setTimeout(() => {
615
+ a(new w("The operation has timed out."));
616
+ }, t));
617
+ this._promise = Promise.race([i, l]).then(n, r);
618
+ }
619
+ get isPending() {
620
+ return this._isPending;
621
+ }
622
+ get isFulfilled() {
623
+ return this._isFulfilled;
624
+ }
625
+ get isRejected() {
626
+ return this._isRejected;
627
+ }
628
+ then(e, t) {
629
+ return this._promise.then(e, t);
630
+ }
631
+ catch(e) {
632
+ return this._promise.catch(e);
633
+ }
634
+ finally(e) {
635
+ return this._promise.finally(e);
636
+ }
637
+ get [Symbol.toStringTag]() {
638
+ return "TimedPromise";
639
+ }
640
+ }
593
641
  class M {
594
642
  static Boolean(e = 0.5) {
595
643
  return Math.random() < e;
@@ -607,17 +655,17 @@ class M {
607
655
  constructor() {
608
656
  }
609
657
  }
610
- async function P(s) {
658
+ async function R(s) {
611
659
  return new Promise((e, t) => setTimeout(e, s));
612
660
  }
613
- async function j() {
661
+ async function T() {
614
662
  return new Promise((s, e) => requestAnimationFrame(() => s()));
615
663
  }
616
- var w = /* @__PURE__ */ ((s) => (s[s.Second = 1e3] = "Second", s[s.Minute = 6e4] = "Minute", s[s.Hour = 36e5] = "Hour", s[s.Day = 864e5] = "Day", s[s.Week = 6048e5] = "Week", s[s.Month = 2592e6] = "Month", s[s.Year = 31536e6] = "Year", s))(w || {});
617
- function T(s, e, t = 864e5) {
664
+ var p = /* @__PURE__ */ ((s) => (s[s.Second = 1e3] = "Second", s[s.Minute = 6e4] = "Minute", s[s.Hour = 36e5] = "Hour", s[s.Day = 864e5] = "Day", s[s.Week = 6048e5] = "Week", s[s.Month = 2592e6] = "Month", s[s.Year = 31536e6] = "Year", s))(p || {});
665
+ function F(s, e, t = 864e5) {
618
666
  return Math.floor((e.getTime() - s.getTime()) / t);
619
667
  }
620
- function R(s, e, t = 864e5) {
668
+ function I(s, e, t = 864e5) {
621
669
  return new u(function* () {
622
670
  const n = e.getTime();
623
671
  let r = s.getTime();
@@ -625,16 +673,16 @@ function R(s, e, t = 864e5) {
625
673
  yield new Date(r), r += t;
626
674
  });
627
675
  }
628
- function F(s, e = 864e5) {
676
+ function E(s, e = 864e5) {
629
677
  return new Date(Math.floor(s.getTime() / e) * e);
630
678
  }
631
- async function I(s, e = "text/javascript") {
679
+ async function A(s, e = "text/javascript") {
632
680
  return new Promise((t, n) => {
633
681
  const r = document.createElement("script");
634
682
  r.async = !0, r.defer = !0, r.src = s, r.type = e, r.onload = () => t(), r.onerror = () => n(), document.body.appendChild(r);
635
683
  });
636
684
  }
637
- function A(s) {
685
+ function q(s) {
638
686
  if (Array.isArray(s))
639
687
  return s.length;
640
688
  let e = 0;
@@ -642,14 +690,14 @@ function A(s) {
642
690
  e += 1;
643
691
  return e;
644
692
  }
645
- function E(s, e, t = 1) {
693
+ function C(s, e, t = 1) {
646
694
  return new u(function* () {
647
695
  e === void 0 && (e = s, s = 0), s > e && (t = t ?? -1);
648
696
  for (let n = s; n < e; n += t)
649
697
  yield n;
650
698
  });
651
699
  }
652
- function q(s) {
700
+ function O(s) {
653
701
  const e = Array.from(s);
654
702
  for (let t = e.length - 1; t > 0; t -= 1) {
655
703
  const n = Math.floor(Math.random() * (t + 1));
@@ -657,7 +705,7 @@ function q(s) {
657
705
  }
658
706
  return e;
659
707
  }
660
- function C(s) {
708
+ function $(s) {
661
709
  return new u(function* () {
662
710
  const e = /* @__PURE__ */ new Set();
663
711
  for (const t of s)
@@ -675,11 +723,11 @@ function v(s, e) {
675
723
  }
676
724
  });
677
725
  }
678
- function O(s, e) {
726
+ function J(s, e) {
679
727
  if (e === void 0) {
680
728
  let r = 0, i = 0;
681
- for (const o of s)
682
- r += o, i += 1;
729
+ for (const l of s)
730
+ r += l, i += 1;
683
731
  return r / i;
684
732
  }
685
733
  let t = 0, n = 0;
@@ -687,7 +735,7 @@ function O(s, e) {
687
735
  t += r * i, n += i;
688
736
  return t / n;
689
737
  }
690
- function $(s) {
738
+ function V(s) {
691
739
  let e = 0;
692
740
  for (let t = 0; t < s.length; t += 1) {
693
741
  const n = s.charCodeAt(t);
@@ -695,43 +743,46 @@ function $(s) {
695
743
  }
696
744
  return e;
697
745
  }
698
- function J(s) {
746
+ function z(s) {
699
747
  let e = 0;
700
748
  for (const t of s)
701
749
  e += t;
702
750
  return e;
703
751
  }
704
- function V(s) {
752
+ function B(s) {
705
753
  return `${s.charAt(0).toUpperCase()}${s.slice(1)}`;
706
754
  }
707
- const z = "1.4.1";
755
+ const H = "1.5.0-rc.1";
708
756
  export {
709
- m as AggregatedIterator,
710
- d as Aggregator,
711
- w as DateUnit,
712
- S as DeferredPromise,
757
+ d as AggregatedIterator,
758
+ m as Aggregator,
759
+ p as DateUnit,
760
+ P as DeferredPromise,
713
761
  h as Exception,
714
- x as JsonStorage,
762
+ b as JsonStorage,
715
763
  M as Random,
716
764
  f as ReducedIterator,
765
+ y as ReferenceException,
717
766
  u as SmartIterator,
718
767
  k as SmartPromise,
719
- b as Subscribers,
720
- z as VERSION,
721
- O as average,
722
- V as capitalize,
723
- A as count,
724
- T as dateDifference,
725
- R as dateRange,
726
- F as dateRound,
727
- P as delay,
728
- $ as hash,
729
- I as loadScript,
730
- j as nextAnimationFrame,
731
- E as range,
732
- q as shuffle,
733
- J as sum,
734
- C as unique,
768
+ S as Subscribers,
769
+ j as TimedPromise,
770
+ w as TimeoutException,
771
+ H as VERSION,
772
+ J as average,
773
+ B as capitalize,
774
+ q as count,
775
+ F as dateDifference,
776
+ I as dateRange,
777
+ E as dateRound,
778
+ R as delay,
779
+ V as hash,
780
+ A as loadScript,
781
+ T as nextAnimationFrame,
782
+ C as range,
783
+ O as shuffle,
784
+ z as sum,
785
+ $ as unique,
735
786
  v as zip
736
787
  };
737
788
  //# sourceMappingURL=core.js.map