email-addresses is a JavaScript/TypeScript library designed for parsing email addresses strictly according to RFC 5322. At version 5.0.0, this package provides functions to extract display names, addresses, local parts, and domains from email strings, even supporting complex forms like `"Bob Example" <bob@example.com>`. Unlike regular expression-based solutions, it uses a recursive descent parser that maps directly to RFC 5322 productions, ensuring robust and spec-compliant parsing. It explicitly states that it does *not* perform RFC 5321 validation (which involves checking for deliverability), focusing solely on the grammatical correctness defined by RFC 5322. The library also supports RFC 6532 for Unicode email addresses and offers options for strictness, partial parsing, and custom address list separators. It is actively maintained and ships with TypeScript types, facilitating its use in modern JavaScript and TypeScript projects.
npm install email-addressesVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing single and multiple email addresses, accessing structured address data (name, address, local, domain), and retrieving the Abstract Syntax Tree (AST) for detailed parsing insights. Also shows behavior for invalid input.
Review the official changelog or migration guide for `email-addresses` v5.x.x for specific API changes. Update import statements, function calls, and option handling as necessary.
If you require stricter validation (e.g., checking MX records, disposable email detection, or deliverability), use an additional library like `node-email-verifier` or a dedicated email validation service in conjunction with `email-addresses`.
After parsing, inspect the `name` property or other `parts` to determine if a display name or comments were present. If only the `local@domain` part is desired, always use the `address` property of the parsed object.
Always check for `null` after calling `emailAddresses(...)`, `emailAddresses.parseOneAddress(...)`, or `emailAddresses.parseAddressList(...)` before attempting to access properties of the returned object to avoid `TypeError: Cannot read properties of null (reading '...')`.
Ensure you are using the correct import style for your module environment (ESM `import` or CommonJS `require`). If using CommonJS, `const addrs = require('email-addresses')` makes `addrs` a callable object. For ESM, `import emailAddresses from 'email-addresses'` makes `emailAddresses` the callable function.Update your code to use ESM `import` statements (e.g., `import emailAddresses from 'email-addresses';`) and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
Always check if the result of `emailAddresses(...)`, `parseOneAddress(...)`, or `parseAddressList(...)` is not `null` before trying to access its properties. For example: `const parsed = emailAddresses('invalid'); if (parsed) { /* use parsed */ } else { /* handle invalid input */ }`.No dependency data recorded yet.