Skip to content

Commit

Permalink
Create production update
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed Aug 23, 2023
1 parent 04ba784 commit 98aefe1
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 84 deletions.
7 changes: 2 additions & 5 deletions dist/src/cnpjValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ function cnpjIsValid(cnpj, errorMsg) {
}
}
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
try {
if (!cnpj) {
Expand Down
7 changes: 2 additions & 5 deletions dist/src/cpfValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ function cpfIsValid(cpf, errorMsg) {
}
}
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
try {
if (!cpf) {
Expand Down
18 changes: 8 additions & 10 deletions dist/src/getOnlyEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ function getOnlyEmail(text, multiple, cleanDomain, repeatEmail) {
domainsToClean_1 = [];
}
var cleanedEmails = matches.map(function (email) {
var e_1, _a;
var e_1, _a, e_2, _b;
try {
for (var domainsToClean_2 = __values(domainsToClean_1), domainsToClean_2_1 = domainsToClean_2.next(); !domainsToClean_2_1.done; domainsToClean_2_1 = domainsToClean_2.next()) {
var domain = domainsToClean_2_1.value;
var index = email.lastIndexOf(domain);
if (index !== -1) {
return email.substring(0, index + domain.length);
email = email.substring(0, index + domain.length);
break;
}
}
}
Expand All @@ -74,33 +75,30 @@ function getOnlyEmail(text, multiple, cleanDomain, repeatEmail) {
}
finally { if (e_1) throw e_1.error; }
}
return email;
});
var cleanedEmails2 = cleanedEmails.map(function (email) {
var e_2, _a;
try {
for (var domainsToClean_3 = __values(domainsToClean_1), domainsToClean_3_1 = domainsToClean_3.next(); !domainsToClean_3_1.done; domainsToClean_3_1 = domainsToClean_3.next()) {
var domain = domainsToClean_3_1.value;
var index = email.indexOf(domain);
if (index !== -1) {
return email.substring(0, index + domain.length);
email = email.substring(0, index + domain.length);
break;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (domainsToClean_3_1 && !domainsToClean_3_1.done && (_a = domainsToClean_3.return)) _a.call(domainsToClean_3);
if (domainsToClean_3_1 && !domainsToClean_3_1.done && (_b = domainsToClean_3.return)) _b.call(domainsToClean_3);
}
finally { if (e_2) throw e_2.error; }
}
return email;
});
if (!repeatEmail) {
var uniqueEmails = __spreadArray([], __read(new Set(cleanedEmails2)), false);
var uniqueEmails = __spreadArray([], __read(new Set(cleanedEmails)), false);
return multiple ? uniqueEmails : uniqueEmails[0];
}
return multiple ? cleanedEmails2 : cleanedEmails2[0];
return multiple ? cleanedEmails : cleanedEmails[0];
}
if (!repeatEmail) {
var uniqueEmails = __spreadArray([], __read(new Set(matches)), false);
Expand Down
47 changes: 29 additions & 18 deletions dist/src/passwordStrengthTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@ function passwordStrengthTester(password) {
if (typeof password !== 'string')
throw new TypeError('The input should be a string.');
var passwordLength = password.length;
var strengthType;
if (passwordLength < 6 && /^\d+$/.test(password)) {
strengthType = 'veryWeak';
}
else if (passwordLength < 8 && /^\d+$/.test(password)) {
strengthType = 'weak';
}
else if (passwordLength < 8 && /\d/.test(password) && /[a-zA-Z]/.test(password)) {
strengthType = 'regular';
}
else if (/[A-Z]/.test(password)
&& /[!@#$%^&*(),.?":{}|<>]/.test(password)
&& /\d/.test(password)
&& /[a-zA-Z]/.test(password)) {
strengthType = 'veryStrong';
}
else {
strengthType = 'strong';
var strengthType = 'unknow';
switch (true) {
case passwordLength <= 5 && /^\d+$/.test(password):
strengthType = 'veryWeak';
break;
case (passwordLength <= 5 && /^[a-zA-Z0-9]+$/.test(password)) || (passwordLength >= 6 && /^[a-zA-Z0-9]+$/.test(password) && passwordLength <= 7) || (passwordLength < 10 && /(.)\1{3,}/.test(password)) || (passwordLength >= 5 && passwordLength <= 8 && /^\d+$/.test(password)):
strengthType = 'weak';
break;
case /(.)\1{5,}/.test(password) && passwordLength > 10:
strengthType = 'regular';
break;
case (passwordLength > 16) || (password.length >= 8 &&
/[A-Z]/.test(password) &&
/[a-z]/.test(password) &&
/[0-9]/.test(password) &&
/[\W_]/.test(password)):
strengthType = 'veryStrong';
break;
case (passwordLength >= 13 && passwordLength <= 16) || (password.length >= 8 &&
/[A-Z]/.test(password) &&
/[a-z]/.test(password) &&
/[0-9]/.test(password)):
strengthType = 'strong';
break;
case (passwordLength >= 9 && passwordLength <= 12) || (password.length >= 6 && password.length <= 8 && /[0-9]/.test(password) && /[a-zA-Z]/.test(password)):
strengthType = 'regular';
break;
default:
break;
}
return strengthType;
}
Expand Down
7 changes: 2 additions & 5 deletions dist/src/validateBRPhoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ function validateBRPhoneNumber(phoneNumber, errorMsg) {
}
}
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
if (!phoneNumber) {
return {
Expand Down
7 changes: 2 additions & 5 deletions dist/src/validateEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ function validateEmail(email, maxLength, country, errorMsg, validDomains) {
}
}
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
if (!email) {
return {
Expand Down
7 changes: 2 additions & 5 deletions dist/src/validateName.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ function validateName(name, minLength, maxLength, errorMsg) {
}
}
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
var minNameLength = minLength || 1;
var maxNameLength = maxLength || 20;
Expand Down
7 changes: 2 additions & 5 deletions dist/src/validatePassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ function validatePassword(password, minLength, maxLength, options, errorMsg) {
}
}
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
var minLenthPassword = minLength || 1;
var maxLenthPassword = maxLength || Infinity;
Expand Down
7 changes: 2 additions & 5 deletions dist/src/validatePhoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ function validatePhoneNumber(phoneNumber, errorMsg) {
}
}
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
if (!phoneNumber) {
return {
Expand Down
7 changes: 2 additions & 5 deletions dist/src/validateSurname.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ function validateSurname(surname, minLength, maxLength, errorMsg) {
}
}
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
var minNameLength = minLength || 1;
var maxNameLength = maxLength || 25;
Expand Down
7 changes: 2 additions & 5 deletions dist/src/validateTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ function validateTextarea(textarea, isRequired, maxLength, errorMsg) {
}
}
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
var maxTextAreaLength = maxLength || 50;
if (maxTextAreaLength < 1 || typeof maxTextAreaLength !== 'number') {
Expand Down
7 changes: 2 additions & 5 deletions dist/src/validateUSPhoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ function validateUSPhoneNumber(phoneNumber, errorMsg) {
}
var usPhoneNumberRegex = /^(1\s?)?(\(\d{3}\)|\d{3})(\s?|-)\d{3}(\s?|-)\d{4}$/;
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
if (!phoneNumber) {
return {
Expand Down
7 changes: 2 additions & 5 deletions dist/src/validateUsername.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ function validateUsername(username, minLength, maxLength, errorMsg) {
}
}
function getErrorMessage(index) {
if (errorMsg && index >= 0 && index < errorMsg.length) {
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
return defaultErrorMsg[index];
var errorMessage = errorMsg[index];
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
if (!username) {
return {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "multiform-validator",
"version": "1.0.24",
"version": "1.0.25",
"description": "Javascript library made to validate, several form fields, such as: email, phone, password, cpf etc.",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
Expand Down

0 comments on commit 98aefe1

Please sign in to comment.