Product
Introducing Ruby Support in Socket
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
email-addresses
Advanced tools
The email-addresses npm package is a robust tool for parsing, validating, and extracting email addresses from text. It provides a variety of functionalities to handle email addresses in different formats and contexts.
Parsing
This feature allows you to parse a single email address from a string. The parsed object contains detailed information about the email address, such as the local part and the domain.
const emailAddresses = require('email-addresses');
const parsed = emailAddresses.parseOneAddress('test@example.com');
console.log(parsed);
Validation
This feature helps in validating whether a given string is a valid email address. It returns true if the email address is valid, otherwise false.
const emailAddresses = require('email-addresses');
const isValid = emailAddresses.parseOneAddress('test@example.com') !== null;
console.log(isValid);
Extraction
This feature allows you to extract multiple email addresses from a block of text. It returns an array of parsed email address objects.
const emailAddresses = require('email-addresses');
const extracted = emailAddresses.parseAddressList('Contact us at support@example.com or sales@example.com');
console.log(extracted);
The email-validator package is a simple tool for validating email addresses. It is less feature-rich compared to email-addresses, focusing primarily on validation rather than parsing or extraction.
The validator package is a comprehensive library for string validation and sanitization, including email validation. While it offers email validation, it does not provide the detailed parsing and extraction capabilities of email-addresses.
The mailparser package is designed for parsing raw email data, including headers and body content. It can extract email addresses from headers but is more complex and geared towards processing entire email messages rather than just email addresses.
An RFC 5322 email address parser.
v 1.1.0
Want to see if something could be an email address? Want to grab the display name or just the address out of a string? Put your regexes down and use this parser!
This library does not validate email addresses - we can't really do that without sending an email. However, it attempts to parse addresses using the (fairly liberal) grammar specified in RFC 5322. You can use this to check if user input looks like an email address.
$ node
> addrs = require("email-addresses")
{ [Function: parse5322]
parseOneAddress: [Function: parseOneAddressSimple],
parseAddressList: [Function: parseAddressListSimple] }
> addrs.parseOneAddress('"Jack Bowman" <jack@fogcreek.com>')
{ name: '"Jack Bowman"',
address: 'jack@fogcreek.com',
local: 'jack',
domain: 'fogcreek.com' }
> addrs.parseAddressList('jack@fogcreek.com, Bob <bob@example.com>')
[ { name: null,
address: 'jack@fogcreek.com',
local: 'jack',
domain: 'fogcreek.com' },
{ name: 'Bob',
address: 'bob@example.com',
local: 'bob',
domain: 'example.com' } ]
> addrs("jack@fogcreek.com")
{ ast:
{ name: 'address-list',
tokens: 'jack@fogcreek.com',
semantic: 'jack@fogcreek.com',
children: [ [Object] ] },
addresses:
[ { node: [Object],
name: null,
address: 'jack@fogcreek.com',
local: 'jack',
domain: 'fogcreek.com' } ] }
> addrs("bogus")
null
Many thanks to Dominic Sayers and his documentation and tests for the is_email function which helped greatly in writing this parser.
Licensed under the MIT License. See the LICENSE file.
FAQs
An email address parser based on rfc5322
The npm package email-addresses receives a total of 402,341 weekly downloads. As such, email-addresses popularity was classified as popular.
We found that email-addresses demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.