2
0
Files
cal/calcom/packages/emails/lib/sanitizeDisplayName.ts
2024-08-09 00:39:27 +02:00

17 lines
403 B
TypeScript

export const sanitizeDisplayName = (nameAndEmail: string) => {
const match = nameAndEmail.match(/^(.*?)\s<(.*)>$/);
if (match) {
const sanitizedName = sanitize(match[1]);
return `${sanitizedName} <${match[2]}>`;
}
return nameAndEmail;
};
const sanitize = (name: string) => {
const charsToReplace = /[;,"<>():]/g;
return name.replace(charsToReplace, " ").replace(/\s+/g, " ");
};