@ztimson/utils 0.25.9 → 0.25.12

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
@@ -543,10 +543,7 @@ class Cache {
543
543
  if (options.storage instanceof Table) {
544
544
  (async () => {
545
545
  var _a2;
546
- return (await ((_a2 = options.storage) == null ? void 0 : _a2.getAll())).forEach((v) => {
547
- console.log(v);
548
- this.add(v);
549
- });
546
+ return (await ((_a2 = options.storage) == null ? void 0 : _a2.getAll())).forEach((v) => this.add(v));
550
547
  })();
551
548
  } else if (options.storageKey) {
552
549
  const stored = (_a = options.storage) == null ? void 0 : _a.getItem(options.storageKey);
@@ -1094,6 +1091,32 @@ async function sleepWhile(fn2, checkInterval = 100) {
1094
1091
  function timeUntil(date) {
1095
1092
  return (date instanceof Date ? date.getTime() : date) - (/* @__PURE__ */ new Date()).getTime();
1096
1093
  }
1094
+ function timezoneOffset(tz, date = /* @__PURE__ */ new Date()) {
1095
+ const dtf = new Intl.DateTimeFormat("en-US", {
1096
+ timeZone: tz,
1097
+ hour12: false,
1098
+ year: "numeric",
1099
+ month: "2-digit",
1100
+ day: "2-digit",
1101
+ hour: "2-digit",
1102
+ minute: "2-digit",
1103
+ second: "2-digit"
1104
+ });
1105
+ const parts = dtf.formatToParts(date);
1106
+ const get = (type) => {
1107
+ var _a;
1108
+ return Number((_a = parts.find((v) => v.type === type)) == null ? void 0 : _a.value);
1109
+ };
1110
+ const y = get("year");
1111
+ const mo = get("month");
1112
+ const d = get("day");
1113
+ const h = get("hour");
1114
+ const m = get("minute");
1115
+ const s = get("second");
1116
+ const asUTC = Date.UTC(y, mo - 1, d, h, m, s);
1117
+ const asLocal = date.getTime();
1118
+ return Math.round((asLocal - asUTC) / 6e4);
1119
+ }
1097
1120
  function downloadFile(blob, name) {
1098
1121
  if (!(blob instanceof Blob)) blob = new Blob(makeArray(blob));
1099
1122
  const url = URL.createObjectURL(blob);
@@ -1629,7 +1652,7 @@ function PES(str, ...args) {
1629
1652
  if (str[i]) combined.push(str[i]);
1630
1653
  if (args[i]) combined.push(args[i]);
1631
1654
  }
1632
- const [paths, methods] = combined.join("").split(":");
1655
+ const [paths, methods] = combined.join("/").split(":");
1633
1656
  return PathEvent.toString(paths, methods == null ? void 0 : methods.split(""));
1634
1657
  }
1635
1658
  class PathError extends Error {
@@ -1824,8 +1847,8 @@ class PathEventEmitter {
1824
1847
  this.prefix = prefix;
1825
1848
  }
1826
1849
  emit(event, ...args) {
1827
- const parsed = new PathEvent(`${this.prefix}/${new PathEvent(event).toString()}`);
1828
- this.listeners.filter((l) => PathEvent.has(l[0], `${this.prefix}/${event}`)).forEach(async (l) => l[1](parsed, ...args));
1850
+ const parsed = PE`${this.prefix}/${event}`;
1851
+ this.listeners.filter((l) => PathEvent.has(l[0], parsed)).forEach(async (l) => l[1](parsed, ...args));
1829
1852
  }
1830
1853
  off(listener) {
1831
1854
  this.listeners = this.listeners.filter((l) => l[1] != listener);
@@ -2168,6 +2191,7 @@ export {
2168
2191
  strSplice,
2169
2192
  timeUntil,
2170
2193
  timestampFilename,
2194
+ timezoneOffset,
2171
2195
  toCsv,
2172
2196
  uploadWithProgress,
2173
2197
  validateEmail,