updated blocklist check logic to prevent adding a subdomain if a higher-level domain is already blocked

This commit is contained in:
Viet Huynh
2023-09-15 05:36:19 +07:00
parent 695d7c7f5a
commit 083335278c
2 changed files with 49 additions and 8 deletions
+18
View File
@@ -17,6 +17,24 @@ export const sleep = (ms = 350) =>
export const isValidDomain = (value) =>
/^(?!-)[A-Za-z0-9-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,6}$/.test(value);
/**
* Extracts all subdomains from a domain including itself.
* @param {string} domain The domain to be extracted.
* @returns {string[]}
*/
export const extractDomain = (domain) =>
domain.split(".").reduce((previous, current, index, array) => {
const nextIndex = index + 1;
if (nextIndex > array.length - 1) return previous;
const domain = [current, ...array.slice(nextIndex)].join(".");
previous.push(domain);
return previous;
}, []);
/**
* Checks if the value is a comment.
* @param {string} value The value to be checked.