@ztimson/utils 0.16.8 → 0.16.10

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
@@ -237,6 +237,8 @@ class Nt {
237
237
  });
238
238
  }
239
239
  getKey(t) {
240
+ if (!this.key)
241
+ throw new Error("No key defined");
240
242
  return t[this.key];
241
243
  }
242
244
  /**
@@ -299,6 +301,14 @@ class Nt {
299
301
  keys() {
300
302
  return Object.keys(this.store);
301
303
  }
304
+ /**
305
+ * Get map of cached items
306
+ *
307
+ * @return {Record<K, T>}
308
+ */
309
+ map() {
310
+ return structuredClone(this.store);
311
+ }
302
312
  /**
303
313
  * Add an item to the cache manually specifying the key
304
314
  *
@@ -363,7 +373,7 @@ class E extends Promise {
363
373
  return this.from(super.finally(e));
364
374
  }
365
375
  }
366
- function It(r, t) {
376
+ function jt(r, t) {
367
377
  r instanceof Blob || (r = new Blob(ut(r)));
368
378
  const e = URL.createObjectURL(r);
369
379
  at(e, t), URL.revokeObjectURL(e);
@@ -372,7 +382,7 @@ function at(r, t) {
372
382
  const e = document.createElement("a");
373
383
  e.href = r, e.download = t || r.split("/").pop(), document.body.appendChild(e), e.click(), document.body.removeChild(e);
374
384
  }
375
- function jt(r = {}) {
385
+ function It(r = {}) {
376
386
  return new Promise((t) => {
377
387
  const e = document.createElement("input");
378
388
  e.type = "file", e.accept = r.accept || "*", e.style.display = "none", e.multiple = !!r.multiple, e.onblur = e.onchange = async () => {
@@ -380,12 +390,12 @@ function jt(r = {}) {
380
390
  }, document.body.appendChild(e), e.click();
381
391
  });
382
392
  }
383
- function Mt(r, t = /* @__PURE__ */ new Date()) {
393
+ function Dt(r, t = /* @__PURE__ */ new Date()) {
384
394
  (typeof t == "number" || typeof t == "string") && (t = new Date(t));
385
395
  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")}`;
386
396
  return r ? r.replace("{{TIMESTAMP}}", e) : e;
387
397
  }
388
- function Dt(r) {
398
+ function Mt(r) {
389
399
  return new E((t, e, n) => {
390
400
  const o = new XMLHttpRequest(), s = new FormData();
391
401
  r.files.forEach((i) => s.append("file", i)), o.withCredentials = !!r.withCredentials, o.upload.addEventListener("progress", (i) => i.lengthComputable ? n(i.loaded / i.total) : null), o.addEventListener("loadend", () => t(T(o.responseText))), o.addEventListener("error", () => e(T(o.responseText))), o.addEventListener("timeout", () => e({ error: "Request timed out" })), o.open("POST", r.url), Object.entries(r.headers || {}).forEach(([i, y]) => o.setRequestHeader(i, y)), o.send(s);
@@ -497,7 +507,7 @@ class z extends p {
497
507
  }
498
508
  }
499
509
  c(z, "code", 403);
500
- class J extends p {
510
+ class K extends p {
501
511
  constructor(t = "Not Found") {
502
512
  super(t);
503
513
  }
@@ -505,8 +515,8 @@ class J extends p {
505
515
  return t.constructor.code == this.code;
506
516
  }
507
517
  }
508
- c(J, "code", 404);
509
- class K extends p {
518
+ c(K, "code", 404);
519
+ class J extends p {
510
520
  constructor(t = "Method Not Allowed") {
511
521
  super(t);
512
522
  }
@@ -514,7 +524,7 @@ class K extends p {
514
524
  return t.constructor.code == this.code;
515
525
  }
516
526
  }
517
- c(K, "code", 405);
527
+ c(J, "code", 405);
518
528
  class Z extends p {
519
529
  constructor(t = "Not Acceptable") {
520
530
  super(t);
@@ -582,9 +592,9 @@ function kt(r, t) {
582
592
  case 403:
583
593
  return new z(t);
584
594
  case 404:
585
- return new J(t);
586
- case 405:
587
595
  return new K(t);
596
+ case 405:
597
+ return new J(t);
588
598
  case 406:
589
599
  return new Z(t);
590
600
  case 500:
@@ -645,14 +655,14 @@ const w = class w {
645
655
  for (let a of [...Object.values(w.interceptors), ...Object.values(this.interceptors)])
646
656
  await new Promise((O) => a(u, () => O()));
647
657
  const R = u.headers.get("Content-Length"), L = R ? parseInt(R, 10) : 0;
648
- let D = 0;
658
+ let M = 0;
649
659
  const N = (k = u.body) == null ? void 0 : k.getReader(), et = new ReadableStream({
650
660
  start(a) {
651
661
  function O() {
652
662
  N == null || N.read().then((B) => {
653
663
  if (B.done)
654
664
  return a.close();
655
- D += B.value.byteLength, y(D / L), a.enqueue(B.value), O();
665
+ M += B.value.byteLength, y(M / L), a.enqueue(B.value), O();
656
666
  }).catch((B) => a.error(B));
657
667
  }
658
668
  O();
@@ -671,7 +681,7 @@ c(w, "interceptors", {}), c(w, "headers", {});
671
681
  let P = w;
672
682
  function Ut(r) {
673
683
  const t = r.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
674
- return T(decodeURIComponent(window.atob(t).split("").map(function(e) {
684
+ return T(decodeURIComponent(atob(t).split("").map(function(e) {
675
685
  return "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2);
676
686
  }).join("")));
677
687
  }
@@ -773,7 +783,7 @@ function qt(r) {
773
783
  const e = t.length == 2 ? Number(t[0]) : 0;
774
784
  return t = t.pop().split("/"), e + Number(t[0]) / Number(t[1]);
775
785
  }
776
- const I = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", j = "0123456789", M = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", ht = I + j + M;
786
+ const j = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", I = "0123456789", D = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", ht = j + I + D;
777
787
  function Ft(r, t = 2) {
778
788
  if (r === 0)
779
789
  return "0 Bytes";
@@ -801,19 +811,19 @@ function zt(r, t = ht) {
801
811
  return t[e];
802
812
  }).join("");
803
813
  }
804
- function Jt(r, t = !1, e = !1, n = !1) {
814
+ function Kt(r, t = !1, e = !1, n = !1) {
805
815
  if (!t && !e && !n)
806
816
  throw new Error("Must enable at least one: letters, numbers, symbols");
807
817
  return Array(r).fill(null).map(() => {
808
818
  let o;
809
819
  do {
810
820
  const s = ~~(Math.random() * 3);
811
- t && s == 0 ? o = I[~~(Math.random() * I.length)] : e && s == 1 ? o = j[~~(Math.random() * j.length)] : n && s == 2 && (o = M[~~(Math.random() * M.length)]);
821
+ t && s == 0 ? o = j[~~(Math.random() * j.length)] : e && s == 1 ? o = I[~~(Math.random() * I.length)] : n && s == 2 && (o = D[~~(Math.random() * D.length)]);
812
822
  } while (!o);
813
823
  return o;
814
824
  }).join("");
815
825
  }
816
- function Kt(r, t) {
826
+ function Jt(r, t) {
817
827
  if (typeof t == "string" && (t = new RegExp(t, "g")), !t.global)
818
828
  throw new TypeError("Regular expression must be global.");
819
829
  let e = [], n;
@@ -927,9 +937,9 @@ export {
927
937
  bt as JSONSanitize,
928
938
  lt as LOG_LEVEL,
929
939
  q as Logger,
930
- K as MethodNotAllowedError,
940
+ J as MethodNotAllowedError,
931
941
  Z as NotAcceptableError,
932
- J as NotFoundError,
942
+ K as NotFoundError,
933
943
  X as NotImplementedError,
934
944
  W as PaymentRequiredError,
935
945
  E as PromiseProgress,
@@ -942,15 +952,14 @@ export {
942
952
  ot as clean,
943
953
  Tt as csv,
944
954
  Pt as dec2Frac,
945
- Ut as decodeJwt,
946
955
  xt as deepCopy,
947
956
  st as deepMerge,
948
957
  x as dotNotation,
949
- It as downloadFile,
958
+ jt as downloadFile,
950
959
  at as downloadUrl,
951
960
  Bt as encodeQuery,
952
961
  kt as errorFromCode,
953
- jt as fileBrowser,
962
+ It as fileBrowser,
954
963
  $t as findByProp,
955
964
  it as flattenArr,
956
965
  F as flattenObj,
@@ -963,23 +972,24 @@ export {
963
972
  G as includes,
964
973
  Yt as insertAt,
965
974
  b as isEqual,
975
+ Ut as jwtDecode,
966
976
  ut as makeArray,
967
977
  ct as makeUnique,
968
- Kt as matchAll,
978
+ Jt as matchAll,
969
979
  ft as md5,
970
980
  At as mixin,
971
981
  Ht as pad,
972
982
  Zt as parseUrl,
973
983
  Wt as randomHex,
974
984
  zt as randomString,
975
- Jt as randomStringBuilder,
985
+ Kt as randomStringBuilder,
976
986
  mt as sleep,
977
987
  _t as sleepUntil,
978
988
  Lt as sortByProp,
979
989
  te as timeUntil,
980
- Mt as timestampFilename,
990
+ Dt as timestampFilename,
981
991
  ee as tyoeKeys,
982
- Dt as uploadWithProgress,
992
+ Mt as uploadWithProgress,
983
993
  Vt as validateEmail
984
994
  };
985
995
  //# sourceMappingURL=index.mjs.map