@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 CHANGED
@@ -1648,6 +1648,9 @@ ${opts.message || this.desc}`;
1648
1648
  split = split.pop().split("/");
1649
1649
  return whole + Number(split[0]) / Number(split[1]);
1650
1650
  }
1651
+ function escapeRegex(value) {
1652
+ return value.replace(/[.*+?^${}()|\[\]\\]/g, "\\$&");
1653
+ }
1651
1654
  function fn(args, fn2, async = false) {
1652
1655
  const keys = Object.keys(args);
1653
1656
  return new Function(...keys, `return (${async ? "async " : ""}(${keys.join(",")}) => { ${fn2} })(${keys.join(",")})`)(...keys.map((k) => args[k]));
@@ -1656,8 +1659,11 @@ ${opts.message || this.desc}`;
1656
1659
  if (!email) return "";
1657
1660
  return `https://www.gravatar.com/avatar/${md5(email)}?d=${def}`;
1658
1661
  }
1659
- function escapeRegex(value) {
1660
- return value.replace(/[.*+?^${}()|\[\]\\]/g, "\\$&");
1662
+ function ipV6ToV4(ip) {
1663
+ if (!ip) return null;
1664
+ const ipv4 = ip.split(":").splice(-1)[0];
1665
+ if (ipv4 == "1") return "127.0.0.1";
1666
+ return ipv4;
1661
1667
  }
1662
1668
  function PE(str, ...args) {
1663
1669
  const combined = [];
@@ -1779,7 +1785,13 @@ ${opts.message || this.desc}`;
1779
1785
  static filter(target, ...filter) {
1780
1786
  const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
1781
1787
  const parsedFilter = makeArray(filter).map((pe) => new PathEvent(pe));
1782
- return parsedTarget.filter((t) => !!parsedFilter.find((f) => (t.fullPath == "*" || f.fullPath == "*" || t.fullPath.startsWith(f.fullPath) || f.fullPath.startsWith(t.fullPath)) && (f.all || t.all || t.methods.intersection(f.methods).length)));
1788
+ return parsedTarget.filter((t) => !!parsedFilter.find((r) => {
1789
+ const wildcard = r.fullPath == "*" || t.fullPath == "*";
1790
+ const p1 = r.fullPath.slice(0, r.fullPath.indexOf("*")), p2 = t.fullPath.slice(0, t.fullPath.indexOf("*"));
1791
+ const scope = p1.startsWith(p2) || p2.startsWith(p1);
1792
+ const methods = r.all || t.all || r.methods.intersection(t.methods).length;
1793
+ return (wildcard || scope) && methods;
1794
+ }));
1783
1795
  }
1784
1796
  /**
1785
1797
  * Squash 2 sets of paths & return true if any overlap is found
@@ -1791,9 +1803,13 @@ ${opts.message || this.desc}`;
1791
1803
  static has(target, ...has) {
1792
1804
  const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
1793
1805
  const parsedRequired = makeArray(has).map((pe) => new PathEvent(pe));
1794
- return !!parsedRequired.find((r) => !!parsedTarget.find(
1795
- (t) => (r.fullPath == "*" || t.fullPath == "*" || r.fullPath.startsWith(t.fullPath)) && (r.all || t.all || r.methods.intersection(t.methods).length)
1796
- ));
1806
+ return !!parsedRequired.find((r) => !!parsedTarget.find((t) => {
1807
+ const wildcard = r.fullPath == "*" || t.fullPath == "*";
1808
+ const p1 = r.fullPath.slice(0, r.fullPath.indexOf("*")), p2 = t.fullPath.slice(0, t.fullPath.indexOf("*"));
1809
+ const scope = p1.startsWith(p2);
1810
+ const methods = r.all || t.all || r.methods.intersection(t.methods).length;
1811
+ return (wildcard || scope) && methods;
1812
+ }));
1797
1813
  }
1798
1814
  /**
1799
1815
  * Squash 2 sets of paths & return true if the target has all paths
@@ -1836,6 +1852,40 @@ ${opts.message || this.desc}`;
1836
1852
  if (methods == null ? void 0 : methods.length) p += `:${makeArray(methods).map((m) => m.toLowerCase()).join("")}`;
1837
1853
  return p;
1838
1854
  }
1855
+ /**
1856
+ * Squash 2 sets of paths & return true if any overlap is found
1857
+ *
1858
+ * @param has Target must have at least one of these path
1859
+ * @return {boolean} Whether there is any overlap
1860
+ */
1861
+ has(...has) {
1862
+ return PathEvent.has(this, ...has);
1863
+ }
1864
+ /**
1865
+ * Squash 2 sets of paths & return true if the target has all paths
1866
+ *
1867
+ * @param has Target must have all these paths
1868
+ * @return {boolean} Whether there is any overlap
1869
+ */
1870
+ hasAll(...has) {
1871
+ return PathEvent.hasAll(this, ...has);
1872
+ }
1873
+ /**
1874
+ * Same as `has` but raises an error if there is no overlap
1875
+ *
1876
+ * @param has Target must have at least one of these path
1877
+ */
1878
+ hasFatal(...has) {
1879
+ return PathEvent.hasFatal(this, ...has);
1880
+ }
1881
+ /**
1882
+ * Same as `hasAll` but raises an error if the target is missing any paths
1883
+ *
1884
+ * @param has Target must have all these paths
1885
+ */
1886
+ hasAllFatal(...has) {
1887
+ return PathEvent.hasAllFatal(this, ...has);
1888
+ }
1839
1889
  /**
1840
1890
  * Filter a set of paths based on this event
1841
1891
  *
@@ -2181,6 +2231,7 @@ ${opts.message || this.desc}`;
2181
2231
  exports2.includes = includes;
2182
2232
  exports2.insertAt = insertAt;
2183
2233
  exports2.instantInterval = instantInterval;
2234
+ exports2.ipV6ToV4 = ipV6ToV4;
2184
2235
  exports2.isEqual = isEqual;
2185
2236
  exports2.kebabCase = kebabCase;
2186
2237
  exports2.logicTest = logicTest;