@ztimson/utils 0.25.10 → 0.25.13

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
@@ -644,6 +644,15 @@ class Cache {
644
644
  } else this.delete(key);
645
645
  return this;
646
646
  }
647
+ /**
648
+ * Find the first cached item to match a filter
649
+ * @param {Partial<T>} filter Partial item to match
650
+ * @param {Boolean} expired Include expired items, defaults to false
651
+ * @returns {T | undefined} Cached item or undefined if nothing matched
652
+ */
653
+ find(filter, expired) {
654
+ return Object.values(this.store).find((row) => (expired || !row._expired) && includes(row, filter));
655
+ }
647
656
  /**
648
657
  * Get item from the cache
649
658
  * @param {K} key Key to lookup
@@ -1091,6 +1100,32 @@ async function sleepWhile(fn2, checkInterval = 100) {
1091
1100
  function timeUntil(date) {
1092
1101
  return (date instanceof Date ? date.getTime() : date) - (/* @__PURE__ */ new Date()).getTime();
1093
1102
  }
1103
+ function timezoneOffset(tz, date = /* @__PURE__ */ new Date()) {
1104
+ const dtf = new Intl.DateTimeFormat("en-US", {
1105
+ timeZone: tz,
1106
+ hour12: false,
1107
+ year: "numeric",
1108
+ month: "2-digit",
1109
+ day: "2-digit",
1110
+ hour: "2-digit",
1111
+ minute: "2-digit",
1112
+ second: "2-digit"
1113
+ });
1114
+ const parts = dtf.formatToParts(date);
1115
+ const get = (type) => {
1116
+ var _a;
1117
+ return Number((_a = parts.find((v) => v.type === type)) == null ? void 0 : _a.value);
1118
+ };
1119
+ const y = get("year");
1120
+ const mo = get("month");
1121
+ const d = get("day");
1122
+ const h = get("hour");
1123
+ const m = get("minute");
1124
+ const s = get("second");
1125
+ const asUTC = Date.UTC(y, mo - 1, d, h, m, s);
1126
+ const asLocal = date.getTime();
1127
+ return Math.round((asLocal - asUTC) / 6e4);
1128
+ }
1094
1129
  function downloadFile(blob, name) {
1095
1130
  if (!(blob instanceof Blob)) blob = new Blob(makeArray(blob));
1096
1131
  const url = URL.createObjectURL(blob);
@@ -1626,7 +1661,7 @@ function PES(str, ...args) {
1626
1661
  if (str[i]) combined.push(str[i]);
1627
1662
  if (args[i]) combined.push(args[i]);
1628
1663
  }
1629
- const [paths, methods] = combined.join("").split(":");
1664
+ const [paths, methods] = combined.join("/").split(":");
1630
1665
  return PathEvent.toString(paths, methods == null ? void 0 : methods.split(""));
1631
1666
  }
1632
1667
  class PathError extends Error {
@@ -1821,8 +1856,8 @@ class PathEventEmitter {
1821
1856
  this.prefix = prefix;
1822
1857
  }
1823
1858
  emit(event, ...args) {
1824
- const parsed = new PathEvent(`${this.prefix}/${new PathEvent(event).toString()}`);
1825
- this.listeners.filter((l) => PathEvent.has(l[0], `${this.prefix}/${event}`)).forEach(async (l) => l[1](parsed, ...args));
1859
+ const parsed = PE`${this.prefix}/${event}`;
1860
+ this.listeners.filter((l) => PathEvent.has(l[0], parsed)).forEach(async (l) => l[1](parsed, ...args));
1826
1861
  }
1827
1862
  off(listener) {
1828
1863
  this.listeners = this.listeners.filter((l) => l[1] != listener);
@@ -2165,6 +2200,7 @@ export {
2165
2200
  strSplice,
2166
2201
  timeUntil,
2167
2202
  timestampFilename,
2203
+ timezoneOffset,
2168
2204
  toCsv,
2169
2205
  uploadWithProgress,
2170
2206
  validateEmail,