email-syntax
Advanced tools
Comparing version 2.0.0 to 2.0.1
export declare class EmailSyntax { | ||
private static _localPartRegex; | ||
private static _domainPartRegex; | ||
private static localPartRegex; | ||
private static domainPartRegex; | ||
/** | ||
* Validates given email address | ||
* @param {string} address - Email address to validate | ||
* @return {boolean} | ||
*/ | ||
@@ -12,21 +13,29 @@ static validate(address: string): boolean; | ||
* @param {string} address - email address | ||
* @return {Object | boolean} | ||
*/ | ||
private static _split(address); | ||
private static split(address); | ||
/** | ||
* Check if quoted and extract local part | ||
* Checks if quoted and extracts local part | ||
* @param {string} localPart - local part of address | ||
* @return {string} | ||
*/ | ||
private static extractFromQuotes(localPart); | ||
/** | ||
* Method for validation of domain name syntaxis | ||
* Validates domain name syntaxis | ||
* @param {string} domainName - domain name | ||
* @return {boolean} | ||
*/ | ||
private static _validateDomainName(domainName); | ||
private static validateDomainName(domainName); | ||
/** | ||
* Method for validation of local-part of address | ||
* Validates local-part of address | ||
* @param {string} localPart - local part of address | ||
* @return {boolean} | ||
*/ | ||
private static _validateLocalPartSyntax(localPart); | ||
private static validateLocalPart(localPart); | ||
/** | ||
* Method to find out is domain name is a valid ip address like 1.2.3.4 | ||
* Checks if domain name is a valid ip address like 1.2.3.4 | ||
* @param {string} domainName - domain name | ||
* @return {boolean} | ||
*/ | ||
private static _isValidIpAddress(domainName); | ||
private static isValidIpAddress(domainName); | ||
} |
@@ -9,5 +9,6 @@ "use strict"; | ||
* @param {string} address - Email address to validate | ||
* @return {boolean} | ||
*/ | ||
EmailSyntax.validate = function (address) { | ||
var splittedAddress = this._split(address); | ||
var splittedAddress = this.split(address); | ||
if (!splittedAddress) | ||
@@ -19,7 +20,7 @@ return false; | ||
return false; | ||
if (!this._validateLocalPartSyntax(splittedAddress['localPart'])) | ||
if (!this.validateLocalPart(splittedAddress['localPart'])) | ||
return false; | ||
/* Domain Name Checks */ | ||
if (!this._isValidIpAddress(splittedAddress['domainName'])) { | ||
if (!this._validateDomainName(splittedAddress['domainName'])) | ||
if (!this.isValidIpAddress(splittedAddress['domainName'])) { | ||
if (!this.validateDomainName(splittedAddress['domainName'])) | ||
return false; | ||
@@ -32,4 +33,5 @@ } | ||
* @param {string} address - email address | ||
* @return {Object | boolean} | ||
*/ | ||
EmailSyntax._split = function (address) { | ||
EmailSyntax.split = function (address) { | ||
if (address && address.length > 0) { | ||
@@ -43,4 +45,5 @@ var splittedAddress = address.split('@'); | ||
/** | ||
* Check if quoted and extract local part | ||
* Checks if quoted and extracts local part | ||
* @param {string} localPart - local part of address | ||
* @return {string} | ||
*/ | ||
@@ -61,5 +64,7 @@ EmailSyntax.extractFromQuotes = function (localPart) { | ||
/** | ||
* Method for validation of domain name syntaxis | ||
* Validates domain name syntaxis | ||
* @param {string} domainName - domain name | ||
* @return {boolean} | ||
*/ | ||
EmailSyntax._validateDomainName = function (domainName) { | ||
EmailSyntax.validateDomainName = function (domainName) { | ||
var parts = domainName.split('.'); | ||
@@ -71,3 +76,3 @@ if (parts.length === 0) | ||
return false; | ||
var p = parts[i].match(this._domainPartRegex); | ||
var p = parts[i].match(this.domainPartRegex); | ||
if (p === null || p[0] !== parts[i]) | ||
@@ -81,6 +86,8 @@ return false; | ||
/** | ||
* Method for validation of local-part of address | ||
* Validates local-part of address | ||
* @param {string} localPart - local part of address | ||
* @return {boolean} | ||
*/ | ||
EmailSyntax._validateLocalPartSyntax = function (localPart) { | ||
var regexResult = localPart.match(this._localPartRegex); | ||
EmailSyntax.validateLocalPart = function (localPart) { | ||
var regexResult = localPart.match(this.localPartRegex); | ||
if (regexResult === null || localPart !== regexResult[0]) | ||
@@ -91,5 +98,7 @@ return false; | ||
/** | ||
* Method to find out is domain name is a valid ip address like 1.2.3.4 | ||
* Checks if domain name is a valid ip address like 1.2.3.4 | ||
* @param {string} domainName - domain name | ||
* @return {boolean} | ||
*/ | ||
EmailSyntax._isValidIpAddress = function (domainName) { | ||
EmailSyntax.isValidIpAddress = function (domainName) { | ||
var ip = domainName.split('.'); | ||
@@ -105,4 +114,4 @@ if (ip.length !== 4) | ||
}; | ||
EmailSyntax._localPartRegex = /^[A-Za-z0-9=?\/^_`{}|~!#$%&'*+-](\.?[A-Za-z0-9=?\/^_`{}|~!#$%&'*+-])*/g; | ||
EmailSyntax._domainPartRegex = /^[A-Za-z0-9](\-?[A-Za-z0-9])*/i; | ||
EmailSyntax.localPartRegex = /^[A-Za-z0-9=?\/^_`{}|~!#$%&'*+-](\.?[A-Za-z0-9=?\/^_`{}|~!#$%&'*+-])*/g; | ||
EmailSyntax.domainPartRegex = /^[A-Za-z0-9](\-?[A-Za-z0-9])*/i; | ||
return EmailSyntax; | ||
@@ -109,0 +118,0 @@ }()); |
{ | ||
"name": "email-syntax", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Email addresses syntax validations library", | ||
@@ -5,0 +5,0 @@ "main": "./lib/email-syntax.js", |
@@ -33,2 +33,12 @@ # email-syntax | ||
On server environment you can use additional methods: | ||
* split(address) - Splits email address to local part and domain name | ||
* extractFromQuotes(localPart) - Checks if quoted and extracts local part | ||
* validateDomainName(domainName) - Validates domain name syntaxis | ||
* validateLocalPart(localPart) - Validates local-part of address | ||
* isValidIpAddress(domainName) - Checks if domain name is a valid ip address like 1.2.3.4 | ||
### Angular 2/4 | ||
@@ -35,0 +45,0 @@ |
Sorry, the diff of this file is not supported yet
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
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
17030
225
58
0