Add build step to CDN domainset

This commit is contained in:
SukkaW
2023-07-13 22:18:53 +08:00
parent 9fde4a3866
commit b43c1628d6
7 changed files with 128 additions and 48 deletions

View File

@@ -0,0 +1,27 @@
const Trie = require('./trie');
/**
* @param {string[]} inputDomains
*/
const domainDeduper = (inputDomains) => {
const trie = Trie.from(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 = d.slice(1);
if (trie.has(a)) {
sets.delete(a);
}
}
return Array.from(sets);
};
module.exports.domainDeduper = domainDeduper;