Refactor for centralized regex check module and regex syntax. Added comments.

This commit is contained in:
Lucid Kobold
2025-07-04 18:34:36 -04:00
parent 9d8c026670
commit 72a6e53d49
4 changed files with 69 additions and 6 deletions

22
src/lib/metaLinkCheck.ts Normal file
View File

@@ -0,0 +1,22 @@
// Global regex used to detect all meta services.
const metaRegex =
/(facebook\.com|meta\.com|instagram\.com|threads\.net|whatsapp\.com)/gi;
/**
* This function will check if a url matches Meta services links using regex.
*
* @param linkUrl representing a suspected blacklisted url
* @returns flag
*/
const metaLinkCheck = (linkUrl: string): boolean => {
let flag = false;
if (linkUrl.match(metaRegex)) {
flag = true;
}
return flag;
};
export { metaRegex };
export default metaLinkCheck;

View File

@@ -0,0 +1,21 @@
// Global regex used to detect Twitter and X links.
const twitterRegex = /(x\.com|twitter\.com)/gi;
/**
* This function will check if a url matches Twitter/X services links using regex.
*
* @param linkUrl representing a suspected blacklisted url
* @return flag
*/
const twitterLinkCheck = (linkUrl: string): boolean => {
let flag = false;
if (linkUrl.match(twitterRegex)) {
flag = true;
}
return flag;
};
export { twitterRegex };
export default twitterLinkCheck;