@ztimson/utils 0.24.1 → 0.24.2
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 +14 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +14 -14
- package/dist/index.mjs.map +1 -1
- package/dist/misc.d.ts +3 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -910,15 +910,15 @@ ${opts.message || this.desc}`;
|
|
|
910
910
|
};
|
|
911
911
|
return format.replace(/YYYY|YY|MMMM|MMM|MM|M|DDD|DD|Do|D|dddd|ddd|HH|H|hh|h|mm|m|ss|s|SSS|A|a|ZZ|Z|z/g, (token) => tokens[token]);
|
|
912
912
|
}
|
|
913
|
-
function instantInterval(
|
|
914
|
-
|
|
915
|
-
return setInterval(
|
|
913
|
+
function instantInterval(fn2, interval) {
|
|
914
|
+
fn2();
|
|
915
|
+
return setInterval(fn2, interval);
|
|
916
916
|
}
|
|
917
917
|
function sleep(ms) {
|
|
918
918
|
return new Promise((res) => setTimeout(res, ms));
|
|
919
919
|
}
|
|
920
|
-
async function sleepWhile(
|
|
921
|
-
while (await
|
|
920
|
+
async function sleepWhile(fn2, checkInterval = 100) {
|
|
921
|
+
while (await fn2()) await sleep(checkInterval);
|
|
922
922
|
}
|
|
923
923
|
function timeUntil(date) {
|
|
924
924
|
return (date instanceof Date ? date.getTime() : date) - (/* @__PURE__ */ new Date()).getTime();
|
|
@@ -1229,16 +1229,16 @@ ${opts.message || this.desc}`;
|
|
|
1229
1229
|
defaults.interceptors.forEach((i) => _Http.addInterceptor(i));
|
|
1230
1230
|
}
|
|
1231
1231
|
}
|
|
1232
|
-
static addInterceptor(
|
|
1232
|
+
static addInterceptor(fn2) {
|
|
1233
1233
|
const key = Object.keys(_Http.interceptors).length.toString();
|
|
1234
|
-
_Http.interceptors[key] =
|
|
1234
|
+
_Http.interceptors[key] = fn2;
|
|
1235
1235
|
return () => {
|
|
1236
1236
|
_Http.interceptors[key] = null;
|
|
1237
1237
|
};
|
|
1238
1238
|
}
|
|
1239
|
-
addInterceptor(
|
|
1239
|
+
addInterceptor(fn2) {
|
|
1240
1240
|
const key = Object.keys(this.interceptors).length.toString();
|
|
1241
|
-
this.interceptors[key] =
|
|
1241
|
+
this.interceptors[key] = fn2;
|
|
1242
1242
|
return () => {
|
|
1243
1243
|
this.interceptors[key] = null;
|
|
1244
1244
|
};
|
|
@@ -1269,8 +1269,8 @@ ${opts.message || this.desc}`;
|
|
|
1269
1269
|
body: opts.body
|
|
1270
1270
|
}).then(async (resp) => {
|
|
1271
1271
|
var _a2, _b;
|
|
1272
|
-
for (let
|
|
1273
|
-
await new Promise((res2) =>
|
|
1272
|
+
for (let fn2 of [...Object.values(_Http.interceptors), ...Object.values(this.interceptors)]) {
|
|
1273
|
+
await new Promise((res2) => fn2(resp, () => res2()));
|
|
1274
1274
|
}
|
|
1275
1275
|
const contentLength = resp.headers.get("Content-Length");
|
|
1276
1276
|
const total = contentLength ? parseInt(contentLength, 10) : 0;
|
|
@@ -1426,9 +1426,9 @@ ${opts.message || this.desc}`;
|
|
|
1426
1426
|
split = split.pop().split("/");
|
|
1427
1427
|
return whole + Number(split[0]) / Number(split[1]);
|
|
1428
1428
|
}
|
|
1429
|
-
function
|
|
1429
|
+
function fn(args, fn2, async = false) {
|
|
1430
1430
|
const keys = Object.keys(args);
|
|
1431
|
-
return new Function(...keys, `return (async (${keys.join(",")}) => { ${
|
|
1431
|
+
return new Function(...keys, `return (${async ? "async " : ""}(${keys.join(",")}) => { ${fn2} })(${keys.join(",")})`)(...keys.map((k) => args[k]));
|
|
1432
1432
|
}
|
|
1433
1433
|
function gravatar(email, def = "mp") {
|
|
1434
1434
|
if (!email) return "";
|
|
@@ -1762,7 +1762,6 @@ ${opts.message || this.desc}`;
|
|
|
1762
1762
|
exports2.addUnique = addUnique;
|
|
1763
1763
|
exports2.adjustedInterval = adjustedInterval;
|
|
1764
1764
|
exports2.arrayDiff = arrayDiff;
|
|
1765
|
-
exports2.asyncFunction = asyncFunction;
|
|
1766
1765
|
exports2.blackOrWhite = blackOrWhite;
|
|
1767
1766
|
exports2.camelCase = camelCase;
|
|
1768
1767
|
exports2.caseInsensitiveSort = caseInsensitiveSort;
|
|
@@ -1782,6 +1781,7 @@ ${opts.message || this.desc}`;
|
|
|
1782
1781
|
exports2.findByProp = findByProp;
|
|
1783
1782
|
exports2.flattenArr = flattenArr;
|
|
1784
1783
|
exports2.flattenObj = flattenObj;
|
|
1784
|
+
exports2.fn = fn;
|
|
1785
1785
|
exports2.formData = formData;
|
|
1786
1786
|
exports2.formatBytes = formatBytes;
|
|
1787
1787
|
exports2.formatDate = formatDate;
|