@ztimson/utils 0.25.10 → 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 +30 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +30 -3
- package/dist/index.mjs.map +1 -1
- package/dist/time.d.ts +7 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1095,6 +1095,32 @@ ${opts.message || this.desc}`;
|
|
|
1095
1095
|
function timeUntil(date) {
|
|
1096
1096
|
return (date instanceof Date ? date.getTime() : date) - (/* @__PURE__ */ new Date()).getTime();
|
|
1097
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
|
+
}
|
|
1098
1124
|
function downloadFile(blob, name) {
|
|
1099
1125
|
if (!(blob instanceof Blob)) blob = new Blob(makeArray(blob));
|
|
1100
1126
|
const url = URL.createObjectURL(blob);
|
|
@@ -1630,7 +1656,7 @@ ${opts.message || this.desc}`;
|
|
|
1630
1656
|
if (str[i]) combined.push(str[i]);
|
|
1631
1657
|
if (args[i]) combined.push(args[i]);
|
|
1632
1658
|
}
|
|
1633
|
-
const [paths, methods] = combined.join("").split(":");
|
|
1659
|
+
const [paths, methods] = combined.join("/").split(":");
|
|
1634
1660
|
return PathEvent.toString(paths, methods == null ? void 0 : methods.split(""));
|
|
1635
1661
|
}
|
|
1636
1662
|
class PathError extends Error {
|
|
@@ -1825,8 +1851,8 @@ ${opts.message || this.desc}`;
|
|
|
1825
1851
|
this.prefix = prefix;
|
|
1826
1852
|
}
|
|
1827
1853
|
emit(event, ...args) {
|
|
1828
|
-
const parsed =
|
|
1829
|
-
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));
|
|
1830
1856
|
}
|
|
1831
1857
|
off(listener) {
|
|
1832
1858
|
this.listeners = this.listeners.filter((l) => l[1] != listener);
|
|
@@ -2168,6 +2194,7 @@ ${opts.message || this.desc}`;
|
|
|
2168
2194
|
exports2.strSplice = strSplice;
|
|
2169
2195
|
exports2.timeUntil = timeUntil;
|
|
2170
2196
|
exports2.timestampFilename = timestampFilename;
|
|
2197
|
+
exports2.timezoneOffset = timezoneOffset;
|
|
2171
2198
|
exports2.toCsv = toCsv;
|
|
2172
2199
|
exports2.uploadWithProgress = uploadWithProgress;
|
|
2173
2200
|
exports2.validateEmail = validateEmail;
|