Socket
Socket
Sign inDemoInstall

email-addresses

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

email-addresses - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

15

lib/email-addresses.js
// email-addresses.js - RFC 5322 email address parser
// v 1.1.1
// v 1.1.2
//

@@ -744,2 +744,5 @@ // http://tools.ietf.org/html/rfc5322

function giveResult(ast) {
function grabSemantic(n) {
return n !== null ? n.semantic : null;
}
function tokensNoWhitespace(n) {

@@ -765,3 +768,3 @@ return n !== null ? collapseWhitespace(n.tokens) : null;

name: name,
address: address,
address: aspec,
local: local,

@@ -771,5 +774,5 @@ domain: domain

name: tokensNoWhitespace(name),
address: tokensNoWhitespace(aspec),
local: tokensNoWhitespace(local),
domain: tokensNoWhitespace(domain)
address: grabSemantic(aspec),
local: grabSemantic(local),
domain: grabSemantic(domain)
});

@@ -892,3 +895,3 @@ }

if (module) {
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = parse5322;

@@ -895,0 +898,0 @@ } else {

2

package.json
{
"version": "1.1.1",
"version": "1.1.2",
"name": "email-addresses",

@@ -4,0 +4,0 @@ "description": "An email address parser based on rfc5322",

@@ -6,3 +6,3 @@ email-addresses.js

v 1.1.1
v 1.1.2

@@ -36,3 +36,8 @@ What?

> addrs.parseOneAddress('"Jack Bowman" <jack@fogcreek.com>')
{ name: '"Jack Bowman"',
{ parts:
{ name: [Object],
address: [Object],
local: [Object],
domain: [Object] },
name: '"Jack Bowman"',
address: 'jack@fogcreek.com',

@@ -42,7 +47,17 @@ local: 'jack',

> addrs.parseAddressList('jack@fogcreek.com, Bob <bob@example.com>')
[ { name: null,
[ { parts:
{ name: null,
address: [Object],
local: [Object],
domain: [Object] },
name: null,
address: 'jack@fogcreek.com',
local: 'jack',
domain: 'fogcreek.com' },
{ name: 'Bob',
{ parts:
{ name: [Object],
address: [Object],
local: [Object],
domain: [Object] },
name: 'Bob',
address: 'bob@example.com',

@@ -59,2 +74,3 @@ local: 'bob',

[ { node: [Object],
parts: [Object],
name: null,

@@ -68,2 +84,26 @@ address: 'jack@fogcreek.com',

Usage
-----
If you want to simply check whether an address or address list parses, you'll want to call the following functions and check whether the results are null or not: ```parseOneAddress``` for a single address and ```parseAddressList``` for multiple addresses.
If you want to examine the parsed address, for example to extract a name or address, you have some options. The object returned by ```parseOneAddress``` has four helper values on it: ```name```, ```address```, ```local```, and ```domain```. See the example above to understand is actually returned. The ```name``` helper field attempts to helpfully collapse whitespace for the field, since that is what we generally expect from names. The ```address```, ```local```, and ```domain``` parts return the "semantic" values for those fields, i.e. they exclude whitespace and RFC 5322 comments. If you desire, you can also obtain the raw parsed tokens or semantic tokens for those fields. The ```parts``` value is an object referencing nodes in the AST generated. Nodes in the AST have two values of interest here, ```tokens``` and ```semantic```.
```
> a = addrs.parseOneAddress('Jack Bowman <jack@fogcreek.com >')
> a.parts.name.tokens
'Jack Bowman '
> a.parts.name.semantic
'JackBowman'
> a.name
'Jack Bowman'
> a.parts.address.tokens
'jack@fogcreek.com '
> a.parts.address.semantic
'jack@fogcreek.com'
> a.address
'jack@fogcreek.com'
```
If you need to, you can inspect the AST directly. The entire AST is returned when calling the module's function.
References

@@ -70,0 +110,0 @@ ----------

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc