@ztimson/utils 0.25.18 → 0.25.20
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 +49 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +49 -12
- package/dist/index.mjs.map +1 -1
- package/dist/path-events.d.ts +26 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -547,14 +547,7 @@ ${opts.message || this.desc}`;
|
|
|
547
547
|
if (options.storage instanceof Table) {
|
|
548
548
|
(async () => {
|
|
549
549
|
var _a2;
|
|
550
|
-
return (await ((_a2 = options.storage) == null ? void 0 : _a2.getAll()))
|
|
551
|
-
if (v) {
|
|
552
|
-
try {
|
|
553
|
-
this.add(v);
|
|
554
|
-
} catch {
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
});
|
|
550
|
+
return this.addAll(await ((_a2 = options.storage) == null ? void 0 : _a2.getAll()));
|
|
558
551
|
})();
|
|
559
552
|
} else if (options.storageKey) {
|
|
560
553
|
const stored = (_a = options.storage) == null ? void 0 : _a.getItem(options.storageKey);
|
|
@@ -1785,7 +1778,13 @@ ${opts.message || this.desc}`;
|
|
|
1785
1778
|
static filter(target, ...filter) {
|
|
1786
1779
|
const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
|
|
1787
1780
|
const parsedFilter = makeArray(filter).map((pe) => new PathEvent(pe));
|
|
1788
|
-
return parsedTarget.filter((t) => !!parsedFilter.find((
|
|
1781
|
+
return parsedTarget.filter((t) => !!parsedFilter.find((r) => {
|
|
1782
|
+
const wildcard = r.fullPath == "*" || t.fullPath == "*";
|
|
1783
|
+
const p1 = r.fullPath.slice(0, r.fullPath.indexOf("*")), p2 = t.fullPath.slice(0, t.fullPath.indexOf("*"));
|
|
1784
|
+
const scope = p1.startsWith(p2) || p2.startsWith(p1);
|
|
1785
|
+
const methods = r.all || t.all || r.methods.intersection(t.methods).length;
|
|
1786
|
+
return (wildcard || scope) && methods;
|
|
1787
|
+
}));
|
|
1789
1788
|
}
|
|
1790
1789
|
/**
|
|
1791
1790
|
* Squash 2 sets of paths & return true if any overlap is found
|
|
@@ -1797,9 +1796,13 @@ ${opts.message || this.desc}`;
|
|
|
1797
1796
|
static has(target, ...has) {
|
|
1798
1797
|
const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
|
|
1799
1798
|
const parsedRequired = makeArray(has).map((pe) => new PathEvent(pe));
|
|
1800
|
-
return !!parsedRequired.find((r) => !!parsedTarget.find(
|
|
1801
|
-
|
|
1802
|
-
|
|
1799
|
+
return !!parsedRequired.find((r) => !!parsedTarget.find((t) => {
|
|
1800
|
+
const wildcard = r.fullPath == "*" || t.fullPath == "*";
|
|
1801
|
+
const p1 = r.fullPath.slice(0, r.fullPath.indexOf("*")), p2 = t.fullPath.slice(0, t.fullPath.indexOf("*"));
|
|
1802
|
+
const scope = p1.startsWith(p2);
|
|
1803
|
+
const methods = r.all || t.all || r.methods.intersection(t.methods).length;
|
|
1804
|
+
return (wildcard || scope) && methods;
|
|
1805
|
+
}));
|
|
1803
1806
|
}
|
|
1804
1807
|
/**
|
|
1805
1808
|
* Squash 2 sets of paths & return true if the target has all paths
|
|
@@ -1842,6 +1845,40 @@ ${opts.message || this.desc}`;
|
|
|
1842
1845
|
if (methods == null ? void 0 : methods.length) p += `:${makeArray(methods).map((m) => m.toLowerCase()).join("")}`;
|
|
1843
1846
|
return p;
|
|
1844
1847
|
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Squash 2 sets of paths & return true if any overlap is found
|
|
1850
|
+
*
|
|
1851
|
+
* @param has Target must have at least one of these path
|
|
1852
|
+
* @return {boolean} Whether there is any overlap
|
|
1853
|
+
*/
|
|
1854
|
+
has(...has) {
|
|
1855
|
+
return PathEvent.has(this, ...has);
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Squash 2 sets of paths & return true if the target has all paths
|
|
1859
|
+
*
|
|
1860
|
+
* @param has Target must have all these paths
|
|
1861
|
+
* @return {boolean} Whether there is any overlap
|
|
1862
|
+
*/
|
|
1863
|
+
hasAll(...has) {
|
|
1864
|
+
return PathEvent.hasAll(this, ...has);
|
|
1865
|
+
}
|
|
1866
|
+
/**
|
|
1867
|
+
* Same as `has` but raises an error if there is no overlap
|
|
1868
|
+
*
|
|
1869
|
+
* @param has Target must have at least one of these path
|
|
1870
|
+
*/
|
|
1871
|
+
hasFatal(...has) {
|
|
1872
|
+
return PathEvent.hasFatal(this, ...has);
|
|
1873
|
+
}
|
|
1874
|
+
/**
|
|
1875
|
+
* Same as `hasAll` but raises an error if the target is missing any paths
|
|
1876
|
+
*
|
|
1877
|
+
* @param has Target must have all these paths
|
|
1878
|
+
*/
|
|
1879
|
+
hasAllFatal(...has) {
|
|
1880
|
+
return PathEvent.hasAllFatal(this, ...has);
|
|
1881
|
+
}
|
|
1845
1882
|
/**
|
|
1846
1883
|
* Filter a set of paths based on this event
|
|
1847
1884
|
*
|