@ztimson/utils 0.24.1 → 0.24.3
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 +25 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +25 -25
- package/dist/index.mjs.map +1 -1
- package/dist/misc.d.ts +3 -2
- package/dist/search.d.ts +7 -1
- 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 "";
|
|
@@ -1443,7 +1443,7 @@ ${opts.message || this.desc}`;
|
|
|
1443
1443
|
if (str[i]) combined.push(str[i]);
|
|
1444
1444
|
if (args[i]) combined.push(args[i]);
|
|
1445
1445
|
}
|
|
1446
|
-
return new PathEvent(combined.join(""));
|
|
1446
|
+
return new PathEvent(combined.join("/"));
|
|
1447
1447
|
}
|
|
1448
1448
|
function PES(str, ...args) {
|
|
1449
1449
|
let combined = [];
|
|
@@ -1502,28 +1502,28 @@ ${opts.message || this.desc}`;
|
|
|
1502
1502
|
return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("c"));
|
|
1503
1503
|
}
|
|
1504
1504
|
set create(v) {
|
|
1505
|
-
v ? this.methods.delete("n").add("c") : this.methods.delete("c");
|
|
1505
|
+
v ? this.methods.delete("n").delete("*").add("c") : this.methods.delete("c");
|
|
1506
1506
|
}
|
|
1507
1507
|
/** Read method specified */
|
|
1508
1508
|
get read() {
|
|
1509
1509
|
return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("r"));
|
|
1510
1510
|
}
|
|
1511
1511
|
set read(v) {
|
|
1512
|
-
v ? this.methods.delete("n").add("r") : this.methods.delete("r");
|
|
1512
|
+
v ? this.methods.delete("n").delete("*").add("r") : this.methods.delete("r");
|
|
1513
1513
|
}
|
|
1514
1514
|
/** Update method specified */
|
|
1515
1515
|
get update() {
|
|
1516
1516
|
return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("u"));
|
|
1517
1517
|
}
|
|
1518
1518
|
set update(v) {
|
|
1519
|
-
v ? this.methods.delete("n").add("u") : this.methods.delete("u");
|
|
1519
|
+
v ? this.methods.delete("n").delete("*").add("u") : this.methods.delete("u");
|
|
1520
1520
|
}
|
|
1521
1521
|
/** Delete method specified */
|
|
1522
1522
|
get delete() {
|
|
1523
1523
|
return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("d"));
|
|
1524
1524
|
}
|
|
1525
1525
|
set delete(v) {
|
|
1526
|
-
v ? this.methods.delete("n").add("d") : this.methods.delete("d");
|
|
1526
|
+
v ? this.methods.delete("n").delete("*").add("d") : this.methods.delete("d");
|
|
1527
1527
|
}
|
|
1528
1528
|
/**
|
|
1529
1529
|
* Combine multiple events into one parsed object. Longest path takes precedent, but all subsequent methods are
|
|
@@ -1681,11 +1681,11 @@ ${opts.message || this.desc}`;
|
|
|
1681
1681
|
}
|
|
1682
1682
|
}).length;
|
|
1683
1683
|
} else {
|
|
1684
|
-
return
|
|
1684
|
+
return logicTest(r, search2);
|
|
1685
1685
|
}
|
|
1686
1686
|
});
|
|
1687
1687
|
}
|
|
1688
|
-
function
|
|
1688
|
+
function logicTest(target, condition) {
|
|
1689
1689
|
const evalBoolean = (a, op, b) => {
|
|
1690
1690
|
switch (op) {
|
|
1691
1691
|
case "=":
|
|
@@ -1711,10 +1711,10 @@ ${opts.message || this.desc}`;
|
|
|
1711
1711
|
return and.filter((p2) => {
|
|
1712
1712
|
const prop = /(\S+)\s*(==?|!=|>=|>|<=|<)\s*(\S+)/g.exec(p2);
|
|
1713
1713
|
if (prop) {
|
|
1714
|
-
const key = Object.keys(
|
|
1715
|
-
return evalBoolean(dotNotation(
|
|
1714
|
+
const key = Object.keys(target).find((k) => k.toLowerCase() == prop[1].toLowerCase());
|
|
1715
|
+
return evalBoolean(dotNotation(target, key || prop[1]), prop[2], JSONAttemptParse(prop[3]));
|
|
1716
1716
|
}
|
|
1717
|
-
const v = Object.values(
|
|
1717
|
+
const v = Object.values(target).map(JSONSerialize).join("");
|
|
1718
1718
|
if (/[A-Z]/g.test(condition)) return v.includes(p2);
|
|
1719
1719
|
return v.toLowerCase().includes(p2);
|
|
1720
1720
|
}).length == and.length;
|
|
@@ -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;
|
|
@@ -1794,6 +1794,7 @@ ${opts.message || this.desc}`;
|
|
|
1794
1794
|
exports2.instantInterval = instantInterval;
|
|
1795
1795
|
exports2.isEqual = isEqual;
|
|
1796
1796
|
exports2.kebabCase = kebabCase;
|
|
1797
|
+
exports2.logicTest = logicTest;
|
|
1797
1798
|
exports2.makeArray = makeArray;
|
|
1798
1799
|
exports2.makeUnique = makeUnique;
|
|
1799
1800
|
exports2.matchAll = matchAll;
|
|
@@ -1811,7 +1812,6 @@ ${opts.message || this.desc}`;
|
|
|
1811
1812
|
exports2.snakeCase = snakeCase;
|
|
1812
1813
|
exports2.sortByProp = sortByProp;
|
|
1813
1814
|
exports2.strSplice = strSplice;
|
|
1814
|
-
exports2.testCondition = testCondition;
|
|
1815
1815
|
exports2.timeUntil = timeUntil;
|
|
1816
1816
|
exports2.timestampFilename = timestampFilename;
|
|
1817
1817
|
exports2.toCsv = toCsv;
|