17 lines
403 B
TypeScript
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, " ");
|
|
};
|