@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.mjs CHANGED
@@ -1781,7 +1781,13 @@ class PathEvent {
1781
1781
  static filter(target, ...filter) {
1782
1782
  const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
1783
1783
  const parsedFilter = makeArray(filter).map((pe) => new PathEvent(pe));
1784
- 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)));
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
+ }));
1785
1791
  }
1786
1792
  /**
1787
1793
  * Squash 2 sets of paths & return true if any overlap is found
@@ -1793,9 +1799,13 @@ class PathEvent {
1793
1799
  static has(target, ...has) {
1794
1800
  const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
1795
1801
  const parsedRequired = makeArray(has).map((pe) => new PathEvent(pe));
1796
- return !!parsedRequired.find((r) => !!parsedTarget.find(
1797
- (t) => (r.fullPath == "*" || t.fullPath == "*" || r.fullPath.startsWith(t.fullPath)) && (r.all || t.all || r.methods.intersection(t.methods).length)
1798
- ));
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
+ }));
1799
1809
  }
1800
1810
  /**
1801
1811
  * Squash 2 sets of paths & return true if the target has all paths
@@ -1838,6 +1848,40 @@ class PathEvent {
1838
1848
  if (methods == null ? void 0 : methods.length) p += `:${makeArray(methods).map((m) => m.toLowerCase()).join("")}`;
1839
1849
  return p;
1840
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
+ }
1841
1885
  /**
1842
1886
  * Filter a set of paths based on this event
1843
1887
  *