Refactor for centralized regex check module and regex syntax. Added comments.
This commit is contained in:
22
src/lib/metaLinkCheck.ts
Normal file
22
src/lib/metaLinkCheck.ts
Normal 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;
|
||||
21
src/lib/twitterLinkCheck.ts
Normal file
21
src/lib/twitterLinkCheck.ts
Normal 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;
|
||||
Reference in New Issue
Block a user