Skip to content

Documentation / @andrew_l/toolkit / maskingEmail

Function: maskingEmail() ​

maskingEmail(value): string

Masks part of the email address to provide a simple level of privacy. The username part is masked as a whole, keeping its first and last characters and its length, while the domain remains intact.

⚠️ Returns an empty string if the provided value is invalid.

Parameters ​

value ​

string

The email address to be masked.

Returns ​

string

The masked email address or an empty string if the value is invalid.

Example ​

ts
maskingEmail('andrew@gmail.com'); // 'a****w@gmail.com'
maskingEmail('user@domain.com'); // 'u**r@domain.com'
maskingEmail('john.doe@x.io'); // 'j******e@x.io'
maskingEmail('invalidemail'); // ''

Released under the MIT License.