Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

normalize-email

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalize-email - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

license

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')
})
})
})
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