refactored domain processing code

This commit is contained in:
Viet Huynh
2023-09-12 16:35:16 +07:00
parent e96d0f719a
commit 40772b567d
3 changed files with 143 additions and 102 deletions
+19
View File
@@ -40,3 +40,22 @@ const request = async (url, options) => {
*/
export const requestGateway = (path, options) =>
request(`${API_HOST}/accounts/${ACCOUNT_ID}/gateway${path}`, options);
/**
* Normalizes a domain.
* @param {string} value The value to be normalized.
* @param {boolean} isAllowlisting Whether the value is to be whitelisted.
* @returns {string}
*/
export const normalizeDomain = (value, isAllowlisting) => {
const normalized = value
.replace(/(0\.0\.0\.0|127\.0\.0\.1|::1|::)\s+/, "")
.replace("||", "")
.replace("^$important", "")
.replace("*.", "")
.replace("^", "");
if (isAllowlisting) return normalized.replace("@@||", "");
return normalized;
};