@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/cache.d.ts +7 -0
- package/dist/index.cjs +39 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +39 -3
- package/dist/index.mjs.map +1 -1
- package/dist/time.d.ts +7 -0
- package/package.json +1 -1
package/dist/cache.d.ts
CHANGED
|
@@ -69,6 +69,13 @@ export declare class Cache<K extends string | number | symbol, T> {
|
|
|
69
69
|
* @param {K} key Key to expire
|
|
70
70
|
*/
|
|
71
71
|
expire(key: K): this;
|
|
72
|
+
/**
|
|
73
|
+
* Find the first cached item to match a filter
|
|
74
|
+
* @param {Partial<T>} filter Partial item to match
|
|
75
|
+
* @param {Boolean} expired Include expired items, defaults to false
|
|
76
|
+
* @returns {T | undefined} Cached item or undefined if nothing matched
|
|
77
|
+
*/
|
|
78
|
+
find(filter: Partial<T>, expired?: boolean): T | undefined;
|
|
72
79
|
/**
|
|
73
80
|
* Get item from the cache
|
|
74
81
|
* @param {K} key Key to lookup
|
package/dist/index.cjs
CHANGED
|
@@ -648,6 +648,15 @@ ${opts.message || this.desc}`;
|
|
|
648
648
|
} else this.delete(key);
|
|
649
649
|
return this;
|
|
650
650
|
}
|
|
651
|
+
/**
|
|
652
|
+
* Find the first cached item to match a filter
|
|
653
|
+
* @param {Partial<T>} filter Partial item to match
|
|
654
|
+
* @param {Boolean} expired Include expired items, defaults to false
|
|
655
|
+
* @returns {T | undefined} Cached item or undefined if nothing matched
|
|
656
|
+
*/
|
|
657
|
+
find(filter, expired) {
|
|
658
|
+
return Object.values(this.store).find((row) => (expired || !row._expired) && includes(row, filter));
|
|
659
|
+
}
|
|
651
660
|
/**
|
|
652
661
|
* Get item from the cache
|
|
653
662
|
* @param {K} key Key to lookup
|
|
@@ -1095,6 +1104,32 @@ ${opts.message || this.desc}`;
|
|
|
1095
1104
|
function timeUntil(date) {
|
|
1096
1105
|
return (date instanceof Date ? date.getTime() : date) - (/* @__PURE__ */ new Date()).getTime();
|
|
1097
1106
|
}
|
|
1107
|
+
function timezoneOffset(tz, date = /* @__PURE__ */ new Date()) {
|
|
1108
|
+
const dtf = new Intl.DateTimeFormat("en-US", {
|
|
1109
|
+
timeZone: tz,
|
|
1110
|
+
hour12: false,
|
|
1111
|
+
year: "numeric",
|
|
1112
|
+
month: "2-digit",
|
|
1113
|
+
day: "2-digit",
|
|
1114
|
+
hour: "2-digit",
|
|
1115
|
+
minute: "2-digit",
|
|
1116
|
+
second: "2-digit"
|
|
1117
|
+
});
|
|
1118
|
+
const parts = dtf.formatToParts(date);
|
|
1119
|
+
const get = (type) => {
|
|
1120
|
+
var _a;
|
|
1121
|
+
return Number((_a = parts.find((v) => v.type === type)) == null ? void 0 : _a.value);
|
|
1122
|
+
};
|
|
1123
|
+
const y = get("year");
|
|
1124
|
+
const mo = get("month");
|
|
1125
|
+
const d = get("day");
|
|
1126
|
+
const h = get("hour");
|
|
1127
|
+
const m = get("minute");
|
|
1128
|
+
const s = get("second");
|
|
1129
|
+
const asUTC = Date.UTC(y, mo - 1, d, h, m, s);
|
|
1130
|
+
const asLocal = date.getTime();
|
|
1131
|
+
return Math.round((asLocal - asUTC) / 6e4);
|
|
1132
|
+
}
|
|
1098
1133
|
function downloadFile(blob, name) {
|
|
1099
1134
|
if (!(blob instanceof Blob)) blob = new Blob(makeArray(blob));
|
|
1100
1135
|
const url = URL.createObjectURL(blob);
|
|
@@ -1630,7 +1665,7 @@ ${opts.message || this.desc}`;
|
|
|
1630
1665
|
if (str[i]) combined.push(str[i]);
|
|
1631
1666
|
if (args[i]) combined.push(args[i]);
|
|
1632
1667
|
}
|
|
1633
|
-
const [paths, methods] = combined.join("").split(":");
|
|
1668
|
+
const [paths, methods] = combined.join("/").split(":");
|
|
1634
1669
|
return PathEvent.toString(paths, methods == null ? void 0 : methods.split(""));
|
|
1635
1670
|
}
|
|
1636
1671
|
class PathError extends Error {
|
|
@@ -1825,8 +1860,8 @@ ${opts.message || this.desc}`;
|
|
|
1825
1860
|
this.prefix = prefix;
|
|
1826
1861
|
}
|
|
1827
1862
|
emit(event, ...args) {
|
|
1828
|
-
const parsed =
|
|
1829
|
-
this.listeners.filter((l) => PathEvent.has(l[0],
|
|
1863
|
+
const parsed = PE`${this.prefix}/${event}`;
|
|
1864
|
+
this.listeners.filter((l) => PathEvent.has(l[0], parsed)).forEach(async (l) => l[1](parsed, ...args));
|
|
1830
1865
|
}
|
|
1831
1866
|
off(listener) {
|
|
1832
1867
|
this.listeners = this.listeners.filter((l) => l[1] != listener);
|
|
@@ -2168,6 +2203,7 @@ ${opts.message || this.desc}`;
|
|
|
2168
2203
|
exports2.strSplice = strSplice;
|
|
2169
2204
|
exports2.timeUntil = timeUntil;
|
|
2170
2205
|
exports2.timestampFilename = timestampFilename;
|
|
2206
|
+
exports2.timezoneOffset = timezoneOffset;
|
|
2171
2207
|
exports2.toCsv = toCsv;
|
|
2172
2208
|
exports2.uploadWithProgress = uploadWithProgress;
|
|
2173
2209
|
exports2.validateEmail = validateEmail;
|