commons-validator-js
Advanced tools
Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "commons-validator-js", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "JavaScript port of Apache Commons Validator", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
"use strict" | ||
import * as Domains from "./Domains.js" | ||
import * as Domains from "./Domains" | ||
import _ from 'lodash' | ||
@@ -9,5 +9,5 @@ import * as punycode from 'punycode' | ||
constructor() { | ||
let domainLabelRegex = "[a-zA-Z0-9](?:[a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?" | ||
let topLabelRegex = "[a-zA-Z](?:[a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?" | ||
let domainNameRegex = "^(?:" + domainLabelRegex + "\\.)*(" + topLabelRegex + ")\\.?$" | ||
const domainLabelRegex = "[a-zA-Z0-9](?:[a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?" | ||
const topLabelRegex = "[a-zA-Z](?:[a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?" | ||
const domainNameRegex = "^(?:" + domainLabelRegex + "\\.)*(" + topLabelRegex + ")\\.?$" | ||
this._domainRegex = new RegExp(domainNameRegex) | ||
@@ -29,11 +29,11 @@ } | ||
isValidCountryCodeTld(ccTld) { | ||
let key = this._chompLeadingDot(this._unicodeToASCII(ccTld).toLowerCase()) | ||
const key = this._chompLeadingDot(this._unicodeToASCII(ccTld).toLowerCase()) | ||
return this._arrayContains(Domains.countryCodeTlds, key) | ||
} | ||
isValidGenericTld(gTld) { | ||
let key = this._chompLeadingDot(this._unicodeToASCII(gTld).toLowerCase()) | ||
const key = this._chompLeadingDot(this._unicodeToASCII(gTld).toLowerCase()) | ||
return this._arrayContains(Domains.genericTlds, key) | ||
} | ||
isValidInfrastructureTld(iTld) { | ||
let key = this._chompLeadingDot(this._unicodeToASCII(iTld).toLowerCase()) | ||
const key = this._chompLeadingDot(this._unicodeToASCII(iTld).toLowerCase()) | ||
return this._arrayContains(Domains.infrastructureTlds, key) | ||
@@ -54,3 +54,3 @@ } | ||
} | ||
let groups = domain.match(this._domainRegex) | ||
const groups = domain.match(this._domainRegex) | ||
if (groups) { | ||
@@ -62,3 +62,3 @@ return groups[1] | ||
isValid(domain) { | ||
let tld = this.extractTld(domain) | ||
const tld = this.extractTld(domain) | ||
if (!tld) { | ||
@@ -65,0 +65,0 @@ return null |
"use strict" | ||
import {DomainValidator} from "./DomainValidator.js" | ||
import {DomainValidator} from "./DomainValidator" | ||
export class EmailValidator { | ||
constructor() { | ||
//let specialChars = "\\p{Cntrl}\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]" // TODO: \\p{Cntrl} | ||
let specialChars = "\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]" | ||
let validChars = "[^\\s" + specialChars + "]" | ||
let quotedUser = "(\"[^\"]*\")" | ||
let word = "((" + validChars + "|')+|" + quotedUser + ")" | ||
let userRegex = "^\\s*" + word + "(\\." + word + ")*$" | ||
//const specialChars = "\\p{Cntrl}\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]" // TODO: \\p{Cntrl} | ||
const specialChars = "\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]" | ||
const validChars = "[^\\s" + specialChars + "]" | ||
const quotedUser = "(\"[^\"]*\")" | ||
const word = "((" + validChars + "|')+|" + quotedUser + ")" | ||
const userRegex = "^\\s*" + word + "(\\." + word + ")*$" | ||
this._userPattern = new RegExp(userRegex) | ||
let emailRegex = "^\\s*?(.+)@(.+?)\\s*$" | ||
const emailRegex = "^\\s*?(.+)@(.+?)\\s*$" | ||
this._emailPattern = new RegExp(emailRegex) | ||
@@ -39,3 +39,3 @@ | ||
let groups = email.match(this._emailPattern) | ||
const groups = email.match(this._emailPattern) | ||
if (!groups) { | ||
@@ -42,0 +42,0 @@ return false |
"use strict" | ||
import {expect, assert} from "chai" | ||
import {DomainValidator} from "../src/DomainValidator.js" | ||
import {DomainValidator} from "../src/DomainValidator" | ||
describe("DomainValidator", function() { | ||
let validator = new DomainValidator() | ||
describe("DomainValidator", () => { | ||
const validator = new DomainValidator() | ||
it ("passes Apache's DomainValidatorTest#testValidDomains", function() { | ||
it ("passes Apache's DomainValidatorTest#testValidDomains", () => { | ||
assert.ok(validator.isValid("apache.org"), "apache.org should validate") | ||
@@ -25,3 +25,3 @@ assert.ok(validator.isValid("www.google.com"), "www.google.com should validate") | ||
it ("passes Apache's DomainValidatorTest#testInvalidDomains", function() { | ||
it ("passes Apache's DomainValidatorTest#testInvalidDomains", () => { | ||
assert.notOk(validator.isValid(".org"), "bare TLD .org shouldn't validate") | ||
@@ -41,3 +41,3 @@ assert.notOk(validator.isValid(" apache.org "), "domain name with spaces shouldn't validate") | ||
it ("passes Apache's DomainValidatorTest#testTopLevelDomains", function() { | ||
it ("passes Apache's DomainValidatorTest#testTopLevelDomains", () => { | ||
// infrastructure TLDs | ||
@@ -65,7 +65,7 @@ assert.ok(validator.isValidInfrastructureTld(".arpa"), ".arpa should validate as iTLD") | ||
it ("passes Apache's DomainValidatorTest#testIDN", function() { | ||
it ("passes Apache's DomainValidatorTest#testIDN", () => { | ||
assert.ok(validator.isValid("www.xn--bcher-kva.ch"), "b\u00fccher.ch in IDN should validate") | ||
}) | ||
it ("passes Apache's DomainValidatorTest#testIDNJava6OrLater", function() { | ||
it ("passes Apache's DomainValidatorTest#testIDNJava6OrLater", () => { | ||
assert.ok(validator.isValid("www.b\u00fccher.ch"), "b\u00fccher.ch should validate") | ||
@@ -77,3 +77,3 @@ assert.ok(validator.isValid("xn--d1abbgf6aiiy.xn--p1ai"), "xn--d1abbgf6aiiy.xn--p1ai should validate") | ||
it ("passes Apache's DomainValidatorTest#testRFC2396domainlabel", function() { | ||
it ("passes Apache's DomainValidatorTest#testRFC2396domainlabel", () => { | ||
assert.ok(validator.isValid("a.ch"), "a.ch should validate") | ||
@@ -88,3 +88,3 @@ assert.ok(validator.isValid("9.ch"), "9.ch should validate") | ||
it ("passes Apache's DomainValidatorTest#testRFC2396toplabel", function() { | ||
it ("passes Apache's DomainValidatorTest#testRFC2396toplabel", () => { | ||
assert.ok(validator.extractTld("a.c"), "a.c (alpha) should validate") | ||
@@ -102,3 +102,3 @@ assert.ok(validator.extractTld("a.cc"), "a.cc (alpha alpha) should validate") | ||
it ("passes Apache's DomainValidatorTest#testDomainNoDots", function() { | ||
it ("passes Apache's DomainValidatorTest#testDomainNoDots", () => { | ||
assert.ok(validator.extractTld("a"), "a (alpha) should validate") | ||
@@ -113,8 +113,8 @@ // assert.ok(validator.extractTld("9"), "9 (alphanum) should validate") // TODO: this test fails | ||
it ("passes Apache's DomainValidatorTest#testValidator297", function() { | ||
it ("passes Apache's DomainValidatorTest#testValidator297", () => { | ||
assert.ok(validator.isValid("xn--d1abbgf6aiiy.xn--p1ai"), "xn--d1abbgf6aiiy.xn--p1ai should validate") | ||
}) | ||
it ("passes Apache's DomainValidatorTest#testValidator306", function() { | ||
let longString = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789A" | ||
it ("passes Apache's DomainValidatorTest#testValidator306", () => { | ||
const longString = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789A" | ||
expect(longString.length).to.be.equal(63) // 26 * 2 + 11 | ||
@@ -128,3 +128,3 @@ | ||
let longDomain = | ||
const longDomain = | ||
longString | ||
@@ -131,0 +131,0 @@ + "." + longString |
"use strict" | ||
import {expect, assert} from "chai" | ||
import {EmailValidator} from "../src/EmailValidator.js" | ||
import {EmailValidator} from "../src/EmailValidator" | ||
describe("EmailValidator", function() { | ||
let validator = new EmailValidator() | ||
describe("EmailValidator", () => { | ||
const validator = new EmailValidator() | ||
it ("passes Apache's EmailValidatorTest#testEmail", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmail", () => { | ||
assert.ok(validator.isValid("jsmith@apache.org")) | ||
}) | ||
it ("passes Apache's EmailValidatorTest#testEmailWithNumericAddress", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailWithNumericAddress", () => { | ||
//assert.ok(validator.isValid("someone@[216.109.118.76]")) // TODO: this test fails | ||
@@ -18,3 +18,3 @@ assert.ok(validator.isValid("someone@yahoo.com")) | ||
it ("passes Apache's EmailValidatorTest#testEmailExtension", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailExtension", () => { | ||
assert.ok(validator.isValid("jsmith@apache.org")) | ||
@@ -37,3 +37,3 @@ | ||
it ("passes Apache's EmailValidatorTest#testEmailWithDash", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailWithDash", () => { | ||
assert.ok(validator.isValid("andy.noble@data-workshop.com")) | ||
@@ -48,7 +48,7 @@ | ||
it ("passes Apache's EmailValidatorTest#testEmailWithDotEnd", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailWithDotEnd", () => { | ||
assert.notOk(validator.isValid("andy.noble@data-workshop.com.")) | ||
}) | ||
it ("passes Apache's EmailValidatorTest#testEmailWithBogusCharacter", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailWithBogusCharacter", () => { | ||
// assert.notOk(validator.isValid("andy.noble@\u008fdata-workshop.com")) // TODO: this test fails | ||
@@ -68,3 +68,3 @@ | ||
it ("passes Apache's EmailValidatorTest#testVALIDATOR_315", function() { | ||
it ("passes Apache's EmailValidatorTest#testVALIDATOR_315", () => { | ||
assert.notOk(validator.isValid("me@at&t.net")) | ||
@@ -74,3 +74,3 @@ assert.ok(validator.isValid("me@att.net")) | ||
it ("passes Apache's EmailValidatorTest#testVALIDATOR_278", function() { | ||
it ("passes Apache's EmailValidatorTest#testVALIDATOR_278", () => { | ||
assert.notOk(validator.isValid("someone@-test.com")) | ||
@@ -80,3 +80,3 @@ assert.notOk(validator.isValid("someone@test-.com")) | ||
it ("passes Apache's EmailValidatorTest#testValidator235", function() { | ||
it ("passes Apache's EmailValidatorTest#testValidator235", () => { | ||
assert.ok(validator.isValid("someone@xn--d1abbgf6aiiy.xn--p1ai"), "xn--d1abbgf6aiiy.xn--p1ai should validate") | ||
@@ -88,3 +88,3 @@ assert.ok(validator.isValid("someone@президент.рф"), "президент.рф should validate") | ||
it ("passes Apache's EmailValidatorTest#testEmailWithCommas", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailWithCommas", () => { | ||
assert.notOk(validator.isValid("joeblow@apa,che.org")) | ||
@@ -97,3 +97,3 @@ | ||
it ("passes Apache's EmailValidatorTest#testEmailWithSpaces", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailWithSpaces", () => { | ||
assert.notOk(validator.isValid("joeblow @apache.org")) | ||
@@ -114,3 +114,3 @@ | ||
/* | ||
it ("passes Apache's EmailValidatorTest#testEmailWithSpaces", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailWithSpaces", () => { | ||
for (let c = 0; c < 32; ++c) { | ||
@@ -125,7 +125,7 @@ assert.notOk(validator.isValid("foo" + String.fromCharCode(c) + "bar@domain.com"), "Test control char " + c) | ||
/* | ||
it ("passes Apache's EmailValidatorTest#testEmailLocalhost", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailLocalhost", () => { | ||
}) | ||
*/ | ||
it ("passes Apache's EmailValidatorTest#testEmailWithSlashes", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailWithSlashes", () => { | ||
assert.ok( | ||
@@ -145,3 +145,3 @@ validator.isValid("joe!/blow@apache.org"), | ||
it ("passes Apache's EmailValidatorTest#testEmailUserName", function() { | ||
it ("passes Apache's EmailValidatorTest#testEmailUserName", () => { | ||
assert.ok(validator.isValid("joe1blow@apache.org")); | ||
@@ -263,3 +263,3 @@ | ||
it ("passes Apache's EmailValidatorTest#testValidator293", function() { | ||
it ("passes Apache's EmailValidatorTest#testValidator293", () => { | ||
assert.ok(validator.isValid("abc-@abc.com")) | ||
@@ -272,3 +272,3 @@ assert.ok(validator.isValid("abc_@abc.com")) | ||
it ("passes Apache's EmailValidatorTest#testValidator365", function() { | ||
it ("passes Apache's EmailValidatorTest#testValidator365", () => { | ||
assert.notOk(validator.isValid( | ||
@@ -300,5 +300,5 @@ "Loremipsumdolorsitametconsecteturadipiscingelit.Nullavitaeligulamattisrhoncusnuncegestasmattisleo."+ | ||
it ("passes Apache's EmailValidatorTest#testValidator374", function() { | ||
it ("passes Apache's EmailValidatorTest#testValidator374", () => { | ||
assert.ok(validator.isValid("abc@school.school")) | ||
}) | ||
}) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
0
1273849