mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 13:38:37 +00:00
refactored domain processing code to improve performance and memory usage
This commit is contained in:
+9
-9
@@ -19,18 +19,18 @@ export const isValidDomain = (value) =>
|
||||
* @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;
|
||||
export const extractDomain = (domain) => {
|
||||
const parts = domain.split(".");
|
||||
const extractedDomains = [];
|
||||
|
||||
if (nextIndex > array.length - 1) return previous;
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const subdomains = parts.slice(i).join(".");
|
||||
|
||||
const domain = [current, ...array.slice(nextIndex)].join(".");
|
||||
extractedDomains.unshift(subdomains);
|
||||
}
|
||||
|
||||
previous.push(domain);
|
||||
|
||||
return previous;
|
||||
}, []);
|
||||
return extractedDomains;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if the value is a comment.
|
||||
|
||||
Reference in New Issue
Block a user