@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.cjs +31 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +31 -7
- package/dist/index.mjs.map +1 -1
- package/dist/time.d.ts +7 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -547,10 +547,7 @@ ${opts.message || this.desc}`;
|
|
|
547
547
|
if (options.storage instanceof Table) {
|
|
548
548
|
(async () => {
|
|
549
549
|
var _a2;
|
|
550
|
-
return (await ((_a2 = options.storage) == null ? void 0 : _a2.getAll())).forEach((v) =>
|
|
551
|
-
console.log(v);
|
|
552
|
-
this.add(v);
|
|
553
|
-
});
|
|
550
|
+
return (await ((_a2 = options.storage) == null ? void 0 : _a2.getAll())).forEach((v) => this.add(v));
|
|
554
551
|
})();
|
|
555
552
|
} else if (options.storageKey) {
|
|
556
553
|
const stored = (_a = options.storage) == null ? void 0 : _a.getItem(options.storageKey);
|
|
@@ -1098,6 +1095,32 @@ ${opts.message || this.desc}`;
|
|
|
1098
1095
|
function timeUntil(date) {
|
|
1099
1096
|
return (date instanceof Date ? date.getTime() : date) - (/* @__PURE__ */ new Date()).getTime();
|
|
1100
1097
|
}
|
|
1098
|
+
function timezoneOffset(tz, date = /* @__PURE__ */ new Date()) {
|
|
1099
|
+
const dtf = new Intl.DateTimeFormat("en-US", {
|
|
1100
|
+
timeZone: tz,
|
|
1101
|
+
hour12: false,
|
|
1102
|
+
year: "numeric",
|
|
1103
|
+
month: "2-digit",
|
|
1104
|
+
day: "2-digit",
|
|
1105
|
+
hour: "2-digit",
|
|
1106
|
+
minute: "2-digit",
|
|
1107
|
+
second: "2-digit"
|
|
1108
|
+
});
|
|
1109
|
+
const parts = dtf.formatToParts(date);
|
|
1110
|
+
const get = (type) => {
|
|
1111
|
+
var _a;
|
|
1112
|
+
return Number((_a = parts.find((v) => v.type === type)) == null ? void 0 : _a.value);
|
|
1113
|
+
};
|
|
1114
|
+
const y = get("year");
|
|
1115
|
+
const mo = get("month");
|
|
1116
|
+
const d = get("day");
|
|
1117
|
+
const h = get("hour");
|
|
1118
|
+
const m = get("minute");
|
|
1119
|
+
const s = get("second");
|
|
1120
|
+
const asUTC = Date.UTC(y, mo - 1, d, h, m, s);
|
|
1121
|
+
const asLocal = date.getTime();
|
|
1122
|
+
return Math.round((asLocal - asUTC) / 6e4);
|
|
1123
|
+
}
|
|
1101
1124
|
function downloadFile(blob, name) {
|
|
1102
1125
|
if (!(blob instanceof Blob)) blob = new Blob(makeArray(blob));
|
|
1103
1126
|
const url = URL.createObjectURL(blob);
|
|
@@ -1633,7 +1656,7 @@ ${opts.message || this.desc}`;
|
|
|
1633
1656
|
if (str[i]) combined.push(str[i]);
|
|
1634
1657
|
if (args[i]) combined.push(args[i]);
|
|
1635
1658
|
}
|
|
1636
|
-
const [paths, methods] = combined.join("").split(":");
|
|
1659
|
+
const [paths, methods] = combined.join("/").split(":");
|
|
1637
1660
|
return PathEvent.toString(paths, methods == null ? void 0 : methods.split(""));
|
|
1638
1661
|
}
|
|
1639
1662
|
class PathError extends Error {
|
|
@@ -1828,8 +1851,8 @@ ${opts.message || this.desc}`;
|
|
|
1828
1851
|
this.prefix = prefix;
|
|
1829
1852
|
}
|
|
1830
1853
|
emit(event, ...args) {
|
|
1831
|
-
const parsed =
|
|
1832
|
-
this.listeners.filter((l) => PathEvent.has(l[0],
|
|
1854
|
+
const parsed = PE`${this.prefix}/${event}`;
|
|
1855
|
+
this.listeners.filter((l) => PathEvent.has(l[0], parsed)).forEach(async (l) => l[1](parsed, ...args));
|
|
1833
1856
|
}
|
|
1834
1857
|
off(listener) {
|
|
1835
1858
|
this.listeners = this.listeners.filter((l) => l[1] != listener);
|
|
@@ -2171,6 +2194,7 @@ ${opts.message || this.desc}`;
|
|
|
2171
2194
|
exports2.strSplice = strSplice;
|
|
2172
2195
|
exports2.timeUntil = timeUntil;
|
|
2173
2196
|
exports2.timestampFilename = timestampFilename;
|
|
2197
|
+
exports2.timezoneOffset = timezoneOffset;
|
|
2174
2198
|
exports2.toCsv = toCsv;
|
|
2175
2199
|
exports2.uploadWithProgress = uploadWithProgress;
|
|
2176
2200
|
exports2.validateEmail = validateEmail;
|