mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: more refactor to the bun
This commit is contained in:
25
Build/lib/domain-deduper.ts
Normal file
25
Build/lib/domain-deduper.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import createTrie from './trie';
|
||||
|
||||
const domainDeduper = (inputDomains: string[]): string[] => {
|
||||
const trie = createTrie(inputDomains);
|
||||
const sets = new Set(inputDomains);
|
||||
|
||||
for (let j = 0, len = inputDomains.length; j < len; j++) {
|
||||
const d = inputDomains[j];
|
||||
if (d[0] !== '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
trie.find(d, false).forEach(f => sets.delete(f));
|
||||
|
||||
const a: string = d.slice(1);
|
||||
|
||||
if (sets.has(a)) {
|
||||
sets.delete(a);
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(sets);
|
||||
};
|
||||
|
||||
export default domainDeduper;
|
||||
Reference in New Issue
Block a user