@byloth/core 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -1,6 +1,6 @@
1
- var d = Object.defineProperty;
2
- var _ = (s, e, t) => e in s ? d(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var u = (s, e, t) => (_(s, typeof e != "symbol" ? e + "" : e, t), t);
1
+ var w = Object.defineProperty;
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 l = (s, e, t) => (y(s, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  class h extends Error {
5
5
  static FromUnknown(e) {
6
6
  if (e instanceof h)
@@ -19,11 +19,11 @@ Caused by ${t.stack}` : this.stack += `
19
19
  Caused by ${t}`);
20
20
  }
21
21
  }
22
- class c {
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) {
@@ -50,7 +50,7 @@ class c {
50
50
  }
51
51
  filter(e) {
52
52
  const t = this._iterator;
53
- return new c(function* () {
53
+ return new u(function* () {
54
54
  let n = 0;
55
55
  for (; ; ) {
56
56
  const r = t.next();
@@ -62,7 +62,7 @@ class c {
62
62
  }
63
63
  map(e) {
64
64
  const t = this._iterator;
65
- return new c(function* () {
65
+ return new u(function* () {
66
66
  let n = 0;
67
67
  for (; ; ) {
68
68
  const r = t.next();
@@ -75,16 +75,16 @@ class c {
75
75
  reduce(e, t) {
76
76
  let n = 0, r = t;
77
77
  if (r === void 0) {
78
- const o = this._iterator.next();
79
- if (o.done)
78
+ const i = this._iterator.next();
79
+ if (i.done)
80
80
  throw new TypeError("Reduce of empty iterator with no initial value");
81
- r = o.value, n += 1;
81
+ r = i.value, n += 1;
82
82
  }
83
83
  for (; ; ) {
84
- const o = this._iterator.next();
85
- if (o.done)
84
+ const i = this._iterator.next();
85
+ if (i.done)
86
86
  return r;
87
- r = e(r, o.value, n), n += 1;
87
+ r = e(r, i.value, n), n += 1;
88
88
  }
89
89
  }
90
90
  enumerate() {
@@ -92,7 +92,7 @@ class c {
92
92
  }
93
93
  unique() {
94
94
  const e = this._iterator;
95
- return new c(function* () {
95
+ return new u(function* () {
96
96
  const t = /* @__PURE__ */ new Set();
97
97
  for (; ; ) {
98
98
  const n = e.next();
@@ -129,23 +129,23 @@ class c {
129
129
  return this;
130
130
  }
131
131
  }
132
- class l {
132
+ class f {
133
133
  constructor(e) {
134
- u(this, "_elements");
135
- this._elements = new c(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 l(function* () {
140
- for (const [n, [r, o]] of t.enumerate())
141
- e(r, o, n) && (yield [r, o]);
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 l(function* () {
147
- for (const [n, [r, o]] of t.enumerate())
148
- yield [r, e(r, o, n)];
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() {
@@ -158,79 +158,79 @@ class l {
158
158
  return Object.fromEntries(this._elements.toArray());
159
159
  }
160
160
  }
161
- class f {
161
+ class d {
162
162
  constructor(e) {
163
- u(this, "_elements");
164
- this._elements = new c(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
168
  for (const [n, r] of this._elements) {
169
- const [o, i] = t.get(n) ?? [0, !0];
170
- i && t.set(n, [o + 1, e(n, r, o)]);
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 l(function* () {
173
- for (const [n, [r, o]] of t)
174
- yield [n, o];
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
179
  for (const [n, r] of this._elements) {
180
- const [o, i] = t.get(n) ?? [0, !1];
181
- i || t.set(n, [o + 1, e(n, r, o)]);
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 l(function* () {
184
- for (const [n, [r, o]] of t)
185
- yield [n, o];
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
- return new f(function* () {
190
+ return new d(function* () {
191
191
  const n = /* @__PURE__ */ new Map();
192
- for (const [r, o] of t) {
193
- const i = n.get(r) ?? 0;
194
- n.set(r, i + 1), e(r, o, i) && (yield [r, o]);
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
- return new f(function* () {
200
+ return new d(function* () {
201
201
  const n = /* @__PURE__ */ new Map();
202
- for (const [r, o] of t) {
203
- const i = n.get(r) ?? 0;
204
- n.set(r, i + 1), yield [r, e(r, o, i)];
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
209
  const n = /* @__PURE__ */ new Map();
210
- for (const [r, o] of this._elements) {
211
- let i, a;
210
+ for (const [r, i] of this._elements) {
211
+ let o, c;
212
212
  if (n.has(r))
213
- [i, a] = n.get(r), i += 1;
213
+ [o, c] = n.get(r), o += 1;
214
214
  else if (t !== void 0)
215
- i = 0, a = t;
215
+ o = 0, c = t;
216
216
  else {
217
- n.set(r, [0, o]);
217
+ n.set(r, [0, i]);
218
218
  continue;
219
219
  }
220
- a = e(r, a, o, i), n.set(r, [i, a]);
220
+ c = e(r, c, i, o), n.set(r, [o, c]);
221
221
  }
222
- return new l(function* () {
223
- for (const [r, [o, i]] of n)
224
- yield [r, i];
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
- return new f(function* () {
229
+ return new d(function* () {
230
230
  const t = /* @__PURE__ */ new Map();
231
231
  for (const [n, r] of e) {
232
- const o = t.get(n) ?? /* @__PURE__ */ new Set();
233
- o.has(r) || (o.add(r), t.set(n, o), yield [n, r]);
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
  }
@@ -240,7 +240,25 @@ class f {
240
240
  const n = e.get(t) ?? 0;
241
241
  e.set(t, n + 1);
242
242
  }
243
- return new l(function* () {
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* () {
244
262
  for (const [t, n] of e)
245
263
  yield [t, n];
246
264
  });
@@ -265,61 +283,29 @@ class f {
265
283
  return e;
266
284
  }
267
285
  }
268
- class m {
286
+ class _ {
269
287
  constructor(e) {
270
- u(this, "_elements");
271
- this._elements = new c(e);
288
+ l(this, "_elements");
289
+ this._elements = new u(e);
272
290
  }
273
291
  filter(e) {
274
- return new m(this._elements.filter(e));
292
+ return new _(this._elements.filter(e));
275
293
  }
276
294
  map(e) {
277
- return new m(this._elements.map(e));
295
+ return new _(this._elements.map(e));
278
296
  }
279
297
  unique() {
280
- return new m(this._elements.unique());
298
+ return new _(this._elements.unique());
281
299
  }
282
300
  byKey(e) {
283
- return new f(this._elements.map((t, n) => [e(t, n), t]));
284
- }
285
- }
286
- class p {
287
- constructor(e, t) {
288
- u(this, "_resolve");
289
- u(this, "_reject");
290
- u(this, "_promise");
291
- let n, r;
292
- this._promise = new Promise((o, i) => {
293
- n = o, r = i;
294
- }).then(e, t), this._resolve = n, this._reject = r;
295
- }
296
- get resolve() {
297
- return this._resolve;
298
- }
299
- get reject() {
300
- return this._reject;
301
- }
302
- then(e, t) {
303
- return this._promise.then(e, t);
304
- }
305
- catch(e) {
306
- return this._promise.catch(e);
307
- }
308
- finally(e) {
309
- return this._promise.finally(e);
310
- }
311
- watch(e) {
312
- return e.then(this.resolve, this.reject), this;
313
- }
314
- get [Symbol.toStringTag]() {
315
- return "DeferredPromise";
301
+ return new d(this._elements.map((t, n) => [e(t, n), t]));
316
302
  }
317
303
  }
318
304
  class x {
319
305
  constructor(e = !0) {
320
- u(this, "_preferPersistence");
321
- u(this, "_volatile");
322
- u(this, "_persistent");
306
+ l(this, "_preferPersistence");
307
+ l(this, "_volatile");
308
+ l(this, "_persistent");
323
309
  this._preferPersistence = e, this._volatile = window.sessionStorage, this._persistent = window.localStorage;
324
310
  }
325
311
  _get(e, t, n) {
@@ -452,7 +438,7 @@ class x {
452
438
  }
453
439
  class b {
454
440
  constructor() {
455
- u(this, "_subscribers");
441
+ l(this, "_subscribers");
456
442
  this._subscribers = [];
457
443
  }
458
444
  add(e) {
@@ -468,7 +454,88 @@ class b {
468
454
  return this._subscribers.slice().map((t) => t(...e));
469
455
  }
470
456
  }
471
- class g {
457
+ class k {
458
+ constructor(e, t) {
459
+ l(this, "_isPending");
460
+ l(this, "_isFulfilled");
461
+ l(this, "_isRejected");
462
+ l(this, "_resolve");
463
+ l(this, "_reject");
464
+ l(this, "_promise");
465
+ this._isPending = !0, this._isFulfilled = !1, this._isRejected = !1;
466
+ let n, r;
467
+ const i = (a, m) => {
468
+ n = a, r = m;
469
+ };
470
+ let o;
471
+ e ? o = (a) => (this._isPending = !1, this._isFulfilled = !0, e(a)) : o = (a) => (this._isPending = !1, this._isFulfilled = !0, a);
472
+ let c;
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;
474
+ }
475
+ get isPending() {
476
+ return this._isPending;
477
+ }
478
+ get isFulfilled() {
479
+ return this._isFulfilled;
480
+ }
481
+ get isRejected() {
482
+ return this._isRejected;
483
+ }
484
+ get resolve() {
485
+ return this._resolve;
486
+ }
487
+ get reject() {
488
+ return this._reject;
489
+ }
490
+ then(e, t) {
491
+ return this._promise.then(e, t);
492
+ }
493
+ catch(e) {
494
+ return this._promise.catch(e);
495
+ }
496
+ finally(e) {
497
+ return this._promise.finally(e);
498
+ }
499
+ watch(e) {
500
+ return e.then(this.resolve, this.reject), this;
501
+ }
502
+ get [Symbol.toStringTag]() {
503
+ return "DeferredPromise";
504
+ }
505
+ }
506
+ class M {
507
+ constructor(e) {
508
+ l(this, "_isPending");
509
+ l(this, "_isFulfilled");
510
+ l(this, "_isRejected");
511
+ l(this, "_promise");
512
+ this._isPending = !0, this._isFulfilled = !1, this._isRejected = !1;
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);
515
+ }
516
+ get isPending() {
517
+ return this._isPending;
518
+ }
519
+ get isFulfilled() {
520
+ return this._isFulfilled;
521
+ }
522
+ get isRejected() {
523
+ return this._isRejected;
524
+ }
525
+ then(e, t) {
526
+ return this._promise.then(e, t);
527
+ }
528
+ catch(e) {
529
+ return this._promise.catch(e);
530
+ }
531
+ finally(e) {
532
+ return this._promise.finally(e);
533
+ }
534
+ get [Symbol.toStringTag]() {
535
+ return "SmartPromise";
536
+ }
537
+ }
538
+ class P {
472
539
  static Boolean(e = 0.5) {
473
540
  return Math.random() < e;
474
541
  }
@@ -485,18 +552,18 @@ class g {
485
552
  constructor() {
486
553
  }
487
554
  }
488
- async function k(s) {
555
+ async function j(s) {
489
556
  return new Promise((e, t) => setTimeout(e, s));
490
557
  }
491
- async function M() {
558
+ async function S() {
492
559
  return new Promise((s, e) => requestAnimationFrame(() => s()));
493
560
  }
494
- 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 || {});
495
- function S(s, e, t = 864e5) {
561
+ var v = /* @__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))(v || {});
562
+ function R(s, e, t = 864e5) {
496
563
  return Math.floor((e.getTime() - s.getTime()) / t);
497
564
  }
498
- function j(s, e, t = 864e5) {
499
- return new c(function* () {
565
+ function F(s, e, t = 864e5) {
566
+ return new u(function* () {
500
567
  const n = e.getTime();
501
568
  let r = s.getTime();
502
569
  for (; r < n; )
@@ -506,13 +573,13 @@ function j(s, e, t = 864e5) {
506
573
  function I(s, e = 864e5) {
507
574
  return new Date(Math.floor(s.getTime() / e) * e);
508
575
  }
509
- async function A(s, e = "text/javascript") {
576
+ async function T(s, e = "text/javascript") {
510
577
  return new Promise((t, n) => {
511
578
  const r = document.createElement("script");
512
579
  r.async = !0, r.defer = !0, r.src = s, r.type = e, r.onload = () => t(), r.onerror = () => n(), document.body.appendChild(r);
513
580
  });
514
581
  }
515
- function T(s) {
582
+ function A(s) {
516
583
  if (Array.isArray(s))
517
584
  return s.length;
518
585
  let e = 0;
@@ -520,14 +587,14 @@ function T(s) {
520
587
  e += 1;
521
588
  return e;
522
589
  }
523
- function P(s, e, t = 1) {
524
- return new c(function* () {
590
+ function q(s, e, t = 1) {
591
+ return new u(function* () {
525
592
  e === void 0 && (e = s, s = 0), s > e && (t = t ?? -1);
526
593
  for (let n = s; n < e; n += t)
527
594
  yield n;
528
595
  });
529
596
  }
530
- function q(s) {
597
+ function C(s) {
531
598
  const e = Array.from(s);
532
599
  for (let t = e.length - 1; t > 0; t -= 1) {
533
600
  const n = Math.floor(Math.random() * (t + 1));
@@ -535,37 +602,37 @@ function q(s) {
535
602
  }
536
603
  return e;
537
604
  }
538
- function C(s) {
539
- return new c(function* () {
605
+ function E(s) {
606
+ return new u(function* () {
540
607
  const e = /* @__PURE__ */ new Set();
541
608
  for (const t of s)
542
609
  e.has(t) || (e.add(t), yield t);
543
610
  });
544
611
  }
545
- function y(s, e) {
546
- return new c(function* () {
612
+ function p(s, e) {
613
+ return new u(function* () {
547
614
  const t = s[Symbol.iterator](), n = e[Symbol.iterator]();
548
615
  for (; ; ) {
549
- const r = t.next(), o = n.next();
550
- if (r.done || o.done)
616
+ const r = t.next(), i = n.next();
617
+ if (r.done || i.done)
551
618
  break;
552
- yield [r.value, o.value];
619
+ yield [r.value, i.value];
553
620
  }
554
621
  });
555
622
  }
556
- function E(s, e) {
623
+ function O(s, e) {
557
624
  if (e === void 0) {
558
- let r = 0, o = 0;
559
- for (const i of s)
560
- r += i, o += 1;
561
- return r / o;
625
+ let r = 0, i = 0;
626
+ for (const o of s)
627
+ r += o, i += 1;
628
+ return r / i;
562
629
  }
563
630
  let t = 0, n = 0;
564
- for (const [r, o] of y(s, e))
565
- t += r * o, n += o;
631
+ for (const [r, i] of p(s, e))
632
+ t += r * i, n += i;
566
633
  return t / n;
567
634
  }
568
- function O(s) {
635
+ function $(s) {
569
636
  let e = 0;
570
637
  for (let t = 0; t < s.length; t += 1) {
571
638
  const n = s.charCodeAt(t);
@@ -573,42 +640,43 @@ function O(s) {
573
640
  }
574
641
  return e;
575
642
  }
576
- function $(s) {
643
+ function J(s) {
577
644
  let e = 0;
578
645
  for (const t of s)
579
646
  e += t;
580
647
  return e;
581
648
  }
582
- function R(s) {
649
+ function V(s) {
583
650
  return `${s.charAt(0).toUpperCase()}${s.slice(1)}`;
584
651
  }
585
- const F = "1.3.0";
652
+ const z = "1.3.2";
586
653
  export {
587
- f as AggregatedIterator,
588
- m as Aggregator,
589
- w as DateUnit,
590
- p as DeferredPromise,
654
+ d as AggregatedIterator,
655
+ _ as Aggregator,
656
+ v as DateUnit,
657
+ k as DeferredPromise,
591
658
  h as Exception,
592
659
  x as JsonStorage,
593
- g as Random,
594
- l as ReducedIterator,
595
- c as SmartIterator,
660
+ P as Random,
661
+ f as ReducedIterator,
662
+ u as SmartIterator,
663
+ M as SmartPromise,
596
664
  b as Subscribers,
597
- F as VERSION,
598
- E as average,
599
- R as capitalize,
600
- T as count,
601
- S as dateDifference,
602
- j as dateRange,
665
+ z as VERSION,
666
+ O as average,
667
+ V as capitalize,
668
+ A as count,
669
+ R as dateDifference,
670
+ F as dateRange,
603
671
  I as dateRound,
604
- k as delay,
605
- O as hash,
606
- A as loadScript,
607
- M as nextAnimationFrame,
608
- P as range,
609
- q as shuffle,
610
- $ as sum,
611
- C as unique,
612
- y as zip
672
+ j as delay,
673
+ $ as hash,
674
+ T as loadScript,
675
+ S as nextAnimationFrame,
676
+ q as range,
677
+ C as shuffle,
678
+ J as sum,
679
+ E as unique,
680
+ p as zip
613
681
  };
614
682
  //# sourceMappingURL=core.js.map