What is addressparser?
The addressparser npm package is used to parse email addresses into their component parts. It is particularly useful for applications that need to handle email addresses in a structured way, such as email clients, validation tools, and email processing systems.
What are addressparser's main functionalities?
Parse a single email address
This feature allows you to parse a single email address into its component parts, such as the name and the email address itself.
const addressparser = require('addressparser');
const parsed = addressparser('John Doe <john.doe@example.com>');
console.log(parsed);
Parse multiple email addresses
This feature allows you to parse a string containing multiple email addresses, separating each address into its component parts.
const addressparser = require('addressparser');
const parsed = addressparser('John Doe <john.doe@example.com>, Jane Doe <jane.doe@example.com>');
console.log(parsed);
Handle complex email address formats
This feature allows you to handle and parse more complex email address formats, including those with special characters and quoted names.
const addressparser = require('addressparser');
const parsed = addressparser('"John Doe, PhD" <john.doe@example.com>, Jane Doe <jane.doe@example.com>');
console.log(parsed);
Other packages similar to addressparser
email-addresses
The email-addresses package provides similar functionality to addressparser, allowing you to parse, validate, and manipulate email addresses. It offers more advanced parsing options and better handling of edge cases compared to addressparser.
mailparser
The mailparser package is a more comprehensive tool for parsing email messages, including headers, attachments, and body content. While it includes email address parsing as part of its functionality, it is more focused on full email message parsing rather than just addresses.
addressparser
Parse e-mail address fields
Installation
Install with npm
npm install addressparser
Usage
Include the module
var addressparser = require("addressparser");
Parse some address strings with addressparser(field)
var addresses = addressparser("andris <andris@tr.ee>");
console.log(addresses); // [{name: "andris", address:"andris@tr.ee"}]
Even complex address fields are supported
addressparser('"Bach, Sebastian" <sebu@example.com>, mozart@example.com (Mozzie)');
// [{name: "Bach, Sebastian", address: "sebu@example.com"},
// {name: "Mozzie", address: "mozart@example.com"}]
addressparser("Music Group: sebu@example.com, mozart@example.com;");
// [{name: "Music Group", address: "sebu@example.com"},
// {name: "Music Group", address: "mozart@example.com"}]
Notes
- NB! this module does not decode any mime-word or punycode encoded strings, it is only a basic parser for parsing the base data, you need to decode the encoded parts later by yourself
License
MIT