@ztimson/utils 0.25.18 → 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
@@ -1785,7 +1785,13 @@ ${opts.message || this.desc}`;
1785
1785
  static filter(target, ...filter) {
1786
1786
  const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
1787
1787
  const parsedFilter = makeArray(filter).map((pe) => new PathEvent(pe));
1788
- 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
+ }));
1789
1795
  }
1790
1796
  /**
1791
1797
  * Squash 2 sets of paths & return true if any overlap is found
@@ -1797,9 +1803,13 @@ ${opts.message || this.desc}`;
1797
1803
  static has(target, ...has) {
1798
1804
  const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
1799
1805
  const parsedRequired = makeArray(has).map((pe) => new PathEvent(pe));
1800
- return !!parsedRequired.find((r) => !!parsedTarget.find(
1801
- (t) => (r.fullPath == "*" || t.fullPath == "*" || r.fullPath.startsWith(t.fullPath)) && (r.all || t.all || r.methods.intersection(t.methods).length)
1802
- ));
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
+ }));
1803
1813
  }
1804
1814
  /**
1805
1815
  * Squash 2 sets of paths & return true if the target has all paths
@@ -1842,6 +1852,40 @@ ${opts.message || this.desc}`;
1842
1852
  if (methods == null ? void 0 : methods.length) p += `:${makeArray(methods).map((m) => m.toLowerCase()).join("")}`;
1843
1853
  return p;
1844
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
+ }
1845
1889
  /**
1846
1890
  * Filter a set of paths based on this event
1847
1891
  *