Parse, validate, and normalize email addresses, primarily using RFC-5321.
Full docs: https://electrovir.github.io/parse-email-address
This uses and is based on smtp-address-parser
v1.1.0, so it has the following features (from smtp-address-parser
):
name@example.org
name@example
name@example.x
This package adds the following features:
npm i parse-email-address
import {isValidEmailAddress, normalizeEmailAddress, parseEmailAddress} from 'parse-email-address';
/**
* Parse email addresses into parts with `parseEmailAddress`. Returns `undefined` if the input is an
* invalid email address.
*/
parseEmailAddress('simple@example.org'); // returns `{user: 'simple', domain: 'example.org', full: 'simple@example.org'}`
parseEmailAddress('tld-too-short@foo.x'); // returns `undefined`
/**
* Normalize email addresses for string comparisons with `normalizeEmailAddress`. Returns
* `undefined` if the input is an invalid email address.
*/
normalizeEmailAddress('SIMPLE@EXAMPLE.ORG'); // returns `'simple@example.org'`
normalizeEmailAddress('tld-too-short@foo.x'); // returns `undefined`
/** Check if an email address is valid with `isValidEmailAddress`. */
isValidEmailAddress('simple@example.org'); // returns `true`
isValidEmailAddress('SIMPLE@EXAMPLE.ORG'); // returns `true`
isValidEmailAddress('tld-too-short@foo.x'); // returns `false`