MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / urlMatch

Method urlMatch

src/pkg/utils/match.ts:20–55  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

18 }
19
20 public urlMatch(url: string): T[] {
21 const cacheMap = this.cacheMap;
22 if (cacheMap.has(url)) {
23 const cached = cacheMap.get(url) as T[];
24 cacheMap.delete(url);
25 cacheMap.set(url, cached);
26 return cached;
27 }
28 const res: T[] = [];
29 for (const [uuid, rules] of this.rulesMap) {
30 try {
31 if (isUrlIncluded(url, rules)) {
32 res.push(uuid);
33 }
34 } catch (e) {
35 console.warn("Unexpected match error", e);
36 }
37 }
38 const sorter = this.sorter;
39 if (sorter !== null && typeof sorter === "object" && typeof res[0] === "string") {
40 (res as string[]).sort((a, b) => {
41 const p = sorter[a];
42 const q = sorter[b];
43 if (p! > -1 && q! > -1) {
44 return p! - q!;
45 }
46 return a.localeCompare(b);
47 });
48 }
49 cacheMap.set(url, res);
50 if (cacheMap.size > this.maxCacheEntries) {
51 const oldest = cacheMap.keys().next().value;
52 if (oldest !== undefined) cacheMap.delete(oldest);
53 }
54 return res;
55 }
56
57 public clearRules(uuid: T) {
58 this.cacheMap.clear();

Callers 5

blackListSelfCheckFunction · 0.95
match.test.tsFile · 0.80
initMethod · 0.80
isUrlBlacklistMethod · 0.80

Calls 10

isUrlIncludedFunction · 0.85
pushMethod · 0.80
warnMethod · 0.80
sortMethod · 0.80
keysMethod · 0.80
hasMethod · 0.65
getMethod · 0.65
deleteMethod · 0.65
setMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected