@ztimson/utils 0.21.0 → 0.21.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/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
- var it = Object.defineProperty;
2
- var ct = (r, t, e) => t in r ? it(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var c = (r, t, e) => ct(r, typeof t != "symbol" ? t + "" : t, e);
4
- function ut(r, t = !1) {
1
+ var ot = Object.defineProperty;
2
+ var it = (r, t, e) => t in r ? ot(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var c = (r, t, e) => it(r, typeof t != "symbol" ? t + "" : t, e);
4
+ function ct(r, t = !1) {
5
5
  if (r == null) throw new Error("Cannot clean a NULL value");
6
6
  return Array.isArray(r) ? r = r.filter((e) => e != null) : Object.entries(r).forEach(([e, n]) => {
7
7
  (t && n === void 0 || !t && n == null) && delete r[e];
8
8
  }), r;
9
9
  }
10
- function Rt(r) {
10
+ function At(r) {
11
11
  return structuredClone(r);
12
12
  }
13
13
  function at(r, ...t) {
@@ -16,7 +16,7 @@ function at(r, ...t) {
16
16
  e[n] && typeof e[n] == "object" && !Array.isArray(e[n]) ? (r[n] || (r[n] = {}), at(r[n], e[n])) : r[n] = e[n];
17
17
  }), r;
18
18
  }
19
- function b(r, t, e) {
19
+ function B(r, t, e) {
20
20
  if (!(r == null || !t))
21
21
  return t.split(/[.[\]]/g).filter((n) => n.length).reduce((n, s, o, i) => {
22
22
  if ((s[0] == '"' || s[0] == "'") && (s = s.slice(1, -1)), !(n != null && n.hasOwnProperty(s))) {
@@ -26,21 +26,21 @@ function b(r, t, e) {
26
26
  return e !== void 0 && o == i.length - 1 ? n[s] = e : n[s];
27
27
  }, r);
28
28
  }
29
- function jt(r) {
29
+ function Rt(r) {
30
30
  return Object.entries(r).map(
31
31
  ([t, e]) => encodeURIComponent(t) + "=" + encodeURIComponent(e)
32
32
  ).join("&");
33
33
  }
34
- function H(r, t, e = {}) {
34
+ function K(r, t, e = {}) {
35
35
  if (typeof r == "object" && !Array.isArray(r)) {
36
36
  for (const n of Object.keys(r)) {
37
37
  const s = t ? t + "." + n : n;
38
- typeof r[n] == "object" ? H(r[n], s, e) : e[s] = r[n];
38
+ typeof r[n] == "object" ? K(r[n], s, e) : e[s] = r[n];
39
39
  }
40
40
  return e;
41
41
  }
42
42
  }
43
- function $t(r) {
43
+ function Ot(r) {
44
44
  const t = new FormData();
45
45
  return Object.entries(r).forEach(([e, n]) => t.append(e, n)), t;
46
46
  }
@@ -50,11 +50,11 @@ function q(r, t, e = !1) {
50
50
  const n = typeof t;
51
51
  return n != typeof r ? !1 : n == "object" ? Object.keys(t).find((s) => !q(r[s], t[s], e)) == null : n == "function" ? r.toString() == t.toString() : r == t;
52
52
  }
53
- function A(r, t) {
53
+ function O(r, t) {
54
54
  const e = typeof r, n = typeof t;
55
- return e != "object" || r == null || n != "object" || t == null ? e == "function" && n == "function" ? r.toString() == t.toString() : r === t : Object.keys(r).length != Object.keys(t).length ? !1 : Object.keys(r).every((o) => A(r[o], t[o]));
55
+ return e != "object" || r == null || n != "object" || t == null ? e == "function" && n == "function" ? r.toString() == t.toString() : r === t : Object.keys(r).length != Object.keys(t).length ? !1 : Object.keys(r).every((o) => O(r[o], t[o]));
56
56
  }
57
- function Ct(r, t) {
57
+ function $t(r, t) {
58
58
  t.forEach((e) => {
59
59
  Object.getOwnPropertyNames(e.prototype).forEach((n) => {
60
60
  Object.defineProperty(
@@ -65,14 +65,14 @@ function Ct(r, t) {
65
65
  });
66
66
  });
67
67
  }
68
- function M(r) {
68
+ function I(r) {
69
69
  try {
70
70
  return JSON.parse(r);
71
71
  } catch {
72
72
  return r;
73
73
  }
74
74
  }
75
- function Lt(r, t) {
75
+ function ut(r, t) {
76
76
  let e = [];
77
77
  return JSON.stringify(r, (n, s) => {
78
78
  if (typeof s == "object" && s !== null) {
@@ -82,42 +82,42 @@ function Lt(r, t) {
82
82
  return s;
83
83
  }, t);
84
84
  }
85
- function Nt(r, t) {
85
+ function Ct(r, t) {
86
86
  return r.indexOf(t) === -1 && r.push(t), r;
87
87
  }
88
- function It(r, t) {
88
+ function Lt(r, t) {
89
89
  return ht([
90
- ...r.filter((e) => !t.includes((n) => A(e, n))),
91
- ...t.filter((e) => !r.includes((n) => A(e, n)))
90
+ ...r.filter((e) => !t.includes((n) => O(e, n))),
91
+ ...t.filter((e) => !r.includes((n) => O(e, n)))
92
92
  ]);
93
93
  }
94
- function Mt(r) {
94
+ function Nt(r) {
95
95
  return function(t, e) {
96
- const n = b(t, r), s = b(e, r);
96
+ const n = B(t, r), s = B(e, r);
97
97
  return typeof n != "string" || typeof s != "string" ? 1 : n.toLowerCase().localeCompare(s.toLowerCase());
98
98
  };
99
99
  }
100
- function Tt(r, t) {
101
- return (e) => A(b(e, r), t);
100
+ function jt(r, t) {
101
+ return (e) => O(B(e, r), t);
102
102
  }
103
103
  function lt(r, t = []) {
104
104
  return r.forEach((e) => Array.isArray(e) ? lt(e, t) : t.push(e)), t;
105
105
  }
106
- function kt(r, t = !1) {
106
+ function Tt(r, t = !1) {
107
107
  return function(e, n) {
108
- const s = b(e, r), o = b(n, r);
108
+ const s = B(e, r), o = B(n, r);
109
109
  return typeof s == "number" && typeof o == "number" ? (t ? -1 : 1) * (s - o) : s > o ? t ? -1 : 1 : s < o ? t ? 1 : -1 : 0;
110
110
  };
111
111
  }
112
112
  function ht(r) {
113
113
  for (let t = r.length - 1; t >= 0; t--)
114
- r.slice(0, t).find((e) => A(e, r[t])) && r.splice(t, 1);
114
+ r.slice(0, t).find((e) => O(e, r[t])) && r.splice(t, 1);
115
115
  return r;
116
116
  }
117
- function ft(r) {
117
+ function S(r) {
118
118
  return Array.isArray(r) ? r : [r];
119
119
  }
120
- class B extends Array {
120
+ class w extends Array {
121
121
  /** Number of elements in set */
122
122
  get size() {
123
123
  return this.length;
@@ -130,19 +130,21 @@ class B extends Array {
130
130
  super(), t != null && t.forEach && t.forEach((e) => this.add(e));
131
131
  }
132
132
  /**
133
- * Add single element to set if unique
134
- * @param {T} el Element to add
133
+ * Add elements to set if unique
134
+ * @param items
135
135
  */
136
- add(t) {
137
- this.has(t) || this.push(t);
136
+ add(...t) {
137
+ return t.filter((e) => !this.has(e)).forEach((e) => this.push(e)), this;
138
138
  }
139
139
  /**
140
- * Delete element from set
141
- * @param {T} el Element that will be deleted
140
+ * Delete elements from set
141
+ * @param items Elements that will be deleted
142
142
  */
143
- delete(t) {
144
- const e = this.indexOf(t);
145
- e != -1 && this.slice(e, 1);
143
+ delete(...t) {
144
+ return t.forEach((e) => {
145
+ const n = this.indexOf(e);
146
+ n != -1 && this.slice(n, 1);
147
+ }), this;
146
148
  }
147
149
  /**
148
150
  * Create list of elements this set has which the comparison set does not
@@ -150,7 +152,7 @@ class B extends Array {
150
152
  * @return {ASet<T>} Different elements
151
153
  */
152
154
  difference(t) {
153
- return new B(this.filter((e) => !t.has(e)));
155
+ return new w(this.filter((e) => !t.has(e)));
154
156
  }
155
157
  /**
156
158
  * Check if set includes element
@@ -166,7 +168,7 @@ class B extends Array {
166
168
  * @return {boolean} Set of common elements
167
169
  */
168
170
  intersection(t) {
169
- return new B(this.filter((e) => t.has(e)));
171
+ return new w(this.filter((e) => t.has(e)));
170
172
  }
171
173
  /**
172
174
  * Check if this set has no elements in common with the comparison set
@@ -198,7 +200,7 @@ class B extends Array {
198
200
  * @return {ASet<T>} New set of unique elements
199
201
  */
200
202
  symmetricDifference(t) {
201
- return new B([...this.difference(t), ...t.difference(this)]);
203
+ return new w([...this.difference(t), ...t.difference(this)]);
202
204
  }
203
205
  /**
204
206
  * Create joined list of elements included in this & the comparison set
@@ -206,17 +208,17 @@ class B extends Array {
206
208
  * @return {ASet<T>} New set of both previous sets combined
207
209
  */
208
210
  union(t) {
209
- return new B([...this, ...t]);
211
+ return new w([...this, ...t]);
210
212
  }
211
213
  }
212
- class Dt {
214
+ class It {
213
215
  /**
214
216
  * Create new cache
215
217
  *
216
218
  * @param {keyof T} key Default property to use as primary key
217
- * @param {number} ttl Default expiry in milliseconds
219
+ * @param options
218
220
  */
219
- constructor(t, e) {
221
+ constructor(t, e = {}) {
220
222
  c(this, "store", {});
221
223
  /** Whether cache is complete */
222
224
  c(this, "complete", !1);
@@ -226,7 +228,15 @@ class Dt {
226
228
  * @return {T[]} Array of items
227
229
  */
228
230
  c(this, "values", this.all());
229
- return this.key = t, this.ttl = e, new Proxy(this, {
231
+ if (this.key = t, this.options = e, e.storageKey && !e.storage && typeof Storage < "u" && (e.storage = localStorage), e.storageKey && e.storage) {
232
+ const n = e.storage.getItem(e.storageKey);
233
+ if (n)
234
+ try {
235
+ Object.assign(this.store, JSON.parse(n));
236
+ } catch {
237
+ }
238
+ }
239
+ return new Proxy(this, {
230
240
  get: (n, s) => s in n ? n[s] : n.store[s],
231
241
  set: (n, s, o) => (s in n ? n[s] = o : n.store[s] = o, !0)
232
242
  });
@@ -264,13 +274,19 @@ class Dt {
264
274
  addAll(t, e = !0) {
265
275
  return t.forEach((n) => this.add(n)), this.complete = e, this;
266
276
  }
277
+ /**
278
+ * Remove all keys from cache
279
+ */
280
+ clear() {
281
+ this.store = {};
282
+ }
267
283
  /**
268
284
  * Delete an item from the cache
269
285
  *
270
286
  * @param {K} key Item's primary key
271
287
  */
272
288
  delete(t) {
273
- delete this.store[t];
289
+ delete this.store[t], this.options.storageKey && this.options.storage && this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.store));
274
290
  }
275
291
  /**
276
292
  * Return cache as an array of key-value pairs
@@ -308,29 +324,29 @@ class Dt {
308
324
  *
309
325
  * @param {K} key Key item will be cached under
310
326
  * @param {T} value Item to cache
311
- * @param {number | undefined} ttl Override default expiry
327
+ * @param {number | undefined} ttl Override default expiry in seconds
312
328
  * @return {this}
313
329
  */
314
- set(t, e, n = this.ttl) {
315
- return this.store[t] = e, n && setTimeout(() => {
330
+ set(t, e, n = this.options.ttl) {
331
+ return this.store[t] = e, this.options.storageKey && this.options.storage && this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.store)), n && setTimeout(() => {
316
332
  this.complete = !1, this.delete(t);
317
- }, n), this;
333
+ }, n * 1e3), this;
318
334
  }
319
335
  }
320
- function Pt(r, t = !0) {
321
- const e = r.reduce((n, s) => (Object.keys(t ? H(s) : s).forEach((o) => {
336
+ function Dt(r, t = !0) {
337
+ const e = r.reduce((n, s) => (Object.keys(t ? K(s) : s).forEach((o) => {
322
338
  n.includes(o) || n.push(o);
323
339
  }), n), []);
324
340
  return [
325
341
  e.join(","),
326
342
  ...r.map((n) => e.map((s) => {
327
- const o = b(n, s), i = typeof o;
343
+ const o = B(n, s), i = typeof o;
328
344
  return i == "string" && o.includes(",") ? `"${o}"` : i == "object" ? `"${JSON.stringify(o)}"` : o;
329
345
  }).join(","))
330
346
  ].join(`
331
347
  `);
332
348
  }
333
- class E extends Promise {
349
+ class b extends Promise {
334
350
  constructor(e) {
335
351
  super((n, s) => e(
336
352
  (o) => n(o),
@@ -347,10 +363,10 @@ class E extends Promise {
347
363
  e != this._progress && (this._progress = e, this.listeners.forEach((n) => n(e)));
348
364
  }
349
365
  static from(e) {
350
- return e instanceof E ? e : new E((n, s) => e.then((...o) => n(...o)).catch((...o) => s(...o)));
366
+ return e instanceof b ? e : new b((n, s) => e.then((...o) => n(...o)).catch((...o) => s(...o)));
351
367
  }
352
368
  from(e) {
353
- const n = E.from(e);
369
+ const n = b.from(e);
354
370
  return this.onProgress((s) => n.progress = s), n;
355
371
  }
356
372
  onProgress(e) {
@@ -367,16 +383,16 @@ class E extends Promise {
367
383
  return this.from(super.finally(e));
368
384
  }
369
385
  }
370
- function Gt(r, t) {
371
- r instanceof Blob || (r = new Blob(ft(r)));
386
+ function Mt(r, t) {
387
+ r instanceof Blob || (r = new Blob(S(r)));
372
388
  const e = URL.createObjectURL(r);
373
- dt(e, t), URL.revokeObjectURL(e);
389
+ ft(e, t), URL.revokeObjectURL(e);
374
390
  }
375
- function dt(r, t) {
391
+ function ft(r, t) {
376
392
  const e = document.createElement("a");
377
393
  e.href = r, e.download = t || r.split("/").pop(), document.body.appendChild(e), e.click(), document.body.removeChild(e);
378
394
  }
379
- function Ut(r = {}) {
395
+ function kt(r = {}) {
380
396
  return new Promise((t) => {
381
397
  const e = document.createElement("input");
382
398
  e.type = "file", e.accept = r.accept || "*", e.style.display = "none", e.multiple = !!r.multiple, e.onblur = e.onchange = async () => {
@@ -384,18 +400,18 @@ function Ut(r = {}) {
384
400
  }, document.body.appendChild(e), e.click();
385
401
  });
386
402
  }
387
- function qt(r, t = /* @__PURE__ */ new Date()) {
403
+ function Pt(r, t = /* @__PURE__ */ new Date()) {
388
404
  (typeof t == "number" || typeof t == "string") && (t = new Date(t));
389
405
  const e = `${t.getFullYear()}-${(t.getMonth() + 1).toString().padStart(2, "0")}-${t.getDate().toString().padStart(2, "0")}_${t.getHours().toString().padStart(2, "0")}-${t.getMinutes().toString().padStart(2, "0")}-${t.getSeconds().toString().padStart(2, "0")}`;
390
406
  return r ? r.replace("{{TIMESTAMP}}", e) : e;
391
407
  }
392
- function Ft(r) {
393
- return new E((t, e, n) => {
408
+ function Gt(r) {
409
+ return new b((t, e, n) => {
394
410
  const s = new XMLHttpRequest(), o = new FormData();
395
- r.files.forEach((i) => o.append("file", i)), s.withCredentials = !!r.withCredentials, s.upload.addEventListener("progress", (i) => i.lengthComputable ? n(i.loaded / i.total) : null), s.addEventListener("loadend", () => t(M(s.responseText))), s.addEventListener("error", () => e(M(s.responseText))), s.addEventListener("timeout", () => e({ error: "Request timed out" })), s.open("POST", r.url), Object.entries(r.headers || {}).forEach(([i, a]) => s.setRequestHeader(i, a)), s.send(o);
411
+ r.files.forEach((i) => o.append("file", i)), s.withCredentials = !!r.withCredentials, s.upload.addEventListener("progress", (i) => i.lengthComputable ? n(i.loaded / i.total) : null), s.addEventListener("loadend", () => t(I(s.responseText))), s.addEventListener("error", () => e(I(s.responseText))), s.addEventListener("timeout", () => e({ error: "Request timed out" })), s.open("POST", r.url), Object.entries(r.headers || {}).forEach(([i, u]) => s.setRequestHeader(i, u)), s.send(o);
396
412
  });
397
413
  }
398
- class _ {
414
+ class W {
399
415
  constructor() {
400
416
  c(this, "listeners", {});
401
417
  }
@@ -436,8 +452,8 @@ class _ {
436
452
  });
437
453
  }
438
454
  }
439
- c(_, "listeners", {});
440
- class p extends Error {
455
+ c(W, "listeners", {});
456
+ class y extends Error {
441
457
  constructor(e, n) {
442
458
  super(e);
443
459
  c(this, "_code");
@@ -464,8 +480,8 @@ class p extends Error {
464
480
  return this.message || super.toString();
465
481
  }
466
482
  }
467
- c(p, "code", 500);
468
- class W extends p {
483
+ c(y, "code", 500);
484
+ class v extends y {
469
485
  constructor(t = "Bad Request") {
470
486
  super(t);
471
487
  }
@@ -473,8 +489,8 @@ class W extends p {
473
489
  return t.constructor.code == this.code;
474
490
  }
475
491
  }
476
- c(W, "code", 400);
477
- class J extends p {
492
+ c(v, "code", 400);
493
+ class J extends y {
478
494
  constructor(t = "Unauthorized") {
479
495
  super(t);
480
496
  }
@@ -483,7 +499,7 @@ class J extends p {
483
499
  }
484
500
  }
485
501
  c(J, "code", 401);
486
- class z extends p {
502
+ class z extends y {
487
503
  constructor(t = "Payment Required") {
488
504
  super(t);
489
505
  }
@@ -492,7 +508,7 @@ class z extends p {
492
508
  }
493
509
  }
494
510
  c(z, "code", 402);
495
- class K extends p {
511
+ class Z extends y {
496
512
  constructor(t = "Forbidden") {
497
513
  super(t);
498
514
  }
@@ -500,8 +516,8 @@ class K extends p {
500
516
  return t.constructor.code == this.code;
501
517
  }
502
518
  }
503
- c(K, "code", 403);
504
- class Z extends p {
519
+ c(Z, "code", 403);
520
+ class V extends y {
505
521
  constructor(t = "Not Found") {
506
522
  super(t);
507
523
  }
@@ -509,8 +525,8 @@ class Z extends p {
509
525
  return t.constructor.code == this.code;
510
526
  }
511
527
  }
512
- c(Z, "code", 404);
513
- class V extends p {
528
+ c(V, "code", 404);
529
+ class X extends y {
514
530
  constructor(t = "Method Not Allowed") {
515
531
  super(t);
516
532
  }
@@ -518,8 +534,8 @@ class V extends p {
518
534
  return t.constructor.code == this.code;
519
535
  }
520
536
  }
521
- c(V, "code", 405);
522
- class X extends p {
537
+ c(X, "code", 405);
538
+ class Q extends y {
523
539
  constructor(t = "Not Acceptable") {
524
540
  super(t);
525
541
  }
@@ -527,8 +543,8 @@ class X extends p {
527
543
  return t.constructor.code == this.code;
528
544
  }
529
545
  }
530
- c(X, "code", 406);
531
- class Q extends p {
546
+ c(Q, "code", 406);
547
+ class _ extends y {
532
548
  constructor(t = "Internal Server Error") {
533
549
  super(t);
534
550
  }
@@ -536,8 +552,8 @@ class Q extends p {
536
552
  return t.constructor.code == this.code;
537
553
  }
538
554
  }
539
- c(Q, "code", 500);
540
- class tt extends p {
555
+ c(_, "code", 500);
556
+ class tt extends y {
541
557
  constructor(t = "Not Implemented") {
542
558
  super(t);
543
559
  }
@@ -546,7 +562,7 @@ class tt extends p {
546
562
  }
547
563
  }
548
564
  c(tt, "code", 501);
549
- class et extends p {
565
+ class et extends y {
550
566
  constructor(t = "Bad Gateway") {
551
567
  super(t);
552
568
  }
@@ -555,7 +571,7 @@ class et extends p {
555
571
  }
556
572
  }
557
573
  c(et, "code", 502);
558
- class rt extends p {
574
+ class rt extends y {
559
575
  constructor(t = "Service Unavailable") {
560
576
  super(t);
561
577
  }
@@ -564,7 +580,7 @@ class rt extends p {
564
580
  }
565
581
  }
566
582
  c(rt, "code", 503);
567
- class nt extends p {
583
+ class nt extends y {
568
584
  constructor(t = "Gateway Timeout") {
569
585
  super(t);
570
586
  }
@@ -573,25 +589,25 @@ class nt extends p {
573
589
  }
574
590
  }
575
591
  c(nt, "code", 504);
576
- function Yt(r, t) {
592
+ function Ut(r, t) {
577
593
  if (r >= 200 && r < 300) return null;
578
594
  switch (r) {
579
595
  case 400:
580
- return new W(t);
596
+ return new v(t);
581
597
  case 401:
582
598
  return new J(t);
583
599
  case 402:
584
600
  return new z(t);
585
601
  case 403:
586
- return new K(t);
587
- case 404:
588
602
  return new Z(t);
589
- case 405:
603
+ case 404:
590
604
  return new V(t);
591
- case 406:
605
+ case 405:
592
606
  return new X(t);
593
- case 500:
607
+ case 406:
594
608
  return new Q(t);
609
+ case 500:
610
+ return new _(t);
595
611
  case 501:
596
612
  return new tt(t);
597
613
  case 502:
@@ -601,20 +617,20 @@ function Yt(r, t) {
601
617
  case 504:
602
618
  return new nt(t);
603
619
  default:
604
- return new p(t, r);
620
+ return new y(t, r);
605
621
  }
606
622
  }
607
- const w = class w {
623
+ const E = class E {
608
624
  constructor(t = {}) {
609
625
  c(this, "interceptors", {});
610
626
  c(this, "headers", {});
611
627
  c(this, "url");
612
- this.url = t.url ?? null, this.headers = t.headers || {}, t.interceptors && t.interceptors.forEach((e) => w.addInterceptor(e));
628
+ this.url = t.url ?? null, this.headers = t.headers || {}, t.interceptors && t.interceptors.forEach((e) => E.addInterceptor(e));
613
629
  }
614
630
  static addInterceptor(t) {
615
- const e = Object.keys(w.interceptors).length.toString();
616
- return w.interceptors[e] = t, () => {
617
- w.interceptors[e] = null;
631
+ const e = Object.keys(E.interceptors).length.toString();
632
+ return E.interceptors[e] = t, () => {
633
+ E.interceptors[e] = null;
618
634
  };
619
635
  }
620
636
  addInterceptor(t) {
@@ -631,52 +647,56 @@ const w = class w {
631
647
  const o = Array.isArray(t.query) ? t.query : Object.keys(t.query).map((i) => ({ key: i, value: t.query[i] }));
632
648
  e += (e.includes("?") ? "&" : "?") + o.map((i) => `${i.key}=${i.value}`).join("&");
633
649
  }
634
- const n = ut({
650
+ const n = ct({
635
651
  "Content-Type": t.body ? t.body instanceof FormData ? "multipart/form-data" : "application/json" : void 0,
636
- ...w.headers,
652
+ ...E.headers,
637
653
  ...this.headers,
638
654
  ...t.headers
639
655
  });
640
- return typeof t.body == "object" && t.body != null && n["Content-Type"] == "application/json" && (t.body = JSON.stringify(t.body)), new E((o, i, a) => {
641
- fetch(e, {
642
- headers: n,
643
- method: t.method || (t.body ? "POST" : "GET"),
644
- body: t.body
645
- }).then(async (u) => {
646
- var G, U;
647
- for (let l of [...Object.values(w.interceptors), ...Object.values(this.interceptors)])
648
- await new Promise((R) => l(u, () => R()));
649
- const v = u.headers.get("Content-Length"), N = v ? parseInt(v, 10) : 0;
650
- let P = 0;
651
- const I = (G = u.body) == null ? void 0 : G.getReader(), ot = new ReadableStream({
652
- start(l) {
653
- function R() {
654
- I == null || I.read().then((O) => {
655
- if (O.done) return l.close();
656
- P += O.value.byteLength, a(P / N), l.enqueue(O.value), R();
657
- }).catch((O) => l.error(O));
656
+ return typeof t.body == "object" && t.body != null && n["Content-Type"] == "application/json" && (t.body = JSON.stringify(t.body)), new b((o, i, u) => {
657
+ try {
658
+ fetch(e, {
659
+ headers: n,
660
+ method: t.method || (t.body ? "POST" : "GET"),
661
+ body: t.body
662
+ }).then(async (a) => {
663
+ var G, U;
664
+ for (let l of [...Object.values(E.interceptors), ...Object.values(this.interceptors)])
665
+ await new Promise((C) => l(a, () => C()));
666
+ const $ = a.headers.get("Content-Length"), j = $ ? parseInt($, 10) : 0;
667
+ let P = 0;
668
+ const T = (G = a.body) == null ? void 0 : G.getReader(), st = new ReadableStream({
669
+ start(l) {
670
+ function C() {
671
+ T == null || T.read().then((A) => {
672
+ if (A.done) return l.close();
673
+ P += A.value.byteLength, u(P / j), l.enqueue(A.value), C();
674
+ }).catch((A) => l.error(A));
675
+ }
676
+ C();
658
677
  }
659
- R();
678
+ });
679
+ if (a.data = new Response(st), t.decode == null || t.decode) {
680
+ const l = (U = a.headers.get("Content-Type")) == null ? void 0 : U.toLowerCase();
681
+ l != null && l.includes("form") ? a.data = await a.data.formData() : l != null && l.includes("json") ? a.data = await a.data.json() : l != null && l.includes("text") ? a.data = await a.data.text() : l != null && l.includes("application") && (a.data = await a.data.blob());
660
682
  }
661
- });
662
- if (u.data = new Response(ot), t.decode == null || t.decode) {
663
- const l = (U = u.headers.get("Content-Type")) == null ? void 0 : U.toLowerCase();
664
- l != null && l.includes("form") ? u.data = await u.data.formData() : l != null && l.includes("json") ? u.data = await u.data.json() : l != null && l.includes("text") ? u.data = await u.data.text() : l != null && l.includes("application") && (u.data = await u.data.blob());
665
- }
666
- u.ok ? o(u) : i(u);
667
- });
683
+ a.ok ? o(a) : i(a);
684
+ }).catch((a) => i(a));
685
+ } catch (a) {
686
+ i(a);
687
+ }
668
688
  });
669
689
  }
670
690
  };
671
- c(w, "interceptors", {}), c(w, "headers", {});
672
- let F = w;
673
- function Ht(r) {
691
+ c(E, "interceptors", {}), c(E, "headers", {});
692
+ let F = E;
693
+ function qt(r) {
674
694
  const t = r.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
675
- return M(decodeURIComponent(atob(t).split("").map(function(e) {
695
+ return I(decodeURIComponent(atob(t).split("").map(function(e) {
676
696
  return "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2);
677
697
  }).join("")));
678
698
  }
679
- const x = {
699
+ const R = {
680
700
  CLEAR: "\x1B[0m",
681
701
  BRIGHT: "\x1B[1m",
682
702
  DIM: "\x1B[2m",
@@ -684,7 +704,7 @@ const x = {
684
704
  BLINK: "\x1B[5m",
685
705
  REVERSE: "\x1B[7m",
686
706
  HIDDEN: "\x1B[8m"
687
- }, j = {
707
+ }, L = {
688
708
  BLACK: "\x1B[30m",
689
709
  RED: "\x1B[31m",
690
710
  GREEN: "\x1B[32m",
@@ -701,7 +721,7 @@ const x = {
701
721
  LIGHT_MAGENTA: "\x1B[95m",
702
722
  LIGHT_CYAN: "\x1B[96m",
703
723
  WHITE: "\x1B[97m"
704
- }, _t = {
724
+ }, Ft = {
705
725
  BLACK: "\x1B[40m",
706
726
  RED: "\x1B[41m",
707
727
  GREEN: "\x1B[42m",
@@ -712,100 +732,94 @@ const x = {
712
732
  WHITE: "\x1B[47m",
713
733
  GREY: "\x1B[100m"
714
734
  };
715
- var yt = /* @__PURE__ */ ((r) => (r[r.ERROR = 0] = "ERROR", r[r.WARN = 1] = "WARN", r[r.INFO = 2] = "INFO", r[r.LOG = 3] = "LOG", r[r.DEBUG = 4] = "DEBUG", r))(yt || {});
716
- const g = class g extends _ {
735
+ var dt = /* @__PURE__ */ ((r) => (r[r.ERROR = 0] = "ERROR", r[r.WARN = 1] = "WARN", r[r.INFO = 2] = "INFO", r[r.LOG = 3] = "LOG", r[r.DEBUG = 4] = "DEBUG", r))(dt || {});
736
+ const m = class m extends W {
717
737
  constructor(t) {
718
738
  super(), this.namespace = t;
719
739
  }
720
- pad(t, e, n, s = !1) {
721
- const o = t.toString(), i = e - o.length;
722
- if (i <= 0) return o;
723
- const a = Array(~~(i / n.length)).fill(n).join("");
724
- return s ? o + a : a + o;
725
- }
726
740
  format(...t) {
727
741
  const e = /* @__PURE__ */ new Date();
728
- return `${`${e.getFullYear()}-${e.getMonth() + 1}-${e.getDate()} ${this.pad(e.getHours().toString(), 2, "0")}:${this.pad(e.getMinutes().toString(), 2, "0")}:${this.pad(e.getSeconds().toString(), 2, "0")}.${this.pad(e.getMilliseconds().toString(), 3, "0", !0)}`}${this.namespace ? ` [${this.namespace}]` : ""} ${t.join(" ")}`;
742
+ return `${`${e.getFullYear()}-${e.getMonth() + 1}-${e.getDate()} ${e.getHours().toString().padStart(2, "0")}:${e.getMinutes().toString().padStart(2, "0")}:${e.getSeconds().toString().padStart(2, "0")}.${e.getMilliseconds().toString().padEnd(3, "0")}`}${this.namespace ? ` [${this.namespace}]` : ""} ${t.map((s) => typeof s == "string" ? s : ut(s, 2)).join(" ")}`;
729
743
  }
730
744
  debug(...t) {
731
- if (g.LOG_LEVEL < 4) return;
745
+ if (m.LOG_LEVEL < 4) return;
732
746
  const e = this.format(...t);
733
- g.emit(4, e), console.debug(j.LIGHT_GREY + e + x.CLEAR);
747
+ m.emit(4, e), console.debug(L.LIGHT_GREY + e + R.CLEAR);
734
748
  }
735
749
  log(...t) {
736
- if (g.LOG_LEVEL < 3) return;
750
+ if (m.LOG_LEVEL < 3) return;
737
751
  const e = this.format(...t);
738
- g.emit(3, e), console.log(x.CLEAR + e);
752
+ m.emit(3, e), console.log(R.CLEAR + e);
739
753
  }
740
754
  info(...t) {
741
- if (g.LOG_LEVEL < 2) return;
755
+ if (m.LOG_LEVEL < 2) return;
742
756
  const e = this.format(...t);
743
- g.emit(2, e), console.info(j.BLUE + e + x.CLEAR);
757
+ m.emit(2, e), console.info(L.BLUE + e + R.CLEAR);
744
758
  }
745
759
  warn(...t) {
746
- if (g.LOG_LEVEL < 1) return;
760
+ if (m.LOG_LEVEL < 1) return;
747
761
  const e = this.format(...t);
748
- g.emit(1, e), console.warn(j.YELLOW + e + x.CLEAR);
762
+ m.emit(1, e), console.warn(L.YELLOW + e + R.CLEAR);
749
763
  }
750
764
  error(...t) {
751
- if (g.LOG_LEVEL < 0) return;
765
+ if (m.LOG_LEVEL < 0) return;
752
766
  const e = this.format(...t);
753
- g.emit(0, e), console.error(j.RED + e + x.CLEAR);
767
+ m.emit(0, e), console.error(L.RED + e + R.CLEAR);
754
768
  }
755
769
  };
756
- c(g, "LOG_LEVEL", 4);
757
- let Y = g;
758
- function Wt(r) {
759
- const t = (a, u) => u < 1e-7 ? a : t(u, ~~(a % u)), e = r.toString().length - 2;
770
+ c(m, "LOG_LEVEL", 4);
771
+ let Y = m;
772
+ function Yt(r) {
773
+ const t = (u, a) => a < 1e-7 ? u : t(a, ~~(u % a)), e = r.toString().length - 2;
760
774
  let n = Math.pow(10, e), s = r * n;
761
775
  const o = t(s, n);
762
776
  s = ~~(s / o), n = ~~(n / o);
763
777
  const i = ~~(s / n);
764
778
  return s -= i * n, `${i ? i + " " : ""}${~~s}/${~~n}`;
765
779
  }
766
- function Jt(r) {
780
+ function Ht(r) {
767
781
  let t = r.split(" ");
768
782
  const e = t.length == 2 ? Number(t[0]) : 0;
769
783
  return t = t.pop().split("/"), e + Number(t[0]) / Number(t[1]);
770
784
  }
771
- const T = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", k = "0123456789", D = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", pt = T + k + D;
772
- function zt(r, t = 2) {
785
+ const D = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", M = "0123456789", k = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", pt = D + M + k;
786
+ function Kt(r, t = 2) {
773
787
  if (r === 0) return "0 Bytes";
774
788
  const e = 1024, n = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], s = Math.floor(Math.log(r) / Math.log(e));
775
789
  return parseFloat((r / Math.pow(e, s)).toFixed(t)) + " " + n[s];
776
790
  }
777
- function Kt(r) {
791
+ function Wt(r) {
778
792
  const t = /(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(r);
779
793
  if (!t) throw new Error(`Number cannot be parsed: ${r}`);
780
794
  return `${t[1] ?? ""} (${t[2]}) ${t[3]}-${t[4]}`.trim();
781
795
  }
782
- function Zt(r, t, e) {
796
+ function vt(r, t, e) {
783
797
  return `${r.slice(0, e)}${t}${r.slice(e + 1)}`;
784
798
  }
785
- function Vt(r, t, e = " ", n = !0) {
799
+ function Jt(r, t, e = " ", n = !0) {
786
800
  return n ? r.toString().padStart(t, e) : r.toString().padEnd(t, e);
787
801
  }
788
- function Xt(r) {
802
+ function zt(r) {
789
803
  return Array(r).fill(null).map(() => Math.round(Math.random() * 15).toString(16)).join("");
790
804
  }
791
- function Qt(r, t = pt) {
805
+ function Zt(r, t = pt) {
792
806
  return Array(r).fill(null).map(() => {
793
807
  const e = ~~(Math.random() * t.length);
794
808
  return t[e];
795
809
  }).join("");
796
810
  }
797
- function te(r, t = !1, e = !1, n = !1) {
811
+ function Vt(r, t = !1, e = !1, n = !1) {
798
812
  if (!t && !e && !n) throw new Error("Must enable at least one: letters, numbers, symbols");
799
813
  return Array(r).fill(null).map(() => {
800
814
  let s;
801
815
  do {
802
816
  const o = ~~(Math.random() * 3);
803
- t && o == 0 ? s = T[~~(Math.random() * T.length)] : e && o == 1 ? s = k[~~(Math.random() * k.length)] : n && o == 2 && (s = D[~~(Math.random() * D.length)]);
817
+ t && o == 0 ? s = D[~~(Math.random() * D.length)] : e && o == 1 ? s = M[~~(Math.random() * M.length)] : n && o == 2 && (s = k[~~(Math.random() * k.length)]);
804
818
  } while (!s);
805
819
  return s;
806
820
  }).join("");
807
821
  }
808
- function ee(r, t) {
822
+ function Xt(r, t) {
809
823
  if (typeof t == "string" && (t = new RegExp(t, "g")), !t.global)
810
824
  throw new TypeError("Regular expression must be global.");
811
825
  let e = [], n;
@@ -813,7 +827,7 @@ function ee(r, t) {
813
827
  e.push(n);
814
828
  return e;
815
829
  }
816
- function re(r) {
830
+ function Qt(r) {
817
831
  const t = new RegExp(
818
832
  "(?:(?<protocol>[\\w\\d]+)\\:\\/\\/)?(?:(?<user>.+)\\@)?(?<host>(?<domain>[^:\\/\\?#@\\n]+)(?:\\:(?<port>\\d*))?)(?<path>\\/.*?)?(?:\\?(?<query>.*?))?(?:#(?<fragment>.*?))?$",
819
833
  "gm"
@@ -821,17 +835,17 @@ function re(r) {
821
835
  if (e.port != null && (e.port = Number(e.port)), n.length > 2 && (e.domain = n.splice(-2, 2).join("."), e.subdomain = n.join(".")), e.query) {
822
836
  const s = e.query.split("&"), o = {};
823
837
  s.forEach((i) => {
824
- const [a, u] = i.split("=");
825
- o[a] = u;
838
+ const [u, a] = i.split("=");
839
+ o[u] = a;
826
840
  }), e.query = o;
827
841
  }
828
842
  return e;
829
843
  }
830
844
  function gt(r) {
831
- var t = wt(Et(bt(mt(r), 8 * r.length)));
845
+ var t = yt(wt(Et(mt(r), 8 * r.length)));
832
846
  return t.toLowerCase();
833
847
  }
834
- function wt(r) {
848
+ function yt(r) {
835
849
  for (var t, e = "0123456789ABCDEF", n = "", s = 0; s < r.length; s++) t = r.charCodeAt(s), n += e.charAt(t >>> 4 & 15) + e.charAt(15 & t);
836
850
  return n;
837
851
  }
@@ -840,269 +854,323 @@ function mt(r) {
840
854
  for (e = 0; e < 8 * r.length; e += 8) t[e >> 5] |= (255 & r.charCodeAt(e / 8)) << e % 32;
841
855
  return t;
842
856
  }
843
- function Et(r) {
857
+ function wt(r) {
844
858
  for (var t = "", e = 0; e < 32 * r.length; e += 8) t += String.fromCharCode(r[e >> 5] >>> e % 32 & 255);
845
859
  return t;
846
860
  }
847
- function bt(r, t) {
861
+ function Et(r, t) {
848
862
  r[t >> 5] |= 128 << t % 32, r[14 + (t + 64 >>> 9 << 4)] = t;
849
863
  for (var e = 1732584193, n = -271733879, s = -1732584194, o = 271733878, i = 0; i < r.length; i += 16) {
850
- var a = e, u = n, v = s, N = o;
851
- n = y(n = y(n = y(n = y(n = d(n = d(n = d(n = d(n = f(n = f(n = f(n = f(n = h(n = h(n = h(n = h(n, s = h(s, o = h(o, e = h(e, n, s, o, r[i + 0], 7, -680876936), n, s, r[i + 1], 12, -389564586), e, n, r[i + 2], 17, 606105819), o, e, r[i + 3], 22, -1044525330), s = h(s, o = h(o, e = h(e, n, s, o, r[i + 4], 7, -176418897), n, s, r[i + 5], 12, 1200080426), e, n, r[i + 6], 17, -1473231341), o, e, r[i + 7], 22, -45705983), s = h(s, o = h(o, e = h(e, n, s, o, r[i + 8], 7, 1770035416), n, s, r[i + 9], 12, -1958414417), e, n, r[i + 10], 17, -42063), o, e, r[i + 11], 22, -1990404162), s = h(s, o = h(o, e = h(e, n, s, o, r[i + 12], 7, 1804603682), n, s, r[i + 13], 12, -40341101), e, n, r[i + 14], 17, -1502002290), o, e, r[i + 15], 22, 1236535329), s = f(s, o = f(o, e = f(e, n, s, o, r[i + 1], 5, -165796510), n, s, r[i + 6], 9, -1069501632), e, n, r[i + 11], 14, 643717713), o, e, r[i + 0], 20, -373897302), s = f(s, o = f(o, e = f(e, n, s, o, r[i + 5], 5, -701558691), n, s, r[i + 10], 9, 38016083), e, n, r[i + 15], 14, -660478335), o, e, r[i + 4], 20, -405537848), s = f(s, o = f(o, e = f(e, n, s, o, r[i + 9], 5, 568446438), n, s, r[i + 14], 9, -1019803690), e, n, r[i + 3], 14, -187363961), o, e, r[i + 8], 20, 1163531501), s = f(s, o = f(o, e = f(e, n, s, o, r[i + 13], 5, -1444681467), n, s, r[i + 2], 9, -51403784), e, n, r[i + 7], 14, 1735328473), o, e, r[i + 12], 20, -1926607734), s = d(s, o = d(o, e = d(e, n, s, o, r[i + 5], 4, -378558), n, s, r[i + 8], 11, -2022574463), e, n, r[i + 11], 16, 1839030562), o, e, r[i + 14], 23, -35309556), s = d(s, o = d(o, e = d(e, n, s, o, r[i + 1], 4, -1530992060), n, s, r[i + 4], 11, 1272893353), e, n, r[i + 7], 16, -155497632), o, e, r[i + 10], 23, -1094730640), s = d(s, o = d(o, e = d(e, n, s, o, r[i + 13], 4, 681279174), n, s, r[i + 0], 11, -358537222), e, n, r[i + 3], 16, -722521979), o, e, r[i + 6], 23, 76029189), s = d(s, o = d(o, e = d(e, n, s, o, r[i + 9], 4, -640364487), n, s, r[i + 12], 11, -421815835), e, n, r[i + 15], 16, 530742520), o, e, r[i + 2], 23, -995338651), s = y(s, o = y(o, e = y(e, n, s, o, r[i + 0], 6, -198630844), n, s, r[i + 7], 10, 1126891415), e, n, r[i + 14], 15, -1416354905), o, e, r[i + 5], 21, -57434055), s = y(s, o = y(o, e = y(e, n, s, o, r[i + 12], 6, 1700485571), n, s, r[i + 3], 10, -1894986606), e, n, r[i + 10], 15, -1051523), o, e, r[i + 1], 21, -2054922799), s = y(s, o = y(o, e = y(e, n, s, o, r[i + 8], 6, 1873313359), n, s, r[i + 15], 10, -30611744), e, n, r[i + 6], 15, -1560198380), o, e, r[i + 13], 21, 1309151649), s = y(s, o = y(o, e = y(e, n, s, o, r[i + 4], 6, -145523070), n, s, r[i + 11], 10, -1120210379), e, n, r[i + 2], 15, 718787259), o, e, r[i + 9], 21, -343485551), e = m(e, a), n = m(n, u), s = m(s, v), o = m(o, N);
864
+ var u = e, a = n, $ = s, j = o;
865
+ n = p(n = p(n = p(n = p(n = d(n = d(n = d(n = d(n = f(n = f(n = f(n = f(n = h(n = h(n = h(n = h(n, s = h(s, o = h(o, e = h(e, n, s, o, r[i + 0], 7, -680876936), n, s, r[i + 1], 12, -389564586), e, n, r[i + 2], 17, 606105819), o, e, r[i + 3], 22, -1044525330), s = h(s, o = h(o, e = h(e, n, s, o, r[i + 4], 7, -176418897), n, s, r[i + 5], 12, 1200080426), e, n, r[i + 6], 17, -1473231341), o, e, r[i + 7], 22, -45705983), s = h(s, o = h(o, e = h(e, n, s, o, r[i + 8], 7, 1770035416), n, s, r[i + 9], 12, -1958414417), e, n, r[i + 10], 17, -42063), o, e, r[i + 11], 22, -1990404162), s = h(s, o = h(o, e = h(e, n, s, o, r[i + 12], 7, 1804603682), n, s, r[i + 13], 12, -40341101), e, n, r[i + 14], 17, -1502002290), o, e, r[i + 15], 22, 1236535329), s = f(s, o = f(o, e = f(e, n, s, o, r[i + 1], 5, -165796510), n, s, r[i + 6], 9, -1069501632), e, n, r[i + 11], 14, 643717713), o, e, r[i + 0], 20, -373897302), s = f(s, o = f(o, e = f(e, n, s, o, r[i + 5], 5, -701558691), n, s, r[i + 10], 9, 38016083), e, n, r[i + 15], 14, -660478335), o, e, r[i + 4], 20, -405537848), s = f(s, o = f(o, e = f(e, n, s, o, r[i + 9], 5, 568446438), n, s, r[i + 14], 9, -1019803690), e, n, r[i + 3], 14, -187363961), o, e, r[i + 8], 20, 1163531501), s = f(s, o = f(o, e = f(e, n, s, o, r[i + 13], 5, -1444681467), n, s, r[i + 2], 9, -51403784), e, n, r[i + 7], 14, 1735328473), o, e, r[i + 12], 20, -1926607734), s = d(s, o = d(o, e = d(e, n, s, o, r[i + 5], 4, -378558), n, s, r[i + 8], 11, -2022574463), e, n, r[i + 11], 16, 1839030562), o, e, r[i + 14], 23, -35309556), s = d(s, o = d(o, e = d(e, n, s, o, r[i + 1], 4, -1530992060), n, s, r[i + 4], 11, 1272893353), e, n, r[i + 7], 16, -155497632), o, e, r[i + 10], 23, -1094730640), s = d(s, o = d(o, e = d(e, n, s, o, r[i + 13], 4, 681279174), n, s, r[i + 0], 11, -358537222), e, n, r[i + 3], 16, -722521979), o, e, r[i + 6], 23, 76029189), s = d(s, o = d(o, e = d(e, n, s, o, r[i + 9], 4, -640364487), n, s, r[i + 12], 11, -421815835), e, n, r[i + 15], 16, 530742520), o, e, r[i + 2], 23, -995338651), s = p(s, o = p(o, e = p(e, n, s, o, r[i + 0], 6, -198630844), n, s, r[i + 7], 10, 1126891415), e, n, r[i + 14], 15, -1416354905), o, e, r[i + 5], 21, -57434055), s = p(s, o = p(o, e = p(e, n, s, o, r[i + 12], 6, 1700485571), n, s, r[i + 3], 10, -1894986606), e, n, r[i + 10], 15, -1051523), o, e, r[i + 1], 21, -2054922799), s = p(s, o = p(o, e = p(e, n, s, o, r[i + 8], 6, 1873313359), n, s, r[i + 15], 10, -30611744), e, n, r[i + 6], 15, -1560198380), o, e, r[i + 13], 21, 1309151649), s = p(s, o = p(o, e = p(e, n, s, o, r[i + 4], 6, -145523070), n, s, r[i + 11], 10, -1120210379), e, n, r[i + 2], 15, 718787259), o, e, r[i + 9], 21, -343485551), e = x(e, u), n = x(n, a), s = x(s, $), o = x(o, j);
852
866
  }
853
867
  return Array(e, n, s, o);
854
868
  }
855
- function C(r, t, e, n, s, o) {
856
- return m(St(m(m(t, r), m(n, o)), s), e);
869
+ function N(r, t, e, n, s, o) {
870
+ return x(St(x(x(t, r), x(n, o)), s), e);
857
871
  }
858
872
  function h(r, t, e, n, s, o, i) {
859
- return C(t & e | ~t & n, r, t, s, o, i);
873
+ return N(t & e | ~t & n, r, t, s, o, i);
860
874
  }
861
875
  function f(r, t, e, n, s, o, i) {
862
- return C(t & n | e & ~n, r, t, s, o, i);
876
+ return N(t & n | e & ~n, r, t, s, o, i);
863
877
  }
864
878
  function d(r, t, e, n, s, o, i) {
865
- return C(t ^ e ^ n, r, t, s, o, i);
879
+ return N(t ^ e ^ n, r, t, s, o, i);
866
880
  }
867
- function y(r, t, e, n, s, o, i) {
868
- return C(e ^ (t | ~n), r, t, s, o, i);
881
+ function p(r, t, e, n, s, o, i) {
882
+ return N(e ^ (t | ~n), r, t, s, o, i);
869
883
  }
870
- function m(r, t) {
884
+ function x(r, t) {
871
885
  var e = (65535 & r) + (65535 & t);
872
886
  return (r >> 16) + (t >> 16) + (e >> 16) << 16 | 65535 & e;
873
887
  }
874
888
  function St(r, t) {
875
889
  return r << t | r >>> 32 - t;
876
890
  }
877
- function ne(r) {
891
+ function _t(r) {
878
892
  return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(r);
879
893
  }
880
- function se(r, t = "mp") {
894
+ function te(r, t = "mp") {
881
895
  return r ? `https://www.gravatar.com/avatar/${gt(r)}?d=${t}` : "";
882
896
  }
883
- function oe(r) {
884
- (typeof r == "number" || typeof r == "string") && (r = new Date(r));
885
- let t = r.getHours(), e = "AM";
886
- return t >= 12 ? (t > 12 && (t -= 12), e = "PM") : t == 0 && (t = 12), `${r.getFullYear()}-${(r.getMonth() + 1).toString().padStart(2, "0")}-${r.getDate().toString().padStart(2, "0")}, ${t}:${r.getMinutes().toString().padStart(2, "0")} ${e}`;
897
+ function ee(r) {
898
+ return r.replace(/[.*+?^${}()|\[\]\\]/g, "\\$&");
887
899
  }
888
- function Ot(r) {
889
- return new Promise((t) => setTimeout(t, r));
900
+ function re(r, ...t) {
901
+ const e = [];
902
+ for (let n = 0; n < r.length || n < t.length; n++)
903
+ r[n] && e.push(r[n]), t[n] && e.push(t[n]);
904
+ return new g(e.join(""));
890
905
  }
891
- async function ie(r, t = 100) {
892
- for (; await r(); ) await Ot(t);
906
+ function xt(r, ...t) {
907
+ let e = [];
908
+ for (let o = 0; o < r.length || o < t.length; o++)
909
+ r[o] && e.push(r[o]), t[o] && e.push(t[o]);
910
+ const [n, s] = e.join("").split(":");
911
+ return g.toString(n, s == null ? void 0 : s.split(""));
893
912
  }
894
- function ce(r) {
895
- return (r instanceof Date ? r.getTime() : r) - (/* @__PURE__ */ new Date()).getTime();
913
+ class H extends Error {
896
914
  }
897
- function ue() {
898
- return Object.keys({});
899
- }
900
- var $ = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, xt = {}, S = {};
901
- Object.defineProperty(S, "__esModule", { value: !0 });
902
- S.persist = S.Persist = void 0;
903
- class st {
915
+ class g {
916
+ constructor(t) {
917
+ /** First directory in path */
918
+ c(this, "module");
919
+ /** Entire path, including the module & name */
920
+ c(this, "fullPath");
921
+ /** Path including the name, excluding the module */
922
+ c(this, "path");
923
+ /** Last sagment of path */
924
+ c(this, "name");
925
+ /** List of methods */
926
+ c(this, "methods");
927
+ var i;
928
+ if (typeof t == "object") return Object.assign(this, t);
929
+ let [e, n, s] = t.split(":");
930
+ s || (s = n || "*"), (e == "*" || !e && s == "*") && (e = "", s = "*");
931
+ let o = e.split("/").filter((u) => !!u);
932
+ this.module = ((i = o.splice(0, 1)[0]) == null ? void 0 : i.toLowerCase()) || "", this.fullPath = e, this.path = o.join("/"), this.name = o.pop() || "", this.methods = new w(s.split(""));
933
+ }
934
+ /** All/Wildcard specified */
935
+ get all() {
936
+ return this.methods.has("*");
937
+ }
938
+ set all(t) {
939
+ t ? new w(["*"]) : this.methods.delete("*");
940
+ }
941
+ /** None specified */
942
+ get none() {
943
+ return this.methods.has("n");
944
+ }
945
+ set none(t) {
946
+ t ? this.methods = new w(["n"]) : this.methods.delete("n");
947
+ }
948
+ /** Create method specified */
949
+ get create() {
950
+ return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("c"));
951
+ }
952
+ set create(t) {
953
+ t ? this.methods.delete("n").add("c") : this.methods.delete("c");
954
+ }
955
+ /** Read method specified */
956
+ get read() {
957
+ return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("r"));
958
+ }
959
+ set read(t) {
960
+ t ? this.methods.delete("n").add("r") : this.methods.delete("r");
961
+ }
962
+ /** Update method specified */
963
+ get update() {
964
+ return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("u"));
965
+ }
966
+ set update(t) {
967
+ t ? this.methods.delete("n").add("u") : this.methods.delete("u");
968
+ }
969
+ /** Delete method specified */
970
+ get delete() {
971
+ return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("d"));
972
+ }
973
+ set delete(t) {
974
+ t ? this.methods.delete("n").add("d") : this.methods.delete("d");
975
+ }
904
976
  /**
905
- * @param {string} key Primary key value will be stored under
906
- * @param {PersistOptions<T>} options Configure using {@link PersistOptions}
977
+ * Combine multiple events into one parsed object. Longest path takes precedent, but all subsequent methods are
978
+ * combined until a "none" is reached
979
+ *
980
+ * @param {string | PathEvent} paths Events as strings or pre-parsed
981
+ * @return {PathEvent} Final combined permission
907
982
  */
908
- constructor(t, e = {}) {
909
- c(this, "key");
910
- c(this, "options");
911
- /** Backend service to store data, must implement `Storage` interface */
912
- c(this, "storage");
913
- /** Listeners which should be notified on changes */
914
- c(this, "watches", {});
915
- /** Private value field */
916
- c(this, "_value");
917
- this.key = t, this.options = e, this.storage = e.storage || localStorage, this.load();
918
- }
919
- /** Current value or default if undefined */
920
- get value() {
921
- var t;
922
- return this._value !== void 0 ? this._value : (t = this.options) == null ? void 0 : t.default;
923
- }
924
- /** Set value with proxy object wrapper to sync future changes */
925
- set value(t) {
926
- t == null || typeof t != "object" ? this._value = t : this._value = new Proxy(t, {
927
- get: (e, n) => typeof e[n] == "function" ? (...o) => {
928
- const i = e[n](...o);
929
- return this.save(), i;
930
- } : e[n],
931
- set: (e, n, s) => (e[n] = s, this.save(), !0)
932
- }), this.save();
933
- }
934
- /** Notify listeners of change */
935
- notify(t) {
936
- Object.values(this.watches).forEach((e) => e(t));
937
- }
938
- /** Delete value from storage */
939
- clear() {
940
- this.storage.removeItem(this.key);
983
+ static combine(...t) {
984
+ let e = !1;
985
+ const n = t.map((s) => new g(s)).toSorted((s, o) => {
986
+ const i = s.fullPath.length, u = o.fullPath.length;
987
+ return i < u ? 1 : i > u ? -1 : 0;
988
+ }).reduce((s, o) => (o.none && (e = !0), s ? (e || (o.all && (s.all = !0), (o.all || o.create) && (s.create = !0), (o.all || o.read) && (s.read = !0), (o.all || o.update) && (s.update = !0), (o.all || o.delete) && (s.delete = !0), s.methods = [...s.methods, ...o.methods]), s) : o), null);
989
+ return n.methods = new w(n.methods), n.raw = xt`${n.fullPath}:${n.methods}`, n;
941
990
  }
942
- /** Save current value to storage */
943
- save() {
944
- this._value === void 0 ? this.clear() : this.storage.setItem(this.key, JSON.stringify(this._value)), this.notify(this.value);
991
+ /**
992
+ * Squash 2 sets of paths & return true if any overlap is found
993
+ *
994
+ * @param {string | PathEvent | (string | PathEvent)[]} target Array of Events as strings or pre-parsed
995
+ * @param has Target must have at least one of these path
996
+ * @return {boolean} Whether there is any overlap
997
+ */
998
+ static has(t, ...e) {
999
+ const n = S(e).map((o) => new g(o)), s = S(t).map((o) => new g(o));
1000
+ return !!n.find((o) => {
1001
+ if (!o.fullPath && o.all) return !0;
1002
+ const i = s.filter((a) => o.fullPath.startsWith(a.fullPath));
1003
+ if (!i.length) return !1;
1004
+ const u = g.combine(...i);
1005
+ return !u.none && (u.all || new w(u.methods).intersection(new w(o.methods)).length);
1006
+ });
1007
+ }
1008
+ /**
1009
+ * Squash 2 sets of paths & return true if the target has all paths
1010
+ *
1011
+ * @param {string | PathEvent | (string | PathEvent)[]} target Array of Events as strings or pre-parsed
1012
+ * @param has Target must have all these paths
1013
+ * @return {boolean} Whether there is any overlap
1014
+ */
1015
+ static hasAll(t, ...e) {
1016
+ return e.filter((n) => g.has(t, n)).length == e.length;
945
1017
  }
946
- /** Load value from storage */
947
- load() {
948
- if (this.storage[this.key] != null) {
949
- let t = JSON.parse(this.storage.getItem(this.key));
950
- t != null && typeof t == "object" && this.options.type && (t.__proto__ = this.options.type.prototype), this.value = t;
951
- } else
952
- this.value = this.options.default || void 0;
1018
+ /**
1019
+ * Same as `has` but raises an error if there is no overlap
1020
+ *
1021
+ * @param {string | string[]} target Array of Events as strings or pre-parsed
1022
+ * @param has Target must have at least one of these path
1023
+ */
1024
+ static hasFatal(t, ...e) {
1025
+ if (!g.has(t, ...e)) throw new H(`Requires one of: ${S(e).join(", ")}`);
953
1026
  }
954
1027
  /**
955
- * Callback function which is run when there are changes
1028
+ * Same as `hasAll` but raises an error if the target is missing any paths
956
1029
  *
957
- * @param {(value: T) => any} fn Callback will run on each change; it's passed the next value & it's return is ignored
958
- * @returns {() => void} Function which will unsubscribe the watch/callback when called
1030
+ * @param {string | string[]} target Array of Events as strings or pre-parsed
1031
+ * @param has Target must have all these paths
959
1032
  */
960
- watch(t) {
961
- const e = Object.keys(this.watches).length;
962
- return this.watches[e] = t, () => {
963
- delete this.watches[e];
964
- };
1033
+ static hasAllFatal(t, ...e) {
1034
+ if (!g.hasAll(t, ...e)) throw new H(`Requires all: ${S(e).join(", ")}`);
965
1035
  }
966
1036
  /**
967
- * Return value as JSON string
1037
+ * Create event string from its components
968
1038
  *
969
- * @returns {string} Stringified object as JSON
1039
+ * @param {string | string[]} path Event path
1040
+ * @param {Method} methods Event method
1041
+ * @return {string} String representation of Event
970
1042
  */
971
- toString() {
972
- return JSON.stringify(this.value);
1043
+ static toString(t, e) {
1044
+ let n = S(t).filter((s) => s != null).join("/");
1045
+ return n = n == null ? void 0 : n.trim().replaceAll(/\/{2,}/g, "/").replaceAll(/(^\/|\/$)/g, ""), e != null && e.length && (n += `:${S(e).map((s) => s.toLowerCase()).join("")}`), n;
973
1046
  }
974
1047
  /**
975
- * Return current value
1048
+ * Create event string from its components
976
1049
  *
977
- * @returns {T} Current value
1050
+ * @return {string} String representation of Event
978
1051
  */
979
- valueOf() {
980
- return this.value;
981
- }
982
- }
983
- S.Persist = st;
984
- function Bt(r) {
985
- return (t, e) => {
986
- const n = (r == null ? void 0 : r.key) || `${t.constructor.name}.${e.toString()}`, s = new st(n, r);
987
- Object.defineProperty(t, e, {
988
- get: function() {
989
- return s.value;
990
- },
991
- set: function(o) {
992
- s.value = o;
993
- }
994
- });
995
- };
1052
+ toString() {
1053
+ return g.toString(this.fullPath, this.methods);
1054
+ }
996
1055
  }
997
- S.persist = Bt;
998
- var L = {};
999
- Object.defineProperty(L, "__esModule", { value: !0 });
1000
- L.MemoryStorage = void 0;
1001
- class At {
1002
- get length() {
1003
- return Object.keys(this).length;
1056
+ class ne {
1057
+ constructor() {
1058
+ c(this, "listeners", []);
1004
1059
  }
1005
- clear() {
1006
- Object.keys(this).forEach((t) => this.removeItem(t));
1060
+ emit(t, ...e) {
1061
+ const n = new g(t);
1062
+ this.listeners.filter((s) => g.has(s[0], t)).forEach(async (s) => s[1](n, ...e));
1007
1063
  }
1008
- getItem(t) {
1009
- return this[t];
1064
+ off(t) {
1065
+ this.listeners = this.listeners.filter((e) => e[1] != t);
1010
1066
  }
1011
- key(t) {
1012
- return Object.keys(this)[t];
1067
+ on(t, e) {
1068
+ return S(t).forEach((n) => this.listeners.push([new g(n), e])), () => this.off(e);
1013
1069
  }
1014
- removeItem(t) {
1015
- delete this[t];
1070
+ once(t, e) {
1071
+ return new Promise((n) => {
1072
+ const s = this.on(t, (o, ...i) => {
1073
+ n(i.length < 2 ? i[0] : i), e && e(o, ...i), s();
1074
+ });
1075
+ });
1016
1076
  }
1017
- setItem(t, e) {
1018
- this[t] = e;
1077
+ relayEvents(t) {
1078
+ t.on("*", (e, ...n) => this.emit(e, ...n));
1019
1079
  }
1020
1080
  }
1021
- L.MemoryStorage = At;
1022
- (function(r) {
1023
- var t = $ && $.__createBinding || (Object.create ? function(n, s, o, i) {
1024
- i === void 0 && (i = o);
1025
- var a = Object.getOwnPropertyDescriptor(s, o);
1026
- (!a || ("get" in a ? !s.__esModule : a.writable || a.configurable)) && (a = { enumerable: !0, get: function() {
1027
- return s[o];
1028
- } }), Object.defineProperty(n, i, a);
1029
- } : function(n, s, o, i) {
1030
- i === void 0 && (i = o), n[i] = s[o];
1031
- }), e = $ && $.__exportStar || function(n, s) {
1032
- for (var o in n) o !== "default" && !Object.prototype.hasOwnProperty.call(s, o) && t(s, n, o);
1033
- };
1034
- Object.defineProperty(r, "__esModule", { value: !0 }), e(S, r), e(L, r);
1035
- })(xt);
1081
+ function se(r) {
1082
+ (typeof r == "number" || typeof r == "string") && (r = new Date(r));
1083
+ let t = r.getHours(), e = "AM";
1084
+ return t >= 12 ? (t > 12 && (t -= 12), e = "PM") : t == 0 && (t = 12), `${r.getFullYear()}-${(r.getMonth() + 1).toString().padStart(2, "0")}-${r.getDate().toString().padStart(2, "0")}, ${t}:${r.getMinutes().toString().padStart(2, "0")} ${e}`;
1085
+ }
1086
+ function bt(r) {
1087
+ return new Promise((t) => setTimeout(t, r));
1088
+ }
1089
+ async function oe(r, t = 100) {
1090
+ for (; await r(); ) await bt(t);
1091
+ }
1092
+ function ie(r) {
1093
+ return (r instanceof Date ? r.getTime() : r) - (/* @__PURE__ */ new Date()).getTime();
1094
+ }
1095
+ function ce() {
1096
+ return Object.keys({});
1097
+ }
1036
1098
  export {
1037
- B as ASet,
1099
+ w as ASet,
1038
1100
  et as BadGatewayError,
1039
- W as BadRequestError,
1040
- Dt as Cache,
1041
- _t as CliBackground,
1042
- x as CliEffects,
1043
- j as CliForeground,
1044
- p as CustomError,
1045
- K as ForbiddenError,
1101
+ v as BadRequestError,
1102
+ It as Cache,
1103
+ Ft as CliBackground,
1104
+ R as CliEffects,
1105
+ L as CliForeground,
1106
+ y as CustomError,
1107
+ Z as ForbiddenError,
1046
1108
  nt as GatewayTimeoutError,
1047
1109
  F as Http,
1048
- Q as InternalServerError,
1049
- M as JSONAttemptParse,
1050
- Lt as JSONSanitize,
1051
- yt as LOG_LEVEL,
1110
+ _ as InternalServerError,
1111
+ I as JSONAttemptParse,
1112
+ ut as JSONSanitize,
1113
+ dt as LOG_LEVEL,
1052
1114
  Y as Logger,
1053
- V as MethodNotAllowedError,
1054
- X as NotAcceptableError,
1055
- Z as NotFoundError,
1115
+ X as MethodNotAllowedError,
1116
+ Q as NotAcceptableError,
1117
+ V as NotFoundError,
1056
1118
  tt as NotImplementedError,
1119
+ re as PE,
1120
+ xt as PES,
1121
+ H as PathError,
1122
+ g as PathEvent,
1123
+ ne as PathEventEmitter,
1057
1124
  z as PaymentRequiredError,
1058
- E as PromiseProgress,
1125
+ b as PromiseProgress,
1059
1126
  rt as ServiceUnavailableError,
1060
- _ as TypedEmitter,
1127
+ W as TypedEmitter,
1061
1128
  J as UnauthorizedError,
1062
- Nt as addUnique,
1063
- It as arrayDiff,
1064
- Mt as caseInsensitiveSort,
1065
- ut as clean,
1066
- Pt as csv,
1067
- Wt as dec2Frac,
1068
- Rt as deepCopy,
1129
+ Ct as addUnique,
1130
+ Lt as arrayDiff,
1131
+ Nt as caseInsensitiveSort,
1132
+ ct as clean,
1133
+ Dt as csv,
1134
+ Yt as dec2Frac,
1135
+ At as deepCopy,
1069
1136
  at as deepMerge,
1070
- b as dotNotation,
1071
- Gt as downloadFile,
1072
- dt as downloadUrl,
1073
- jt as encodeQuery,
1074
- Yt as errorFromCode,
1075
- Ut as fileBrowser,
1076
- Tt as findByProp,
1137
+ B as dotNotation,
1138
+ Mt as downloadFile,
1139
+ ft as downloadUrl,
1140
+ Rt as encodeQuery,
1141
+ Ut as errorFromCode,
1142
+ ee as escapeRegex,
1143
+ kt as fileBrowser,
1144
+ jt as findByProp,
1077
1145
  lt as flattenArr,
1078
- H as flattenObj,
1079
- $t as formData,
1080
- zt as formatBytes,
1081
- oe as formatDate,
1082
- Kt as formatPhoneNumber,
1083
- Jt as fracToDec,
1084
- se as gravatar,
1146
+ K as flattenObj,
1147
+ Ot as formData,
1148
+ Kt as formatBytes,
1149
+ se as formatDate,
1150
+ Wt as formatPhoneNumber,
1151
+ Ht as fracToDec,
1152
+ te as gravatar,
1085
1153
  q as includes,
1086
- Zt as insertAt,
1087
- A as isEqual,
1088
- Ht as jwtDecode,
1089
- ft as makeArray,
1154
+ vt as insertAt,
1155
+ O as isEqual,
1156
+ qt as jwtDecode,
1157
+ S as makeArray,
1090
1158
  ht as makeUnique,
1091
- ee as matchAll,
1159
+ Xt as matchAll,
1092
1160
  gt as md5,
1093
- Ct as mixin,
1094
- Vt as pad,
1095
- re as parseUrl,
1096
- Xt as randomHex,
1097
- Qt as randomString,
1098
- te as randomStringBuilder,
1099
- Ot as sleep,
1100
- ie as sleepUntil,
1101
- kt as sortByProp,
1102
- ce as timeUntil,
1103
- qt as timestampFilename,
1104
- ue as tyoeKeys,
1105
- Ft as uploadWithProgress,
1106
- ne as validateEmail
1161
+ $t as mixin,
1162
+ Jt as pad,
1163
+ Qt as parseUrl,
1164
+ zt as randomHex,
1165
+ Zt as randomString,
1166
+ Vt as randomStringBuilder,
1167
+ bt as sleep,
1168
+ oe as sleepWhile,
1169
+ Tt as sortByProp,
1170
+ ie as timeUntil,
1171
+ Pt as timestampFilename,
1172
+ ce as tyoeKeys,
1173
+ Gt as uploadWithProgress,
1174
+ _t as validateEmail
1107
1175
  };
1108
1176
  //# sourceMappingURL=index.mjs.map