address-rfc2822
Advanced tools
Comparing version 2.0.6 to 2.1.0
## 2.1.0 - 2021-02-26 | ||
- make parse accept an options object as second argument | ||
- allow , character in display name, off by default #52 | ||
## 2.0.6 - 2020-11-17 | ||
@@ -3,0 +8,0 @@ |
15
index.js
@@ -5,3 +5,3 @@ 'use strict'; | ||
exports.parse = function parse (line, startAt) { | ||
exports.parse = function parse (line, opts = null) { | ||
if (!line) throw new Error('Nothing to parse'); | ||
@@ -11,2 +11,12 @@ | ||
const defaultOpts = { | ||
startAt: null, | ||
allowAtInDisplayName: true, | ||
allowCommaInDisplayName: false, | ||
} | ||
const { startAt, allowAtInDisplayName, allowCommaInDisplayName } = typeof opts === 'object' | ||
? Object.assign({}, defaultOpts, opts) | ||
: Object.assign({}, defaultOpts, { startAt: opts }) | ||
const addr = ea_lib({ | ||
@@ -20,3 +30,4 @@ input: line, | ||
startAt: startAt || null, | ||
atInDisplayName: true // allow at in display name | ||
atInDisplayName: allowAtInDisplayName, | ||
commaInDisplayName: allowCommaInDisplayName, | ||
}); | ||
@@ -23,0 +34,0 @@ |
{ | ||
"name": "address-rfc2822", | ||
"version": "2.0.6", | ||
"version": "2.1.0", | ||
"description": "RFC 2822 & 5322 (Header) email address parser", | ||
@@ -34,4 +34,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"email-addresses": "^3.1.0" | ||
"email-addresses": "^4.0.0" | ||
} | ||
} |
@@ -24,14 +24,23 @@ [![Build Status][ci-img]][ci-url] | ||
const addrparser = require('address-rfc2822'); | ||
```js | ||
const addrparser = require('address-rfc2822'); | ||
const addresses = addrparser.parse("Matt Sergeant <helpme+npm@gmail.com>"); | ||
const address = addresses[0]; | ||
const addresses = addrparser.parse("Matt Sergeant <helpme+npm@gmail.com>"); | ||
const address = addresses[0]; | ||
console.log(`Email address: ${address.address}`); | ||
console.log(`Email name: ${address.name()}`); | ||
console.log(`Reformatted: ${address.format()}`); | ||
console.log(`User part: ${address.user()}`); | ||
console.log(`Host part: ${address.host()}`); | ||
console.log(`Email address: ${address.address}`); | ||
console.log(`Email name: ${address.name()}`); | ||
console.log(`Reformatted: ${address.format()}`); | ||
console.log(`User part: ${address.user()}`); | ||
console.log(`Host part: ${address.host()}`); | ||
``` | ||
More Info | ||
------- | ||
- [RFC 2822](https://tools.ietf.org/html/rfc2822) | ||
- [RFC 5322](https://tools.ietf.org/html/rfc5322) | ||
License | ||
@@ -38,0 +47,0 @@ ------- |
@@ -94,1 +94,25 @@ const assert = require('assert') | ||
}) | ||
describe('parse with options', function () { | ||
it('should not allow parsing display name with comma by default', function (done) { | ||
try { | ||
address.parse('Foo, Bar <foo@example.com>'); | ||
} | ||
catch (e) { | ||
assert.equal(e.message, 'No results'); | ||
} | ||
done(); | ||
}) | ||
it('should allow parsing display name with comma', function (done) { | ||
try { | ||
const [r] = address.parse('Foo, Bar <foo@example.com>', { allowCommaInDisplayName: true }); | ||
assert.equal('foo@example.com', r.address); | ||
assert.equal('Foo, Bar', r.phrase); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
done(); | ||
}) | ||
}) |
349
60
20871
8
+ Addedemail-addresses@4.0.0(transitive)
- Removedemail-addresses@3.1.0(transitive)
Updatedemail-addresses@^4.0.0