@ztimson/utils 0.13.1 → 0.13.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/utils.mjs CHANGED
@@ -1,5 +1,5 @@
1
- var v = Object.defineProperty;
2
- var z = (n, e, t) => e in n ? v(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
1
+ var W = Object.defineProperty;
2
+ var z = (n, e, t) => e in n ? W(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
3
  var u = (n, e, t) => (z(n, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  function J(n, e = !1) {
5
5
  if (n == null)
@@ -8,7 +8,7 @@ function J(n, e = !1) {
8
8
  (e && r === void 0 || !e && r == null) && delete n[t];
9
9
  }), n;
10
10
  }
11
- function ft(n) {
11
+ function dt(n) {
12
12
  return JSON.parse(JSON.stringify(n));
13
13
  }
14
14
  function K(n, ...e) {
@@ -17,7 +17,7 @@ function K(n, ...e) {
17
17
  t[r] && typeof t[r] == "object" && !Array.isArray(t[r]) ? (n[r] || (n[r] = {}), K(n[r], t[r])) : n[r] = t[r];
18
18
  }), n;
19
19
  }
20
- function L(n, e, t) {
20
+ function S(n, e, t) {
21
21
  if (!(n == null || !e))
22
22
  return e.split(/[.[\]]/g).filter((r) => r.length).reduce((r, o, s, i) => {
23
23
  if ((o[0] == '"' || o[0] == "'") && (o = o.slice(1, -1)), !(r != null && r.hasOwnProperty(o))) {
@@ -49,7 +49,7 @@ function R(n, e) {
49
49
  const t = typeof n, r = typeof e;
50
50
  return t != "object" || n == null || r != "object" || e == null ? t == "function" && r == "function" ? n.toString() == e.toString() : n === e : Object.keys(n).length != Object.keys(e).length ? !1 : Object.keys(n).every((s) => R(n[s], e[s]));
51
51
  }
52
- function dt(n, e) {
52
+ function pt(n, e) {
53
53
  e.forEach((t) => {
54
54
  Object.getOwnPropertyNames(t.prototype).forEach((r) => {
55
55
  Object.defineProperty(
@@ -60,7 +60,7 @@ function dt(n, e) {
60
60
  });
61
61
  });
62
62
  }
63
- function pt(n, e) {
63
+ function yt(n, e) {
64
64
  let t = [];
65
65
  return JSON.parse(JSON.stringify(n, (r, o) => {
66
66
  if (typeof o == "object" && o !== null) {
@@ -71,31 +71,31 @@ function pt(n, e) {
71
71
  return o;
72
72
  }, e));
73
73
  }
74
- function yt(n, e) {
74
+ function gt(n, e) {
75
75
  return n.indexOf(e) === -1 && n.push(e), n;
76
76
  }
77
- function gt(n, e) {
77
+ function Et(n, e) {
78
78
  return X([
79
79
  ...n.filter((t) => !e.includes((r) => R(t, r))),
80
80
  ...e.filter((t) => !n.includes((r) => R(t, r)))
81
81
  ]);
82
82
  }
83
- function Et(n) {
83
+ function mt(n) {
84
84
  return function(e, t) {
85
- const r = L(e, n), o = L(t, n);
85
+ const r = S(e, n), o = S(t, n);
86
86
  return typeof r != "string" || typeof o != "string" ? 1 : r.toLowerCase().localeCompare(o.toLowerCase());
87
87
  };
88
88
  }
89
89
  function Z(n, e = []) {
90
90
  return n.forEach((t) => Array.isArray(t) ? Z(t, e) : e.push(t)), e;
91
91
  }
92
- function mt(n, e = !1) {
92
+ function wt(n, e = !1) {
93
93
  return function(t, r) {
94
- const o = L(t, n), s = L(r, n);
94
+ const o = S(t, n), s = S(r, n);
95
95
  return typeof o == "number" && typeof s == "number" ? (e ? -1 : 1) * (o - s) : o > s ? e ? -1 : 1 : o < s ? e ? 1 : -1 : 0;
96
96
  };
97
97
  }
98
- function wt(n, e) {
98
+ function xt(n, e) {
99
99
  return (t) => R(t[n], e);
100
100
  }
101
101
  function X(n) {
@@ -103,7 +103,7 @@ function X(n) {
103
103
  n.slice(0, e).find((t) => R(t, n[e])) && n.splice(e, 1);
104
104
  return n;
105
105
  }
106
- function xt(n) {
106
+ function At(n) {
107
107
  return Array.isArray(n) ? n : [n];
108
108
  }
109
109
  class B extends Array {
@@ -145,10 +145,14 @@ class B extends Array {
145
145
  return new B([...this, ...e]);
146
146
  }
147
147
  }
148
- function At(n, e) {
148
+ function Q(n, e) {
149
149
  const t = document.createElement("a");
150
150
  t.href = n, t.download = e, document.body.appendChild(t), t.click(), document.body.removeChild(t);
151
151
  }
152
+ function Bt(n, e) {
153
+ const t = URL.createObjectURL(n);
154
+ Q(t, e), URL.revokeObjectURL(t);
155
+ }
152
156
  class F {
153
157
  constructor() {
154
158
  u(this, "listeners", {});
@@ -219,7 +223,7 @@ class w extends Error {
219
223
  }
220
224
  }
221
225
  u(w, "code", 500);
222
- class Q extends w {
226
+ class _ extends w {
223
227
  constructor(e = "Bad Request") {
224
228
  super(e);
225
229
  }
@@ -227,8 +231,8 @@ class Q extends w {
227
231
  return e.constructor.code == this.code;
228
232
  }
229
233
  }
230
- u(Q, "code", 400);
231
- class _ extends w {
234
+ u(_, "code", 400);
235
+ class tt extends w {
232
236
  constructor(e = "Unauthorized") {
233
237
  super(e);
234
238
  }
@@ -236,8 +240,8 @@ class _ extends w {
236
240
  return e.constructor.code == this.code;
237
241
  }
238
242
  }
239
- u(_, "code", 401);
240
- class tt extends w {
243
+ u(tt, "code", 401);
244
+ class et extends w {
241
245
  constructor(e = "Forbidden") {
242
246
  super(e);
243
247
  }
@@ -245,8 +249,8 @@ class tt extends w {
245
249
  return e.constructor.code == this.code;
246
250
  }
247
251
  }
248
- u(tt, "code", 403);
249
- class et extends w {
252
+ u(et, "code", 403);
253
+ class nt extends w {
250
254
  constructor(e = "Not Found") {
251
255
  super(e);
252
256
  }
@@ -254,8 +258,8 @@ class et extends w {
254
258
  return e.constructor.code == this.code;
255
259
  }
256
260
  }
257
- u(et, "code", 404);
258
- class nt extends w {
261
+ u(nt, "code", 404);
262
+ class rt extends w {
259
263
  constructor(e = "Internal Server Error") {
260
264
  super(e);
261
265
  }
@@ -263,7 +267,7 @@ class nt extends w {
263
267
  return e.constructor.code == this.code;
264
268
  }
265
269
  }
266
- u(nt, "code", 500);
270
+ u(rt, "code", 500);
267
271
  class m extends Promise {
268
272
  constructor(t) {
269
273
  super((r, o) => t(
@@ -341,28 +345,28 @@ const g = class g {
341
345
  method: e.method || (e.body ? "POST" : "GET"),
342
346
  body: e.body
343
347
  }).then(async (c) => {
344
- var M, q;
348
+ var U, M;
345
349
  console.log("done!");
346
350
  for (let x of [...Object.values(g.interceptors), ...Object.values(this.interceptors)])
347
- await new Promise((C) => x(c, () => C()));
351
+ await new Promise((O) => x(c, () => O()));
348
352
  c.ok || i(c);
349
353
  const b = c.headers.get("Content-Length"), I = b ? parseInt(b, 10) : 0;
350
354
  let G = 0;
351
- const T = (M = c.body) == null ? void 0 : M.getReader(), W = new ReadableStream({
355
+ const T = (U = c.body) == null ? void 0 : U.getReader(), v = new ReadableStream({
352
356
  start(x) {
353
- function C() {
354
- T == null || T.read().then(({ done: $, value: U }) => {
357
+ function O() {
358
+ T == null || T.read().then(({ done: $, value: q }) => {
355
359
  if ($)
356
360
  return x.close();
357
- G += U.byteLength, d(G / I), x.enqueue(U), C();
361
+ G += q.byteLength, d(G / I), x.enqueue(q), O();
358
362
  }).catch(($) => {
359
363
  x.error($);
360
364
  });
361
365
  }
362
- C();
366
+ O();
363
367
  }
364
- }), O = new Response(W), y = (q = c.headers.get("Content-Type")) == null ? void 0 : q.toLowerCase();
365
- y != null && y.includes("json") ? c.data = await O.json() : y != null && y.includes("text") ? c.data = await O.text() : y != null && y.includes("form") ? c.data = await O.formData() : y != null && y.includes("application") && (c.data = await O.blob()), s(c);
368
+ }), L = new Response(v), y = (M = c.headers.get("Content-Type")) == null ? void 0 : M.toLowerCase();
369
+ y != null && y.includes("json") ? c.data = await L.json() : y != null && y.includes("text") ? c.data = await L.text() : y != null && y.includes("form") ? c.data = await L.formData() : y != null && y.includes("application") && (c.data = await L.blob()), s(c);
366
370
  });
367
371
  });
368
372
  }
@@ -377,7 +381,7 @@ const A = {
377
381
  BLINK: "\x1B[5m",
378
382
  REVERSE: "\x1B[7m",
379
383
  HIDDEN: "\x1B[8m"
380
- }, S = {
384
+ }, C = {
381
385
  BLACK: "\x1B[30m",
382
386
  RED: "\x1B[31m",
383
387
  GREEN: "\x1B[32m",
@@ -394,7 +398,7 @@ const A = {
394
398
  LIGHT_MAGENTA: "\x1B[95m",
395
399
  LIGHT_CYAN: "\x1B[96m",
396
400
  WHITE: "\x1B[97m"
397
- }, Bt = {
401
+ }, Rt = {
398
402
  BLACK: "\x1B[40m",
399
403
  RED: "\x1B[41m",
400
404
  GREEN: "\x1B[42m",
@@ -405,7 +409,7 @@ const A = {
405
409
  WHITE: "\x1B[47m",
406
410
  GREY: "\x1B[100m"
407
411
  };
408
- var rt = /* @__PURE__ */ ((n) => (n[n.ERROR = 0] = "ERROR", n[n.WARN = 1] = "WARN", n[n.INFO = 2] = "INFO", n[n.LOG = 3] = "LOG", n[n.DEBUG = 4] = "DEBUG", n))(rt || {});
412
+ var ot = /* @__PURE__ */ ((n) => (n[n.ERROR = 0] = "ERROR", n[n.WARN = 1] = "WARN", n[n.INFO = 2] = "INFO", n[n.LOG = 3] = "LOG", n[n.DEBUG = 4] = "DEBUG", n))(ot || {});
409
413
  const p = class p extends F {
410
414
  constructor(e) {
411
415
  super(), this.namespace = e;
@@ -425,7 +429,7 @@ const p = class p extends F {
425
429
  if (p.LOG_LEVEL < 4)
426
430
  return;
427
431
  const t = this.format(...e);
428
- p.emit(4, t), console.debug(S.LIGHT_GREY + t + A.CLEAR);
432
+ p.emit(4, t), console.debug(C.LIGHT_GREY + t + A.CLEAR);
429
433
  }
430
434
  log(...e) {
431
435
  if (p.LOG_LEVEL < 3)
@@ -437,24 +441,24 @@ const p = class p extends F {
437
441
  if (p.LOG_LEVEL < 2)
438
442
  return;
439
443
  const t = this.format(...e);
440
- p.emit(2, t), console.info(S.BLUE + t + A.CLEAR);
444
+ p.emit(2, t), console.info(C.BLUE + t + A.CLEAR);
441
445
  }
442
446
  warn(...e) {
443
447
  if (p.LOG_LEVEL < 1)
444
448
  return;
445
449
  const t = this.format(...e);
446
- p.emit(1, t), console.warn(S.YELLOW + t + A.CLEAR);
450
+ p.emit(1, t), console.warn(C.YELLOW + t + A.CLEAR);
447
451
  }
448
452
  error(...e) {
449
453
  if (p.LOG_LEVEL < 0)
450
454
  return;
451
455
  const t = this.format(...e);
452
- p.emit(0, t), console.error(S.RED + t + A.CLEAR);
456
+ p.emit(0, t), console.error(C.RED + t + A.CLEAR);
453
457
  }
454
458
  };
455
459
  u(p, "LOG_LEVEL", 4);
456
460
  let Y = p;
457
- function Rt(n) {
461
+ function bt(n) {
458
462
  const e = (d, c) => c < 1e-7 ? d : e(c, ~~(d % c)), t = n.toString().length - 2;
459
463
  let r = Math.pow(10, t), o = n * r;
460
464
  const s = e(o, r);
@@ -462,7 +466,7 @@ function Rt(n) {
462
466
  const i = ~~(o / r);
463
467
  return o -= i * r, `${i ? i + " " : ""}${~~o}/${~~r}`;
464
468
  }
465
- function bt(n) {
469
+ function Lt(n) {
466
470
  let e = n.split(" ");
467
471
  const t = e.length == 2 ? Number(e[0]) : 0;
468
472
  return e = e.pop().split("/"), t + Number(e[0]) / Number(e[1]);
@@ -473,30 +477,30 @@ function Ot(n, e) {
473
477
  function Ct(n) {
474
478
  return Array(n).fill(null).map(() => Math.round(Math.random() * 15).toString(16)).join("");
475
479
  }
476
- const D = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", j = "0123456789", k = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", ot = D + j + k;
480
+ const D = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", j = "0123456789", k = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", st = D + j + k;
477
481
  function St(n) {
478
482
  const e = /(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(n);
479
483
  if (!e)
480
484
  throw new Error(`Number cannot be parsed: ${n}`);
481
485
  return `${e[1] ?? ""} (${e[2]}) ${e[3]}-${e[4]}`.trim();
482
486
  }
483
- function Lt(n, e, t) {
487
+ function Nt(n, e, t) {
484
488
  return `${n.slice(0, t)}${e}${n.slice(t + 1)}`;
485
489
  }
486
- function Nt(n, e, t, r = !0) {
490
+ function It(n, e, t, r = !0) {
487
491
  const o = n.toString(), s = e - o.length;
488
492
  if (s <= 0)
489
493
  return o;
490
494
  const i = Array(~~(s / t.length)).fill(t).join("");
491
495
  return r ? i + o : o + i;
492
496
  }
493
- function It(n, e = ot) {
497
+ function Tt(n, e = st) {
494
498
  return Array(n).fill(null).map(() => {
495
499
  const t = ~~(Math.random() * e.length);
496
500
  return e[t];
497
501
  }).join("");
498
502
  }
499
- function Tt(n, e = !1, t = !1, r = !1) {
503
+ function $t(n, e = !1, t = !1, r = !1) {
500
504
  if (!e && !t && !r)
501
505
  throw new Error("Must enable at least one: letters, numbers, symbols");
502
506
  return Array(n).fill(null).map(() => {
@@ -508,7 +512,7 @@ function Tt(n, e = !1, t = !1, r = !1) {
508
512
  return o;
509
513
  }).join("");
510
514
  }
511
- function $t(n, e) {
515
+ function Dt(n, e) {
512
516
  if (typeof e == "string" && (e = new RegExp(e, "g")), !e.global)
513
517
  throw new TypeError("Regular expression must be global.");
514
518
  let t = [], r;
@@ -516,28 +520,28 @@ function $t(n, e) {
516
520
  t.push(r);
517
521
  return t;
518
522
  }
519
- function st(n) {
520
- var e = it(ut(at(ct(n), 8 * n.length)));
523
+ function it(n) {
524
+ var e = ct(at(lt(ut(n), 8 * n.length)));
521
525
  return e.toLowerCase();
522
526
  }
523
- function it(n) {
527
+ function ct(n) {
524
528
  for (var e, t = "0123456789ABCDEF", r = "", o = 0; o < n.length; o++)
525
529
  e = n.charCodeAt(o), r += t.charAt(e >>> 4 & 15) + t.charAt(15 & e);
526
530
  return r;
527
531
  }
528
- function ct(n) {
532
+ function ut(n) {
529
533
  for (var e = Array(n.length >> 2), t = 0; t < e.length; t++)
530
534
  e[t] = 0;
531
535
  for (t = 0; t < 8 * n.length; t += 8)
532
536
  e[t >> 5] |= (255 & n.charCodeAt(t / 8)) << t % 32;
533
537
  return e;
534
538
  }
535
- function ut(n) {
539
+ function at(n) {
536
540
  for (var e = "", t = 0; t < 32 * n.length; t += 8)
537
541
  e += String.fromCharCode(n[t >> 5] >>> t % 32 & 255);
538
542
  return e;
539
543
  }
540
- function at(n, e) {
544
+ function lt(n, e) {
541
545
  n[e >> 5] |= 128 << e % 32, n[14 + (e + 64 >>> 9 << 4)] = e;
542
546
  for (var t = 1732584193, r = -271733879, o = -1732584194, s = 271733878, i = 0; i < n.length; i += 16) {
543
547
  var d = t, c = r, b = o, I = s;
@@ -546,7 +550,7 @@ function at(n, e) {
546
550
  return Array(t, r, o, s);
547
551
  }
548
552
  function N(n, e, t, r, o, s) {
549
- return E(lt(E(E(e, n), E(r, s)), o), t);
553
+ return E(ht(E(E(e, n), E(r, s)), o), t);
550
554
  }
551
555
  function a(n, e, t, r, o, s, i) {
552
556
  return N(e & t | ~e & r, n, e, o, s, i);
@@ -564,21 +568,21 @@ function E(n, e) {
564
568
  var t = (65535 & n) + (65535 & e);
565
569
  return (n >> 16) + (e >> 16) + (t >> 16) << 16 | 65535 & t;
566
570
  }
567
- function lt(n, e) {
571
+ function ht(n, e) {
568
572
  return n << e | n >>> 32 - e;
569
573
  }
570
- function Dt(n) {
574
+ function jt(n) {
571
575
  return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(n);
572
576
  }
573
- function jt(n) {
577
+ function kt(n) {
574
578
  return Object.entries(n).map(
575
579
  ([e, t]) => encodeURIComponent(e) + "=" + encodeURIComponent(t)
576
580
  ).join("&");
577
581
  }
578
- function kt(n, e = "mp") {
579
- return n ? `https://www.gravatar.com/avatar/${st(n)}?d=${e}` : "";
582
+ function Gt(n, e = "mp") {
583
+ return n ? `https://www.gravatar.com/avatar/${it(n)}?d=${e}` : "";
580
584
  }
581
- function Gt(n) {
585
+ function Ut(n) {
582
586
  const e = new RegExp(
583
587
  "(?:(?<protocol>[\\w\\d]+)\\:\\/\\/)?(?:(?<user>.+)\\@)?(?<host>(?<domain>[^:\\/\\?#@\\n]+)(?:\\:(?<port>\\d*))?)(?<path>\\/.*?)?(?:\\?(?<query>.*?))?(?:#(?<fragment>.*?))?$",
584
588
  "gm"
@@ -598,7 +602,7 @@ function Mt(n) {
598
602
  function qt(n) {
599
603
  return new Promise((e) => setTimeout(e, n));
600
604
  }
601
- function Ut(n) {
605
+ function Pt(n) {
602
606
  const e = n instanceof Date ? n : new Date(n);
603
607
  return new Intl.DateTimeFormat("en-us", {
604
608
  weekday: "long",
@@ -609,7 +613,7 @@ function Ut(n) {
609
613
  hour12: !0
610
614
  }).format(e);
611
615
  }
612
- function Pt(n) {
616
+ function Ht(n) {
613
617
  return new m((e, t, r) => {
614
618
  const o = new XMLHttpRequest(), s = new FormData();
615
619
  s.append("file", n.file), o.withCredentials = !!n.withCredentials, Object.entries(n.headers || {}).forEach(([i, d]) => o.setRequestHeader(i, d)), o.upload.addEventListener("progress", (i) => i.lengthComputable ? r(i.loaded / i.total) : null), o.upload.addEventListener("load", (i) => e(i)), o.upload.addEventListener("error", (i) => t(i)), o.open("POST", n.url), o.send(s);
@@ -617,56 +621,57 @@ function Pt(n) {
617
621
  }
618
622
  export {
619
623
  B as ASet,
620
- Q as BadRequestError,
621
- Bt as CliBackground,
624
+ _ as BadRequestError,
625
+ Rt as CliBackground,
622
626
  A as CliEffects,
623
- S as CliForeground,
627
+ C as CliForeground,
624
628
  w as CustomError,
625
- tt as ForbiddenError,
629
+ et as ForbiddenError,
626
630
  H as Http,
627
- nt as InternalServerError,
628
- rt as LOG_LEVEL,
631
+ rt as InternalServerError,
632
+ ot as LOG_LEVEL,
629
633
  Y as Logger,
630
- et as NotFoundError,
634
+ nt as NotFoundError,
631
635
  m as PromiseProgress,
632
636
  F as TypedEmitter,
633
- _ as UnauthorizedError,
634
- yt as addUnique,
635
- gt as arrayDiff,
636
- Et as caseInsensitiveSort,
637
+ tt as UnauthorizedError,
638
+ gt as addUnique,
639
+ Et as arrayDiff,
640
+ mt as caseInsensitiveSort,
637
641
  J as clean,
638
642
  Ot as countChars,
639
643
  Ct as createHex,
640
- Rt as dec2Frac,
641
- ft as deepCopy,
644
+ bt as dec2Frac,
645
+ dt as deepCopy,
642
646
  K as deepMerge,
643
- L as dotNotation,
644
- At as download,
645
- wt as findByProp,
647
+ S as dotNotation,
648
+ Q as download,
649
+ Bt as downloadBlob,
650
+ xt as findByProp,
646
651
  Z as flattenArr,
647
652
  V as flattenObj,
648
- jt as formEncode,
649
- Ut as formatDate,
653
+ kt as formEncode,
654
+ Pt as formatDate,
650
655
  St as formatPhoneNumber,
651
- bt as fracToDec,
652
- kt as gravatar,
656
+ Lt as fracToDec,
657
+ Gt as gravatar,
653
658
  P as includes,
654
- Lt as insertAt,
659
+ Nt as insertAt,
655
660
  R as isEqual,
656
- xt as makeArray,
661
+ At as makeArray,
657
662
  X as makeUnique,
658
- $t as matchAll,
659
- st as md5,
660
- dt as mixin,
661
- Nt as pad,
662
- It as randomString,
663
- Tt as randomStringBuilder,
664
- pt as sanitizedJSON,
663
+ Dt as matchAll,
664
+ it as md5,
665
+ pt as mixin,
666
+ It as pad,
667
+ Tt as randomString,
668
+ $t as randomStringBuilder,
669
+ yt as sanitizedJSON,
665
670
  qt as sleep,
666
- mt as sortByProp,
671
+ wt as sortByProp,
667
672
  Mt as timeUntil,
668
- Pt as uploadWithProgress,
669
- Gt as urlParser,
670
- Dt as validateEmail
673
+ Ht as uploadWithProgress,
674
+ Ut as urlParser,
675
+ jt as validateEmail
671
676
  };
672
677
  //# sourceMappingURL=utils.mjs.map