-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
EmailUtils.ts
30 lines (28 loc) · 1.12 KB
/
EmailUtils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* Trims the `mailto:` part from mail link.
* @param mailLink - The `mailto:` link to be trimmed
* @returns The email address
*/
function trimMailTo(mailLink: string) {
return mailLink.replace('mailto:', '');
}
/**
* Prepends a zero-width space (U+200B) character before all `.` and `@` characters
* in the email address to provide explicit line break opportunities for consistent
* breaking across platforms.
*
* Note: as explained [here](https://github.com/Expensify/App/issues/30985#issuecomment-1815379835),
* this only provides opportunities for line breaking (rather than forcing line breaks) that shall
* be used by the platform implementation when there are no other customary rules applicable
* and the text would otherwise overflow.
* @param email - The email address to be sanitized
* @returns The email with inserted line break opportunities
*/
function prefixMailSeparatorsWithBreakOpportunities(email: string) {
return email.replace(
/([.@])/g,
// below: zero-width space (U+200B) character
'$1',
);
}
export default {trimMailTo, prefixMailSeparatorsWithBreakOpportunities};