email-addresses
Advanced tools
Comparing version 1.1.0 to 1.1.1
// email-addresses.js - RFC 5322 email address parser | ||
// v 1.1.0 | ||
// v 1.1.1 | ||
// | ||
@@ -715,5 +715,33 @@ // http://tools.ietf.org/html/rfc5322 | ||
// One expects names to get normalized like this: | ||
// " First Last " -> "First Last" | ||
// "First Last" -> "First Last" | ||
// "First Last" -> "First Last" | ||
function collapseWhitespace(s) { | ||
function isWhitespace(c) { | ||
return c === ' ' || | ||
c === '\t' || | ||
c === '\r' || | ||
c === '\n'; | ||
} | ||
var i, str; | ||
str = ""; | ||
for (i = 0; i < s.length; i += 1) { | ||
if (!isWhitespace(s[i]) || !isWhitespace(s[i + 1])) { | ||
str += s[i]; | ||
} | ||
} | ||
if (isWhitespace(str[0])) { | ||
str = str.substring(1); | ||
} | ||
if (isWhitespace(str[str.length - 1])) { | ||
str = str.substring(0, str.length - 1); | ||
} | ||
return str; | ||
} | ||
function giveResult(ast) { | ||
function grabSemantic(n) { | ||
return n !== null ? n.semantic : null; | ||
function tokensNoWhitespace(n) { | ||
return n !== null ? collapseWhitespace(n.tokens) : null; | ||
} | ||
@@ -735,6 +763,12 @@ var i, ret, addresses, addr, name, aspec, local, domain; | ||
node: addr, | ||
name: grabSemantic(name), | ||
address: grabSemantic(aspec), | ||
local: grabSemantic(local), | ||
domain: grabSemantic(domain) | ||
parts: { | ||
name: name, | ||
address: address, | ||
local: local, | ||
domain: domain | ||
}, | ||
name: tokensNoWhitespace(name), | ||
address: tokensNoWhitespace(aspec), | ||
local: tokensNoWhitespace(local), | ||
domain: tokensNoWhitespace(domain) | ||
}); | ||
@@ -741,0 +775,0 @@ } |
{ | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"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.0 | ||
v 1.1.1 | ||
@@ -15,2 +15,13 @@ What? | ||
Why use this? | ||
------------- | ||
Use this library because you can be sure it really respects the RFC: | ||
- The functions in the recursive decent parser match up with the productions in the RFC | ||
- The productions from the RFC are written above each function for easy verification | ||
- Tests include all of the test cases from the [is_email](https://github.com/dominicsayers/isemail) project, which are extensive | ||
Installation | ||
------------ | ||
npm install email-addresses | ||
Example | ||
@@ -62,3 +73,4 @@ ------- | ||
----- | ||
Many thanks to Dominic Sayers and his documentation and tests for the is_email function which helped greatly in writing this parser. | ||
Many thanks to [Dominic Sayers](https://github.com/dominicsayers) and his documentation and tests | ||
for the [is_email](https://github.com/dominicsayers/isemail) function which helped greatly in writing this parser. | ||
@@ -65,0 +77,0 @@ License |
@@ -31,2 +31,10 @@ var fs = require("fs"), | ||
result = fxn("First Last <first@last.com>"); | ||
t.equal(result.name, "First Last", | ||
"whitespace is not removed from display names without quotes"); | ||
result = fxn(" First Last <first@last.com>"); | ||
t.equal(result.name, "First Last", | ||
"whitespace in names is collapsed"); | ||
t.end(); | ||
@@ -33,0 +41,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84601
922
77