Socket
Socket
Sign inDemoInstall

isemail

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isemail - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

test/tests.json

18

package.json
{
"name": "isemail",
"version": "1.1.2",
"version": "1.2.0",
"author": "Eli Skeggs <skeggse@gmail.com>",

@@ -8,3 +8,4 @@ "description": "validate an email address according to RFCs 5321, 5322, and others",

"scripts": {
"test": "mocha"
"test": "lab -r console -o stdout -r lcov -o coverage.lcov -a code -L",
"test-cov-html": "lab -r html -o coverage.html -a code"
},

@@ -28,14 +29,9 @@ "repository": {

"devDependencies": {
"mocha": "~2.3.2",
"chai": "~3.2.0"
"code": "^1.5.0",
"lab": "^5.16.1"
},
"licenses": [
{
"type": "BSD",
"url": "http://www.opensource.org/licenses/bsd-license.php"
}
],
"license": "BSD-2-Clause",
"engines": {
"node": ">=0.8.0"
"node": ">=0.10"
}
}
isemail
=======
Node email address validation library
[![Build Status](https://travis-ci.org/hapijs/isemail.png)](https://travis-ci.org/hapijs/isemail)
[![Coverage Status](https://coveralls.io/repos/hapijs/isemail/badge.png?branch=master)](https://coveralls.io/r/hapijs/isemail?branch=master)
Lead Maintainer: [Eli Skeggs](https://github.com/skeggse)
This first version of `isemail` is a port of the PHP `is_email` function by Dominic Sayers.
Future versions will improve upon the current version, optimizing it for efficient usage and DRYing the code.
Install

@@ -21,3 +23,3 @@ -------

The tests were pulled from is_email's extensive [test suite][tests] on October 15, 2013. Many thanks to the contributors!
The tests were pulled from is_email's extensive [test suite][tests] on October 15, 2013. Many thanks to the contributors! Additional tests have been added to increase code coverage and verify edge-cases.

@@ -27,3 +29,3 @@ Run any of the following.

```sh
$ mocha
$ lab
$ npm test

@@ -88,2 +90,3 @@ $ make test

Add tests for library usage, not just functionality comparisons.
Future versions will improve upon the current version, optimizing it for efficient usage and DRYing the code.

@@ -90,0 +93,0 @@ License

@@ -1,185 +0,33 @@

var expect = require('chai').expect;
var isEmail = require('..');
var Lab = require('lab');
var Code = require('code');
var IsEmail = require('..');
var Tests = require('./tests.json');
// diagnoses
var internals = {
defaultThreshold: 16
};
// Test shortcuts
var isEmail = IsEmail;
var lab = exports.lab = Lab.script();
var before = lab.before;
var after = lab.after;
var describe = lab.describe;
var it = lab.it;
var expect = Code.expect;
// Diagnoses
var diag = isEmail.diagnoses;
// expectations
var expectations = [
['', diag.errNoDomain],
['test', diag.errNoDomain],
['@', diag.errNoLocalPart],
['test@', diag.errNoDomain],
['test@io', diag.valid],
['@io', diag.errNoLocalPart],
['@iana.org', diag.errNoLocalPart],
['test@iana.org', diag.valid],
['test@nominet.org.uk', diag.valid],
['test@about.museum', diag.valid],
['a@iana.org', diag.valid],
['test@e.com', diag.dnsWarnNoRecord],
['test@iana.a', diag.dnsWarnNoRecord],
['test.test@iana.org', diag.valid],
['.test@iana.org', diag.errDotStart],
['test.@iana.org', diag.errDotEnd],
['test..iana.org', diag.errConsecutiveDots],
['test_exa-mple.com', diag.errNoDomain],
['!#$%&`*+/=?^`{|}~@iana.org', diag.valid],
['test\\@test@iana.org', diag.errExpectingATEXT],
['123@iana.org', diag.valid],
['test@123.com', diag.valid],
['test@iana.123', diag.rfc5321TLDNumeric],
['test@255.255.255.255', diag.rfc5321TLDNumeric],
['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@iana.org', diag.valid],
['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklmn@iana.org', diag.rfc5322LocalTooLong],
['test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm', diag.rfc5322LabelTooLong],
['test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.com', diag.dnsWarnNoRecord],
['test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm.com', diag.rfc5322LabelTooLong],
['test@mason-dixon.com', diag.valid],
['test@-iana.org', diag.errDomainHyphenStart],
['test@iana-.com', diag.errDomainHyphenEnd],
//['test@aaad.com', diag.dnsWarnNoMXRecord],
['test@iana.co-uk', diag.dnsWarnNoRecord],
['test@.iana.org', diag.errDotStart],
['test@iana.org.', diag.errDotEnd],
['test@iana..com', diag.errConsecutiveDots],
['a@a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v', diag.dnsWarnNoRecord],
['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi', diag.dnsWarnNoRecord],
['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij', diag.rfc5322TooLong],
['a@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.hij', diag.rfc5322TooLong],
['a@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.hijk', diag.rfc5322DomainTooLong],
['"test"@iana.org', diag.rfc5321QuotedString],
['""@iana.org', diag.rfc5321QuotedString],
['"""@iana.org', diag.errExpectingATEXT],
['"\\a"@iana.org', diag.rfc5321QuotedString],
['"\\""@iana.org', diag.rfc5321QuotedString],
['"\\"@iana.org', diag.errUnclosedQuotedString],
['"\\\\"@iana.org', diag.rfc5321QuotedString],
['test"@iana.org', diag.errExpectingATEXT],
['"test@iana.org', diag.errUnclosedQuotedString],
['"test"test@iana.org', diag.errATEXTAfterQS],
['test"text"@iana.org', diag.errExpectingATEXT],
['"test""test"@iana.org', diag.errExpectingATEXT],
['"test"."test"@iana.org', diag.deprecatedLocalPart],
['"test\\ test"@iana.org', diag.rfc5321QuotedString],
['"test".test@iana.org', diag.deprecatedLocalPart],
['"test\0"@iana.org', diag.errExpectingQTEXT],
['"test\\\0"@iana.org', diag.deprecatedQP],
['"test\r\n test"@iana.org', diag.cfwsFWS],
['"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghj"@iana.org', diag.rfc5322LocalTooLong],
['"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefg\\h"@iana.org', diag.rfc5322LocalTooLong],
['test@[255.255.255.255]', diag.rfc5321AddressLiteral],
['test@a[255.255.255.255]', diag.errExpectingATEXT],
['test@[255.255.255]', diag.rfc5322DomainLiteral],
['test@[255.255.255.255.255]', diag.rfc5322DomainLiteral],
['test@[255.255.255.256]', diag.rfc5322DomainLiteral],
['test@[1111:2222:3333:4444:5555:6666:7777:8888]', diag.rfc5322DomainLiteral],
['test@[IPv6:1111:2222:3333:4444:5555:6666:7777]', diag.rfc5322IPv6GroupCount],
['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]', diag.rfc5321AddressLiteral],
['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]', diag.rfc5322IPv6GroupCount],
['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:888G]', diag.rfc5322IPv6BadCharacter],
['test@[IPv6:1111:2222:3333:4444:5555:6666::8888]', diag.deprecatedIPv6],
['test@[IPv6:1111:2222:3333:4444:5555::8888]', diag.rfc5321AddressLiteral],
['test@[IPv6:1111:2222:3333:4444:5555:6666::7777:8888]', diag.rfc5322IPv6MaxGroups],
['test@[IPv6::3333:4444:5555:6666:7777:8888]', diag.rfc5322IPv6ColonStart],
['test@[IPv6:::3333:4444:5555:6666:7777:8888]', diag.rfc5321AddressLiteral],
['test@[IPv6:1111::4444:5555::8888]', diag.rfc5322IPv62x2xColon],
['test@[IPv6:::]', diag.rfc5321AddressLiteral],
['test@[IPv6:1111:2222:3333:4444:5555:255.255.255.255]', diag.rfc5322IPv6GroupCount],
['test@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255]', diag.rfc5321AddressLiteral],
['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:255.255.255.255]', diag.rfc5322IPv6GroupCount],
['test@[IPv6:1111:2222:3333:4444::255.255.255.255]', diag.rfc5321AddressLiteral],
['test@[IPv6:1111:2222:3333:4444:5555:6666::255.255.255.255]', diag.rfc5322IPv6MaxGroups],
['test@[IPv6:1111:2222:3333:4444:::255.255.255.255]', diag.rfc5322IPv62x2xColon],
['test@[IPv6::255.255.255.255]', diag.rfc5322IPv6ColonStart],
[' test @iana.org', diag.deprecatedCFWSNearAt],
['test@ iana .com', diag.deprecatedCFWSNearAt],
['test . test@iana.org', diag.deprecatedFWS],
['\r\n test@iana.org', diag.cfwsFWS],
['\r\n \r\n test@iana.org', diag.deprecatedFWS],
['(comment)test@iana.org', diag.cfwsComment],
['((comment)test@iana.org', diag.errUnclosedComment],
['(comment(comment))test@iana.org', diag.cfwsComment],
['test@(comment)iana.org', diag.deprecatedCFWSNearAt],
['test(comment)test@iana.org', diag.errATEXTAfterCFWS],
['test@(comment)[255.255.255.255]', diag.deprecatedCFWSNearAt],
['(comment)abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@iana.org', diag.cfwsComment],
['test@(comment)abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.com', diag.deprecatedCFWSNearAt],
['(comment)test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghik.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghik.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstu', diag.cfwsComment],
['test@iana.org\n', diag.errExpectingATEXT],
['test@xn--hxajbheg2az3al.xn--jxalpdlp', diag.dnsWarnNoRecord],
['xn--test@iana.org', diag.valid],
['test@iana.org-', diag.errDomainHyphenEnd],
['"test@iana.org', diag.errUnclosedQuotedString],
['(test@iana.org', diag.errUnclosedComment],
['test@(iana.org', diag.errUnclosedComment],
['test@[1.2.3.4', diag.errUnclosedDomainLiteral],
['"test\\"@iana.org', diag.errUnclosedQuotedString],
['(comment\\)test@iana.org', diag.errUnclosedComment],
['test@iana.org(comment\\)', diag.errUnclosedComment],
['test@iana.org(comment\\', diag.errBackslashEnd],
['test@[RFC-5322-domain-literal]', diag.rfc5322DomainLiteral],
['test@[RFC-5322]-domain-literal]', diag.errATEXTAfterDomainLiteral],
['test@[RFC-5322-[domain-literal]', diag.errExpectingDTEXT],
['test@[RFC-5322-\\\x07-domain-literal]', diag.rfc5322DomainLiteralOBSDText],
['test@[RFC-5322-\\\t-domain-literal]', diag.rfc5322DomainLiteralOBSDText],
['test@[RFC-5322-\\]-domain-literal]', diag.rfc5322DomainLiteralOBSDText],
['test@[RFC-5322-\x7f-domain-literal]', diag.rfc5322DomainLiteralOBSDText],
['test@[RFC-5322-domain-literal\\]', diag.errUnclosedDomainLiteral],
['test@[RFC-5322-domain-literal\\', diag.errBackslashEnd],
['test@[RFC 5322 domain literal]', diag.rfc5322DomainLiteral],
['test@[RFC-5322-domain-literal] (comment)', diag.rfc5322DomainLiteral],
['\x7f@iana.org', diag.errExpectingATEXT],
['test@\x7f.org', diag.errExpectingATEXT],
['"\x7f"@iana.org', diag.deprecatedQTEXT],
['"\\\x7f"@iana.org', diag.deprecatedQP],
['(\x7f)test@iana.org', diag.deprecatedCTEXT],
['test@iana.org\r', diag.errCRNoLF],
['\rtest@iana.org', diag.errCRNoLF],
['"\rtest"@iana.org', diag.errCRNoLF],
['(\r)test@iana.org', diag.errCRNoLF],
['test@iana.org(\r)', diag.errCRNoLF],
['\ntest@iana.org', diag.errExpectingATEXT],
['"\n"@iana.org', diag.errExpectingQTEXT],
['"\\\n"@iana.org', diag.deprecatedQP],
['(\n)test@iana.org', diag.errExpectingCTEXT],
['\x07@iana.org', diag.errExpectingATEXT],
['test@\x07.org', diag.errExpectingATEXT],
['"\x07"@iana.org', diag.deprecatedQTEXT],
['"\\\x07"@iana.org', diag.deprecatedQP],
['(\x07)test@iana.org', diag.deprecatedCTEXT],
['\r\ntest@iana.org', diag.errFWSCRLFEnd],
['\r\n \r\ntest@iana.org', diag.errFWSCRLFEnd],
[' \r\ntest@iana.org', diag.errFWSCRLFEnd],
[' \r\n test@iana.org', diag.cfwsFWS],
[' \r\n \r\ntest@iana.org', diag.errFWSCRLFEnd],
[' \r\n\r\ntest@iana.org', diag.errFWSCRLFx2],
[' \r\n\r\n test@iana.org', diag.errFWSCRLFx2],
['test@iana.org\r\n ', diag.cfwsFWS],
['test@iana.org\r\n \r\n ', diag.deprecatedFWS],
['test@iana.org\r\n', diag.errFWSCRLFEnd],
['test@iana.org \r', diag.errCRNoLF],
['test@iana.org\r\n \r\n', diag.errFWSCRLFEnd],
['test@iana.org \r\n', diag.errFWSCRLFEnd],
['test@iana.org \r\n ', diag.cfwsFWS],
['test@iana.org \r\n \r\n', diag.errFWSCRLFEnd],
['test@iana.org \r\n\r\n', diag.errFWSCRLFx2],
['test@iana.org \r\n\r\n ', diag.errFWSCRLFx2],
['test@iana. org', diag.deprecatedFWS],
['test@[\r', diag.errCRNoLF],
['test@[\r\n', diag.errFWSCRLFEnd],
[' test@iana.org', diag.cfwsFWS],
['test@iana.org ', diag.cfwsFWS],
['test@[IPv6:1::2:]', diag.rfc5322IPv6ColonEnd],
['"test\\ยฉ"@iana.org', diag.errExpectingQPair],
['test@iana/icann.org', diag.rfc5322Domain],
['test.(comment)test@iana.org', diag.deprecatedComment],
['test@iana.(comment)org', diag.deprecatedComment],
['test@iana(comment)iana.org', diag.errATEXTAfterCFWS],
['(comment\r\n comment)test@iana.org', diag.cfwsFWS],
['test@org', diag.rfc5321TLD],
['test@example.com', diag.dnsWarnNoMXRecord],
['test@nic.no', diag.dnsWarnNoRecord]
];
// Expectations
var expectations = Tests.map(function mapper (value) {
value[1] = diag[value[1]];
return value;
});
// Null characters aren't supported in JSON
expectations.push(['test@[\0', diag.errExpectingDTEXT]);
expectations.push(['(\0)test@example.com', diag.errExpectingCTEXT]);
var tldExpectations = [

@@ -192,2 +40,79 @@ ['shouldbe@invalid', diag.errUnknownTLD],

it('should check options.tldWhitelist', function (done) {
expect(isEmail('person@top', {
tldWhitelist: 'top',
checkDNS: false
})).to.equal(true);
expect(isEmail('person@top', {
tldWhitelist: ['com'],
checkDNS: false
})).to.equal(false);
expect(function () {
isEmail('', {
tldWhitelist: 77
});
}).to.throw(/tldWhitelist/);
done();
});
it('should check options.minDomainAtoms', function (done) {
expect(function () {
isEmail('person@top', {
minDomainAtoms: -1
});
}).to.throw(/minDomainAtoms/);
expect(function () {
isEmail('person@top', {
minDomainAtoms: 1.5
});
}).to.throw(/minDomainAtoms/);
done();
});
it('should use options.errorLevel', function (done) {
expect(isEmail('person@123', {
errorLevel: diag.rfc5321TLDNumeric + 1
})).to.equal(0);
expect(isEmail('person@123', {
errorLevel: diag.rfc5321TLDNumeric
})).to.equal(diag.rfc5321TLDNumeric);
done();
});
it('should ensure callback provided with checkDNS', function (done) {
expect(function () {
isEmail('person@top', {
checkDNS: true
});
}).to.throw(/(?=.*\bcheckDNS\b)(?=.*\bcallback\b)/);
done();
});
it('should handle omitted options', function (done) {
expect(isEmail(expectations[0][0])).to.equal(expectations[0][1] < internals.defaultThreshold);
done();
});
it('should handle omitted options with callback', function (done) {
isEmail(expectations[0][0], function (res) {
expect(res).to.equal(expectations[0][1] < internals.defaultThreshold);
done();
});
});
expectations.forEach(function (obj, i) {

@@ -214,3 +139,3 @@

it('should handle tld test ' + (i + 1), function () {
it('should handle tld test ' + (i + 1), function (done) {

@@ -228,6 +153,8 @@ expect(isEmail(email, {

})).to.equal(result);
done();
});
});
it('should handle domain atom test 1', function () {
it('should handle domain atom test 1', function (done) {

@@ -238,5 +165,7 @@ expect(isEmail('shouldbe@invalid', {

})).to.equal(diag.errDomainTooShort);
done();
});
it('should handle domain atom test 2', function () {
it('should handle domain atom test 2', function (done) {

@@ -247,3 +176,5 @@ expect(isEmail('valid@example.com', {

})).to.equal(diag.valid);
done();
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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