emailaddress
v0.1.1
Published
Email address object.
Downloads
3
Readme
emailaddress
Represents email addresses as objects. Parses an address from a string and validates the format. Can also parse multiple addresses from a string or array of strings.
Usage
Example 1
const EmailAddress = require('emailaddress'); let emailAddress = new EmailAddress('Somebody [email protected]');
emailAddress.valueOf();
emailAddress.toString();
'Somebody [email protected]'
emailAddress.toJSON();
{ address: '[email protected]', domain: 'example.com', local: 'somebody', name: 'Somebody', original: 'Somebody [email protected]' }
emailAddress.address;
emailAddress.domain;
'example.com'
emailAddress.local;
'somebody'
emailAddress.name;
'Somebody'
Example 2
const EmailAddress = require('emailaddress'); let emailAddress = new EmailAddress('n00b <@.>');
emailAddress.valueOf();
undefined
emailAddress.toString();
'n00b <@.>'
emailAddress.toJSON();
{ address: null, domain: null, local: null, name: null, original: 'n00b <@.>' }
emailAddress.address;
undefined
emailAddress.domain;
undefined
emailAddress.local;
undefined
emailAddress.name;
undefined
Example 3
const EmailAddress = require('emailaddress'); let emailAddress = new EmailAddress('[email protected]');
emailAddress.valueOf();
emailAddress.toString();
emailAddress.toJSON();
{ address: '[email protected]', domain: 'example.com', local: 'nobody', name: null, original: '[email protected]' }
emailAddress.address;
emailAddress.domain;
'example.com'
emailAddress.local;
'nobody'
emailAddress.name;
undefined
Example 4
const EmailAddress = require('emailaddress'); let to = 'Somebody [email protected],n00b <@.>,[email protected]'; let emailAddresses = EmailAddress.parseEmailAddresses(to);
emailAddresses.length;
2
emailAddresses[0].toJSON();
{ address: '[email protected]', domain: 'example.com', local: 'somebody', name: 'Somebody', original: 'Somebody [email protected]' }
emailAddresses[1].toJSON();
{ address: '[email protected]', domain: 'example.com', local: 'nobody', name: null, original: '[email protected]' }
Example 5
const EmailAddress = require('emailaddress'); let to = ['Somebody [email protected]','n00b <@.>','[email protected]']; let emailAddresses = EmailAddress.parseEmailAddresses(to);
emailAddresses.length;
2
emailAddresses[0].toJSON();
{ address: '[email protected]', domain: 'example.com', local: 'somebody', name: 'Somebody', original: 'Somebody [email protected]' }
emailAddresses[1].toJSON();
{ address: '[email protected]', domain: 'example.com', local: 'nobody', name: null, original: '[email protected]' }
Example 6
const EmailAddress = require('emailaddress'); let to = ['Somebody [email protected]','n00b <@.>','[email protected]']; let emailAddresses = [...EmailAddress.emailAddresses(to)]
emailAddresses.length;
3
emailAddresses[0].toJSON();
{ address: '[email protected]', domain: 'example.com', local: 'somebody', name: 'Somebody', original: 'Somebody [email protected]' }
emailAddresses[1].toJSON();
{ address: null, domain: null, local: null, name: null, original: 'n00b <@.>' }
emailAddresses[2].toJSON();
{ address: '[email protected]', domain: 'example.com', local: 'nobody', name: null, original: '[email protected]' }
Dependencies
- [email-addresses]
Requires Node 4 with harmony features or Traceur.
License
ISC