@rtorcato/js-common / emails
emails
Functions
isValidEmail()
isValidEmail(
boolean
Defined in: emails/index.ts:14
Validates if a string is a valid email address (simple regex).
Example
isValidEmail('user@example.com') // true
isValidEmail('user@example') // false
isValidEmail('not an email') // false
Parameters
email
string
The email address to validate.
Returns
boolean
True if valid, false otherwise.
normalizeEmail()
normalizeEmail(
string
Defined in: emails/index.ts:31
Normalizes an email address by trimming and converting to lowercase.
Example
normalizeEmail(' User@Example.COM ') // 'user@example.com'
Parameters
email
string
The email address to normalize.
Returns
string
The normalized email address.
maskEmail()
maskEmail(
string
Defined in: emails/index.ts:48
Masks an email address for privacy (e.g., j***@domain.com).
Example
maskEmail('jane@example.com') // 'j***@example.com'
maskEmail('a@example.com') // '*@example.com'
maskEmail('nope') // 'nope'
Parameters
email
string
The email address to mask.
Returns
string
The masked email address.
getEmailDomain()
getEmailDomain(
string
Defined in: emails/index.ts:60
Extracts the domain from an email address.
Parameters
email
string
The email address.
Returns
string
The domain part of the email, or an empty string if invalid.
isFreeEmailProvider()
isFreeEmailProvider(
boolean
Defined in: emails/index.ts:81
Checks if an email address is from a free provider (e.g., gmail, yahoo, outlook).
Parameters
email
string
The email address.
Returns
boolean
True if the email is from a free provider, false otherwise.