normalize-email
Advanced tools
Comparing version 1.0.0 to 1.1.0
62
index.js
@@ -1,37 +0,49 @@ | ||
'use strict' | ||
'use strict'; | ||
var isEmail = require('is-email') | ||
module.exports = function normalizeEmail(email) { | ||
if (typeof email != 'string') { | ||
throw new TypeError('normalize-email expects a string') | ||
var PLUS_ONLY = /\+.*$/; | ||
var PLUS_AND_DOT = /\.|\+.*$/g; | ||
var normalizeableProviders = { | ||
'gmail.com': { | ||
'cut': PLUS_AND_DOT | ||
}, | ||
'googlemail.com': { | ||
'cut': PLUS_AND_DOT, | ||
'aliasOf': 'gmail.com' | ||
}, | ||
'hotmail.com': { | ||
'cut': PLUS_ONLY | ||
}, | ||
'live.com': { | ||
'cut': PLUS_AND_DOT | ||
}, | ||
'outlook.com': { | ||
'cut': PLUS_ONLY | ||
} | ||
}; | ||
if (!isEmail(email)) { | ||
return email | ||
module.exports = function normalizeEmail(eMail) { | ||
if (typeof eMail != 'string') { | ||
throw new TypeError('normalize-email expects a string'); | ||
} | ||
email = email.toLowerCase() | ||
var email = eMail.toLowerCase(); | ||
var emailParts = email.split(/@/); | ||
var emailParts = email.split(/@/) | ||
var username = emailParts[0] | ||
var domain = emailParts[1] | ||
if (emailParts.length !== 2) { | ||
return eMail; | ||
} | ||
if (isNormalizeableProvider(domain)) { | ||
username = username.split('+')[0] | ||
var username = emailParts[0]; | ||
var domain = emailParts[1]; | ||
if(!/hotmail\.com$/.test(domain)) { | ||
username = username.replace(/\./g, '') | ||
if (normalizeableProviders.hasOwnProperty(domain)) { | ||
if (normalizeableProviders[domain].hasOwnProperty('cut')) { | ||
username = username.replace(normalizeableProviders[domain].cut, ''); | ||
} | ||
if (normalizeableProviders[domain].hasOwnProperty('aliasOf')) { | ||
domain = normalizeableProviders[domain].aliasOf; | ||
} | ||
} | ||
if (domain == 'googlemail.com') { | ||
domain = 'gmail.com' | ||
} | ||
return username + '@' + domain | ||
return username + '@' + domain; | ||
} | ||
function isNormalizeableProvider(domain) { | ||
return /^hotmail\.com|gmail\.com|googlemail\.com|live\.com$/.test(domain) | ||
} |
@@ -5,3 +5,3 @@ { | ||
"author": "John Otander", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "index.js", | ||
@@ -23,3 +23,4 @@ "directories": { | ||
"hotmail", | ||
"live" | ||
"live", | ||
"outlook" | ||
], | ||
@@ -31,5 +32,2 @@ "license": "MIT", | ||
"homepage": "https://github.com/johnotander/normalize-email", | ||
"dependencies": { | ||
"is-email": "^0.1.1" | ||
}, | ||
"devDependencies": { | ||
@@ -36,0 +34,0 @@ "mocha": "*" |
@@ -31,2 +31,9 @@ var assert = require('assert') | ||
var outlookEmailsToNormalize = [ | ||
'john.otander@outlook.com', | ||
'JOHN.otander@outlook.com', | ||
'john.Otander+any.label@outlook.com', | ||
'john.otander+foobar@outlook.com', | ||
] | ||
describe('normalize-email', function() { | ||
@@ -55,2 +62,9 @@ | ||
}) | ||
it('should normalize outlook emails', function() { | ||
outlookEmailsToNormalize.forEach(function(email) { | ||
assert.equal(normalizeEmail(email), 'john.otander@outlook.com') | ||
}) | ||
}) | ||
}) |
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
6107
0
99
5
- Removedis-email@^0.1.1
- Removedis-email@0.1.1(transitive)