@ztimson/utils 0.25.17 → 0.25.19
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 +57 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +57 -6
- package/dist/index.mjs.map +1 -1
- package/dist/misc.d.ts +11 -5
- package/dist/path-events.d.ts +26 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1644,6 +1644,9 @@ function fracToDec(frac) {
|
|
|
1644
1644
|
split = split.pop().split("/");
|
|
1645
1645
|
return whole + Number(split[0]) / Number(split[1]);
|
|
1646
1646
|
}
|
|
1647
|
+
function escapeRegex(value) {
|
|
1648
|
+
return value.replace(/[.*+?^${}()|\[\]\\]/g, "\\$&");
|
|
1649
|
+
}
|
|
1647
1650
|
function fn(args, fn2, async = false) {
|
|
1648
1651
|
const keys = Object.keys(args);
|
|
1649
1652
|
return new Function(...keys, `return (${async ? "async " : ""}(${keys.join(",")}) => { ${fn2} })(${keys.join(",")})`)(...keys.map((k) => args[k]));
|
|
@@ -1652,8 +1655,11 @@ function gravatar(email, def = "mp") {
|
|
|
1652
1655
|
if (!email) return "";
|
|
1653
1656
|
return `https://www.gravatar.com/avatar/${md5(email)}?d=${def}`;
|
|
1654
1657
|
}
|
|
1655
|
-
function
|
|
1656
|
-
|
|
1658
|
+
function ipV6ToV4(ip) {
|
|
1659
|
+
if (!ip) return null;
|
|
1660
|
+
const ipv4 = ip.split(":").splice(-1)[0];
|
|
1661
|
+
if (ipv4 == "1") return "127.0.0.1";
|
|
1662
|
+
return ipv4;
|
|
1657
1663
|
}
|
|
1658
1664
|
function PE(str, ...args) {
|
|
1659
1665
|
const combined = [];
|
|
@@ -1775,7 +1781,13 @@ class PathEvent {
|
|
|
1775
1781
|
static filter(target, ...filter) {
|
|
1776
1782
|
const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
|
|
1777
1783
|
const parsedFilter = makeArray(filter).map((pe) => new PathEvent(pe));
|
|
1778
|
-
return parsedTarget.filter((t) => !!parsedFilter.find((
|
|
1784
|
+
return parsedTarget.filter((t) => !!parsedFilter.find((r) => {
|
|
1785
|
+
const wildcard = r.fullPath == "*" || t.fullPath == "*";
|
|
1786
|
+
const p1 = r.fullPath.slice(0, r.fullPath.indexOf("*")), p2 = t.fullPath.slice(0, t.fullPath.indexOf("*"));
|
|
1787
|
+
const scope = p1.startsWith(p2) || p2.startsWith(p1);
|
|
1788
|
+
const methods = r.all || t.all || r.methods.intersection(t.methods).length;
|
|
1789
|
+
return (wildcard || scope) && methods;
|
|
1790
|
+
}));
|
|
1779
1791
|
}
|
|
1780
1792
|
/**
|
|
1781
1793
|
* Squash 2 sets of paths & return true if any overlap is found
|
|
@@ -1787,9 +1799,13 @@ class PathEvent {
|
|
|
1787
1799
|
static has(target, ...has) {
|
|
1788
1800
|
const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
|
|
1789
1801
|
const parsedRequired = makeArray(has).map((pe) => new PathEvent(pe));
|
|
1790
|
-
return !!parsedRequired.find((r) => !!parsedTarget.find(
|
|
1791
|
-
|
|
1792
|
-
|
|
1802
|
+
return !!parsedRequired.find((r) => !!parsedTarget.find((t) => {
|
|
1803
|
+
const wildcard = r.fullPath == "*" || t.fullPath == "*";
|
|
1804
|
+
const p1 = r.fullPath.slice(0, r.fullPath.indexOf("*")), p2 = t.fullPath.slice(0, t.fullPath.indexOf("*"));
|
|
1805
|
+
const scope = p1.startsWith(p2);
|
|
1806
|
+
const methods = r.all || t.all || r.methods.intersection(t.methods).length;
|
|
1807
|
+
return (wildcard || scope) && methods;
|
|
1808
|
+
}));
|
|
1793
1809
|
}
|
|
1794
1810
|
/**
|
|
1795
1811
|
* Squash 2 sets of paths & return true if the target has all paths
|
|
@@ -1832,6 +1848,40 @@ class PathEvent {
|
|
|
1832
1848
|
if (methods == null ? void 0 : methods.length) p += `:${makeArray(methods).map((m) => m.toLowerCase()).join("")}`;
|
|
1833
1849
|
return p;
|
|
1834
1850
|
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Squash 2 sets of paths & return true if any overlap is found
|
|
1853
|
+
*
|
|
1854
|
+
* @param has Target must have at least one of these path
|
|
1855
|
+
* @return {boolean} Whether there is any overlap
|
|
1856
|
+
*/
|
|
1857
|
+
has(...has) {
|
|
1858
|
+
return PathEvent.has(this, ...has);
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* Squash 2 sets of paths & return true if the target has all paths
|
|
1862
|
+
*
|
|
1863
|
+
* @param has Target must have all these paths
|
|
1864
|
+
* @return {boolean} Whether there is any overlap
|
|
1865
|
+
*/
|
|
1866
|
+
hasAll(...has) {
|
|
1867
|
+
return PathEvent.hasAll(this, ...has);
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* Same as `has` but raises an error if there is no overlap
|
|
1871
|
+
*
|
|
1872
|
+
* @param has Target must have at least one of these path
|
|
1873
|
+
*/
|
|
1874
|
+
hasFatal(...has) {
|
|
1875
|
+
return PathEvent.hasFatal(this, ...has);
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* Same as `hasAll` but raises an error if the target is missing any paths
|
|
1879
|
+
*
|
|
1880
|
+
* @param has Target must have all these paths
|
|
1881
|
+
*/
|
|
1882
|
+
hasAllFatal(...has) {
|
|
1883
|
+
return PathEvent.hasAllFatal(this, ...has);
|
|
1884
|
+
}
|
|
1835
1885
|
/**
|
|
1836
1886
|
* Filter a set of paths based on this event
|
|
1837
1887
|
*
|
|
@@ -2178,6 +2228,7 @@ export {
|
|
|
2178
2228
|
includes,
|
|
2179
2229
|
insertAt,
|
|
2180
2230
|
instantInterval,
|
|
2231
|
+
ipV6ToV4,
|
|
2181
2232
|
isEqual,
|
|
2182
2233
|
kebabCase,
|
|
2183
2234
|
logicTest,
|