@ztimson/utils 0.24.1 → 0.24.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/index.mjs CHANGED
@@ -906,15 +906,15 @@ function formatDate(format = "YYYY-MM-DD H:mm", date = /* @__PURE__ */ new Date(
906
906
  };
907
907
  return format.replace(/YYYY|YY|MMMM|MMM|MM|M|DDD|DD|Do|D|dddd|ddd|HH|H|hh|h|mm|m|ss|s|SSS|A|a|ZZ|Z|z/g, (token) => tokens[token]);
908
908
  }
909
- function instantInterval(fn, interval) {
910
- fn();
911
- return setInterval(fn, interval);
909
+ function instantInterval(fn2, interval) {
910
+ fn2();
911
+ return setInterval(fn2, interval);
912
912
  }
913
913
  function sleep(ms) {
914
914
  return new Promise((res) => setTimeout(res, ms));
915
915
  }
916
- async function sleepWhile(fn, checkInterval = 100) {
917
- while (await fn()) await sleep(checkInterval);
916
+ async function sleepWhile(fn2, checkInterval = 100) {
917
+ while (await fn2()) await sleep(checkInterval);
918
918
  }
919
919
  function timeUntil(date) {
920
920
  return (date instanceof Date ? date.getTime() : date) - (/* @__PURE__ */ new Date()).getTime();
@@ -1225,16 +1225,16 @@ const _Http = class _Http {
1225
1225
  defaults.interceptors.forEach((i) => _Http.addInterceptor(i));
1226
1226
  }
1227
1227
  }
1228
- static addInterceptor(fn) {
1228
+ static addInterceptor(fn2) {
1229
1229
  const key = Object.keys(_Http.interceptors).length.toString();
1230
- _Http.interceptors[key] = fn;
1230
+ _Http.interceptors[key] = fn2;
1231
1231
  return () => {
1232
1232
  _Http.interceptors[key] = null;
1233
1233
  };
1234
1234
  }
1235
- addInterceptor(fn) {
1235
+ addInterceptor(fn2) {
1236
1236
  const key = Object.keys(this.interceptors).length.toString();
1237
- this.interceptors[key] = fn;
1237
+ this.interceptors[key] = fn2;
1238
1238
  return () => {
1239
1239
  this.interceptors[key] = null;
1240
1240
  };
@@ -1265,8 +1265,8 @@ const _Http = class _Http {
1265
1265
  body: opts.body
1266
1266
  }).then(async (resp) => {
1267
1267
  var _a2, _b;
1268
- for (let fn of [...Object.values(_Http.interceptors), ...Object.values(this.interceptors)]) {
1269
- await new Promise((res2) => fn(resp, () => res2()));
1268
+ for (let fn2 of [...Object.values(_Http.interceptors), ...Object.values(this.interceptors)]) {
1269
+ await new Promise((res2) => fn2(resp, () => res2()));
1270
1270
  }
1271
1271
  const contentLength = resp.headers.get("Content-Length");
1272
1272
  const total = contentLength ? parseInt(contentLength, 10) : 0;
@@ -1422,9 +1422,9 @@ function fracToDec(frac) {
1422
1422
  split = split.pop().split("/");
1423
1423
  return whole + Number(split[0]) / Number(split[1]);
1424
1424
  }
1425
- function asyncFunction(args, fn) {
1425
+ function fn(args, fn2, async = false) {
1426
1426
  const keys = Object.keys(args);
1427
- return new Function(...keys, `return (async (${keys.join(",")}) => { ${fn} })(${keys.join(",")})`)(...keys.map((k) => args[k]));
1427
+ return new Function(...keys, `return (${async ? "async " : ""}(${keys.join(",")}) => { ${fn2} })(${keys.join(",")})`)(...keys.map((k) => args[k]));
1428
1428
  }
1429
1429
  function gravatar(email, def = "mp") {
1430
1430
  if (!email) return "";
@@ -1439,7 +1439,7 @@ function PE(str, ...args) {
1439
1439
  if (str[i]) combined.push(str[i]);
1440
1440
  if (args[i]) combined.push(args[i]);
1441
1441
  }
1442
- return new PathEvent(combined.join(""));
1442
+ return new PathEvent(combined.join("/"));
1443
1443
  }
1444
1444
  function PES(str, ...args) {
1445
1445
  let combined = [];
@@ -1498,28 +1498,28 @@ class PathEvent {
1498
1498
  return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("c"));
1499
1499
  }
1500
1500
  set create(v) {
1501
- v ? this.methods.delete("n").add("c") : this.methods.delete("c");
1501
+ v ? this.methods.delete("n").delete("*").add("c") : this.methods.delete("c");
1502
1502
  }
1503
1503
  /** Read method specified */
1504
1504
  get read() {
1505
1505
  return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("r"));
1506
1506
  }
1507
1507
  set read(v) {
1508
- v ? this.methods.delete("n").add("r") : this.methods.delete("r");
1508
+ v ? this.methods.delete("n").delete("*").add("r") : this.methods.delete("r");
1509
1509
  }
1510
1510
  /** Update method specified */
1511
1511
  get update() {
1512
1512
  return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("u"));
1513
1513
  }
1514
1514
  set update(v) {
1515
- v ? this.methods.delete("n").add("u") : this.methods.delete("u");
1515
+ v ? this.methods.delete("n").delete("*").add("u") : this.methods.delete("u");
1516
1516
  }
1517
1517
  /** Delete method specified */
1518
1518
  get delete() {
1519
1519
  return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("d"));
1520
1520
  }
1521
1521
  set delete(v) {
1522
- v ? this.methods.delete("n").add("d") : this.methods.delete("d");
1522
+ v ? this.methods.delete("n").delete("*").add("d") : this.methods.delete("d");
1523
1523
  }
1524
1524
  /**
1525
1525
  * Combine multiple events into one parsed object. Longest path takes precedent, but all subsequent methods are
@@ -1677,11 +1677,11 @@ function search(rows, search2, regex, transform = (r) => r) {
1677
1677
  }
1678
1678
  }).length;
1679
1679
  } else {
1680
- return testCondition(search2, r);
1680
+ return logicTest(r, search2);
1681
1681
  }
1682
1682
  });
1683
1683
  }
1684
- function testCondition(condition, row) {
1684
+ function logicTest(target, condition) {
1685
1685
  const evalBoolean = (a, op, b) => {
1686
1686
  switch (op) {
1687
1687
  case "=":
@@ -1707,10 +1707,10 @@ function testCondition(condition, row) {
1707
1707
  return and.filter((p2) => {
1708
1708
  const prop = /(\S+)\s*(==?|!=|>=|>|<=|<)\s*(\S+)/g.exec(p2);
1709
1709
  if (prop) {
1710
- const key = Object.keys(row).find((k) => k.toLowerCase() == prop[1].toLowerCase());
1711
- return evalBoolean(dotNotation(row, key || prop[1]), prop[2], JSONAttemptParse(prop[3]));
1710
+ const key = Object.keys(target).find((k) => k.toLowerCase() == prop[1].toLowerCase());
1711
+ return evalBoolean(dotNotation(target, key || prop[1]), prop[2], JSONAttemptParse(prop[3]));
1712
1712
  }
1713
- const v = Object.values(row).map((v2) => typeof v2 == "object" && v2 != null ? JSON.stringify(v2) : v2).join("");
1713
+ const v = Object.values(target).map(JSONSerialize).join("");
1714
1714
  if (/[A-Z]/g.test(condition)) return v.includes(p2);
1715
1715
  return v.toLowerCase().includes(p2);
1716
1716
  }).length == and.length;
@@ -1759,7 +1759,6 @@ export {
1759
1759
  addUnique,
1760
1760
  adjustedInterval,
1761
1761
  arrayDiff,
1762
- asyncFunction,
1763
1762
  blackOrWhite,
1764
1763
  camelCase,
1765
1764
  caseInsensitiveSort,
@@ -1779,6 +1778,7 @@ export {
1779
1778
  findByProp,
1780
1779
  flattenArr,
1781
1780
  flattenObj,
1781
+ fn,
1782
1782
  formData,
1783
1783
  formatBytes,
1784
1784
  formatDate,
@@ -1791,6 +1791,7 @@ export {
1791
1791
  instantInterval,
1792
1792
  isEqual,
1793
1793
  kebabCase,
1794
+ logicTest,
1794
1795
  makeArray,
1795
1796
  makeUnique,
1796
1797
  matchAll,
@@ -1808,7 +1809,6 @@ export {
1808
1809
  snakeCase,
1809
1810
  sortByProp,
1810
1811
  strSplice,
1811
- testCondition,
1812
1812
  timeUntil,
1813
1813
  timestampFilename,
1814
1814
  toCsv,