email-validator
Advanced tools
Comparing version 1.1.1 to 1.2.1
35
index.js
@@ -1,4 +0,5 @@ | ||
"use strict"; | ||
/* eslint no-useless-escape: "error" */ | ||
'use strict'; | ||
var tester = /^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-?\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/; | ||
const tester = /^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-?\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/; // eslint-disable-line no-useless-escape | ||
// Thanks to: | ||
@@ -8,24 +9,30 @@ // http://fightingforalostcause.net/misc/2006/compare-email-regex.php | ||
// http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses/201378#201378 | ||
exports.validate = function(email) | ||
{ | ||
if (!email) | ||
exports.validate = function (email) { | ||
if (!email) { | ||
return false; | ||
if(email.length>254) | ||
} | ||
if (email.length > 254) { | ||
return false; | ||
} | ||
var valid = tester.test(email); | ||
if(!valid) | ||
const valid = tester.test(email); | ||
if (!valid) { | ||
return false; | ||
} | ||
// Further checking of some things regex can't handle | ||
var parts = email.split("@"); | ||
if(parts[0].length>64) | ||
const parts = email.split('@'); | ||
if (parts[0].length > 64) { | ||
return false; | ||
} | ||
var domainParts = parts[1].split("."); | ||
if(domainParts.some(function(part) { return part.length>63; })) | ||
const domainParts = parts[1].split('.'); | ||
if (domainParts.some(part => { | ||
return part.length > 63; | ||
})) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
}; |
{ | ||
"name": "email-validator", | ||
"version": "1.1.1", | ||
"author": "Robert Schultz <robert@cosmicrealms.com>", | ||
"version": "1.2.1", | ||
"author": "Manish Saraan <manish021js@gmail.com>", | ||
"description": "Provides a fast, pretty robust e-mail validator. Only checks form, not function.", | ||
"main": "index", | ||
"scripts": { | ||
"test": "mocha test.js && xo index.js --fix" | ||
}, | ||
"typings": "index.d.ts", | ||
@@ -17,7 +20,7 @@ "engines": { | ||
], | ||
"homepage": "http://github.com/Sembiance/email-validator", | ||
"homepage": "http://github.com/manishsaraan/email-validator", | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://github.com/Sembiance/email-validator/raw/master/LICENSE" | ||
"url": "http://github.com/manishsaraan/email-validator/raw/master/LICENSE" | ||
} | ||
@@ -27,2 +30,7 @@ ], | ||
{ | ||
"name": "Manish Saraan", | ||
"email": "manish021js@gmail.com", | ||
"url": "https://github.com/manishsaraan" | ||
}, | ||
{ | ||
"name": "Brad Martin", | ||
@@ -35,4 +43,9 @@ "email": "bradwaynemartin@gmail.com", | ||
"type": "git", | ||
"url": "http://github.com/Sembiance/email-validator.git" | ||
"url": "http://github.com/manishsaraan/email-validator.git" | ||
}, | ||
"devDependencies": { | ||
"chai": "4.1.2", | ||
"mocha": "5.0.5", | ||
"xo": "^0.20.3" | ||
} | ||
} |
# email-validator | ||
A simple module to validate an e-mail address | ||
[![travis build](https://img.shields.io/travis/manishsaraan/email-validator.svg?style=flat-square)](https://travis-ci.org/manishsaraan/email-validator) | ||
[![version](https://img.shields.io/npm/v/email-validator.svg?style=flat-square)]((http://npm.im/email-validator)) | ||
[![downloads](https://img.shields.io/npm/dm/email-validator.svg?style=flat-square)](https://npm-stat.com/charts.html?package=email-validators&from=2015-08-01) | ||
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg?style=flat-square)](https://github.com/xojs/xo) | ||
## Installation | ||
@@ -41,6 +46,7 @@ Install via NPM: | ||
robert@cosmicrealms.com | ||
* robert@cosmicrealms.com | ||
* manish021js@gmail.com | ||
Distributed under the unlicense public domain. See ``LICENSE`` for more information. | ||
[https://github.com/Sembiance/email-validator](https://github.com/Sembiance/email-validator) | ||
[https://github.com/manishsaraan/email-validator](https://github.com/manishsaraan/email-validator) |
44
test.js
@@ -1,6 +0,5 @@ | ||
"use strict"; | ||
const expect = require('chai').expect; | ||
const validator = require("."); | ||
var validator = require("./index"); | ||
var validSupported = | ||
const validSupported = | ||
[ | ||
@@ -31,3 +30,3 @@ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org", | ||
var validUnsupported = | ||
const validUnsupported = | ||
[ | ||
@@ -43,3 +42,3 @@ "\"quoted\"@sld.com", | ||
var invalidSupported = | ||
const invalidSupported = | ||
[ | ||
@@ -74,19 +73,20 @@ "@missing-local.org", | ||
]; | ||
describe('TEST EMAILS AGAINST VALIDATOR', () => { | ||
it('Should Be Valid', () => { | ||
validSupported.forEach( email => { | ||
expect(validator.validate(email)).to.equal(true); | ||
}); | ||
}); | ||
console.log('SYNC VERSION TESTS') | ||
console.log('=====================') | ||
console.log("SUPPORTED BY MODULE:\n"); | ||
it('Should Be Invalid', () => { | ||
invalidSupported.forEach( email => { | ||
expect(validator.validate(email)).to.equal(false); | ||
}); | ||
}); | ||
console.log("SHOULD BE VALID:"); | ||
validSupported.forEach(function(email) { console.log("%s : %s", validator.validate(email) ? " VALID" : " INVALID", email); }); | ||
console.log("\nSHOULD BE INVALID:"); | ||
invalidSupported.forEach(function(email) { console.log("%s : %s", validator.validate(email) ? " VALID" : " INVALID", email); }); | ||
console.log("\n\nNOT SUPPORTED BY MODULE:\n"); | ||
console.log("SHOULD BE VALID:"); | ||
validUnsupported.forEach(function(email) { console.log("%s : %s", validator.validate(email) ? " VALID" : " INVALID", email); }); | ||
process.exit(0); | ||
it('Should Be Invalid(UnSupported By Module)', () => { | ||
validUnsupported.forEach( email => { | ||
expect(validator.validate(email)).to.equal(false); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
17973
10
380
0
52
3
2