Skip to content

Commit

Permalink
chore: publishing 1.0.34 version
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed Mar 17, 2024
1 parent bc24ede commit fdabfb6
Show file tree
Hide file tree
Showing 35 changed files with 154 additions and 119 deletions.
1 change: 1 addition & 0 deletions packages/typescript/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
node_modules/
tests/**/*
types/
9 changes: 7 additions & 2 deletions packages/typescript/dist/src/cnpjValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ function calculateSecondVerifier(cnpjBase, firstVerifier) {
var remainder = sum % 11;
return remainder < 2 ? 0 : 11 - remainder;
}
var defaultErrorMsg = ['CNPJ invalid', 'CNPJ must have 14 numerical digits', 'CNPJ is not valid', 'Unknown error'];
var defaultErrorMsg = [
'CNPJ invalid',
'CNPJ must have 14 numerical digits',
'CNPJ is not valid',
'Unknown error',
];
function cnpjIsValid(cnpj, errorMsg) {
if (errorMsg === void 0) { errorMsg = defaultErrorMsg; }
if (typeof cnpj !== 'string')
Expand All @@ -34,7 +39,7 @@ function cnpjIsValid(cnpj, errorMsg) {
}
}
function getErrorMessage(index) {
var errorMessage = errorMsg[index];
var errorMessage = errorMsg ? errorMsg[index] : null;
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
try {
Expand Down
10 changes: 5 additions & 5 deletions packages/typescript/dist/src/cpfValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function cpfIsValid(cpf, errorMsg) {
}
}
function getErrorMessage(index) {
var errorMessage = errorMsg[index];
var errorMessage = errorMsg ? errorMsg[index] : null;
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
try {
Expand Down Expand Up @@ -58,15 +58,15 @@ function cpfIsValid(cpf, errorMsg) {
somaTotal2 += multiplicador2;
var valorDeVerificacao = somaTotal - Number(cpfLimpo[9]);
var valorDeVerificacao2 = somaTotal2 - Number(cpfLimpo[10]);
primeiroVerificador = (11 - (valorDeVerificacao % 11));
segundoVerificador = (11 - (valorDeVerificacao2 % 11));
primeiroVerificador = 11 - (valorDeVerificacao % 11);
segundoVerificador = 11 - (valorDeVerificacao2 % 11);
}
if (primeiroVerificador > 9)
primeiroVerificador = 0;
if (segundoVerificador > 9)
segundoVerificador = 0;
if (primeiroVerificador === Number(cpfLimpo[9])
&& segundoVerificador === Number(cpfLimpo[10])) {
if (primeiroVerificador === Number(cpfLimpo[9]) &&
segundoVerificador === Number(cpfLimpo[10])) {
return {
isValid: true,
errorMsg: null,
Expand Down
13 changes: 3 additions & 10 deletions packages/typescript/dist/src/getOnlyEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,9 @@ function getOnlyEmail(text, multiple, cleanDomain, repeatEmail) {
if (!matches)
return 'No email found';
if (cleanDomain) {
var domainsToClean_1;
if (Array.isArray(cleanDomain)) {
domainsToClean_1 = cleanDomain;
}
else if (cleanDomain === true) {
domainsToClean_1 = CleanAfterDefaultDomain;
}
else {
domainsToClean_1 = [];
}
var domainsToClean_1 = Array.isArray(cleanDomain)
? cleanDomain
: CleanAfterDefaultDomain;
var cleanedEmails = matches.map(function (email) {
var e_1, _a, e_2, _b;
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/dist/src/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function isEmail(email) {
var regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (Number(email[0]))
return false;
if (!(regex.test(email)))
if (!regex.test(email))
return false;
var depoisDoArroba = email.indexOf('@') + 1;
var depoisDoUltimoPonto = email.lastIndexOf('.');
Expand Down
4 changes: 1 addition & 3 deletions packages/typescript/dist/src/isMD5.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ function isMD5(value) {
if (allZeroRegex.test(trimmedValue)) {
return false;
}
var weakHashes = [
'd41d8cd98f00b204e9800998ecf8427e',
];
var weakHashes = ['d41d8cd98f00b204e9800998ecf8427e'];
if (weakHashes.includes(trimmedValue)) {
return false;
}
Expand Down
26 changes: 13 additions & 13 deletions packages/typescript/dist/src/isPostalCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ function isPostalCode(postalCode) {
var brazilPostalCodeRegex = /^\d{5}-\d{3}$/;
var italyPostalCodeRegex = /^\d{5}$/;
var usZipCodeOnlyRegex = /^\d{5}$/;
return (usZipCodeRegex.test(postalCode)
|| canadaPostalCodeRegex.test(postalCode)
|| ukPostalCodeRegex.test(postalCode)
|| francePostalCodeRegex.test(postalCode)
|| netherlandsPostalCodeRegex.test(postalCode)
|| japanPostalCodeRegex.test(postalCode)
|| spainPostalCodeRegex.test(postalCode)
|| southAfricaPostalCodeRegex.test(postalCode)
|| germanyPostalCodeRegex.test(postalCode)
|| switzerlandPostalCodeRegex.test(postalCode)
|| brazilPostalCodeRegex.test(postalCode)
|| italyPostalCodeRegex.test(postalCode)
|| usZipCodeOnlyRegex.test(postalCode));
return (usZipCodeRegex.test(postalCode) ||
canadaPostalCodeRegex.test(postalCode) ||
ukPostalCodeRegex.test(postalCode) ||
francePostalCodeRegex.test(postalCode) ||
netherlandsPostalCodeRegex.test(postalCode) ||
japanPostalCodeRegex.test(postalCode) ||
spainPostalCodeRegex.test(postalCode) ||
southAfricaPostalCodeRegex.test(postalCode) ||
germanyPostalCodeRegex.test(postalCode) ||
switzerlandPostalCodeRegex.test(postalCode) ||
brazilPostalCodeRegex.test(postalCode) ||
italyPostalCodeRegex.test(postalCode) ||
usZipCodeOnlyRegex.test(postalCode));
}
exports.default = isPostalCode;
31 changes: 20 additions & 11 deletions packages/typescript/dist/src/passwordStrengthTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,35 @@ function passwordStrengthTester(password) {
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)):
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)):
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)):
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)):
case (passwordLength >= 9 && passwordLength <= 12) ||
(password.length >= 6 &&
password.length <= 8 &&
/[0-9]/.test(password) &&
/[a-zA-Z]/.test(password)):
strengthType = 'regular';
break;
default:
Expand Down
8 changes: 6 additions & 2 deletions packages/typescript/dist/src/validateBRPhoneNumber.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var defaultErrorMsg = ['Field phone number cannot be empty', 'Invalid phone number', 'Unknown error'];
var defaultErrorMsg = [
'Field phone number cannot be empty',
'Invalid phone number',
'Unknown error',
];
function validateBRPhoneNumber(phoneNumber, errorMsg) {
if (errorMsg === void 0) { errorMsg = defaultErrorMsg; }
if (typeof phoneNumber !== 'string')
Expand All @@ -15,7 +19,7 @@ function validateBRPhoneNumber(phoneNumber, errorMsg) {
}
}
function getErrorMessage(index) {
var errorMessage = errorMsg[index];
var errorMessage = errorMsg ? errorMsg[index] : null;
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
if (!phoneNumber) {
Expand Down
30 changes: 21 additions & 9 deletions packages/typescript/dist/src/validateEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ var defaultErrorMsg = [
'Email domain is not allowed.',
'Unknown error',
];
var validDomainsDefault = ['@gmail.com', '@outlook.com', '@yahoo.com', '@icloud.com', '@hotmail.com',
'@mail.ru', '@yandex.ru', '@gmx.com', '@zoho.com', '@protonmail.com', '@protonmail.ch'
var validDomainsDefault = [
'@gmail.com',
'@outlook.com',
'@yahoo.com',
'@icloud.com',
'@hotmail.com',
'@mail.ru',
'@yandex.ru',
'@gmx.com',
'@zoho.com',
'@protonmail.com',
'@protonmail.ch',
];
function validateEmail(email, maxLength, country, errorMsg, validDomains) {
if (country === void 0) { country = ''; }
Expand All @@ -22,13 +32,15 @@ function validateEmail(email, maxLength, country, errorMsg, validDomains) {
if (typeof email !== 'string')
throw new TypeError('The input should be a string.');
var regex = /(?:)/;
if (validDomains === true) {
regex = new RegExp("".concat(validDomainsDefault.join('|'), "$"), 'i');
}
else if (Array.isArray(validDomains) && validDomains.length > 0) {
var validDomainsCustom = validDomains.map(function (domain) { return domain.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); });
if (Array.isArray(validDomains) && validDomains.length > 0) {
var validDomainsCustom = validDomains.map(function (domain) {
return domain.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
});
regex = new RegExp("".concat(validDomainsCustom.join('|'), "$"), 'i');
}
else if (validDomains) {
regex = new RegExp("".concat(validDomainsDefault.join('|'), "$"), 'i');
}
if (errorMsg) {
if (!Array.isArray(errorMsg))
throw new Error('errorMsg must be an Array or null');
Expand All @@ -55,13 +67,13 @@ function validateEmail(email, maxLength, country, errorMsg, validDomains) {
if (maxEmailLength < 1 || typeof maxEmailLength !== 'number')
throw new Error('maxLength must be a number and cannot be less than 1');
try {
if (regex && !regex.test(email)) {
if (!regex.test(email)) {
return {
isValid: false,
errorMsg: getErrorMessage(4),
};
}
if (!((0, isEmail_1.default)(email))) {
if (!(0, isEmail_1.default)(email)) {
return {
isValid: false,
errorMsg: getErrorMessage(1),
Expand Down
10 changes: 7 additions & 3 deletions packages/typescript/dist/src/validateName.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Object.defineProperty(exports, "__esModule", { value: true });
var defaultErrorMsg = [
'Name cannot be empty',
'Name cannot contain numbers', 'Name cannot contain special characters',
'Name cannot contain numbers',
'Name cannot contain special characters',
'This name is not valid',
'Name too big, try again',
'Unknown error',
Expand All @@ -21,12 +22,15 @@ function validateName(name, minLength, maxLength, errorMsg) {
}
}
function getErrorMessage(index) {
var errorMessage = errorMsg[index];
var errorMessage = errorMsg ? errorMsg[index] : null;
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
var minNameLength = minLength || 1;
var maxNameLength = maxLength || 20;
if (maxNameLength < 1 || minNameLength < 1 || typeof minNameLength !== 'number' || typeof maxNameLength !== 'number') {
if (maxNameLength < 1 ||
minNameLength < 1 ||
typeof minNameLength !== 'number' ||
typeof maxNameLength !== 'number') {
throw new Error('maxLength or minLength must be a number and cannot be less than 1');
}
if (minNameLength > maxNameLength) {
Expand Down
54 changes: 25 additions & 29 deletions packages/typescript/dist/src/validatePassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ function validatePassword(password, minLength, maxLength, options, errorMsg) {
var minLenthPassword = minLength || 1;
var maxLenthPassword = maxLength || Infinity;
function getErrorMessage(index) {
var errorMessage = errorMsg[index];
var errorMessage = errorMsg ? errorMsg[index] : null;
if (errorMessage === 'This password is too long' || errorMessage === 'password too short') {
if (maxLenthPassword === Infinity) {
return "Password must be greater than ".concat(minLenthPassword, " characters");
}
else {
return "Password must be between ".concat(minLenthPassword, " and ").concat(maxLenthPassword, " characters");
}
return "Password must be between ".concat(minLenthPassword, " and ").concat(maxLenthPassword, " characters");
}
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
Expand All @@ -64,31 +62,29 @@ function validatePassword(password, minLength, maxLength, options, errorMsg) {
errorMsg: getErrorMessage(1),
};
}
if (options != null) {
if (options.requireUppercase && !/[A-Z]/.test(password)) {
return {
isValid: false,
errorMsg: getErrorMessage(2),
};
}
if (options.requireSpecialChar && !/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
return {
isValid: false,
errorMsg: getErrorMessage(3),
};
}
if (options.requireNumber && !/\d/.test(password)) {
return {
isValid: false,
errorMsg: getErrorMessage(4),
};
}
if (options.requireString && !/[a-zA-Z]/.test(password)) {
return {
isValid: false,
errorMsg: getErrorMessage(5),
};
}
if (options.requireUppercase && !/[A-Z]/.test(password)) {
return {
isValid: false,
errorMsg: getErrorMessage(2),
};
}
if (options.requireSpecialChar && !/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
return {
isValid: false,
errorMsg: getErrorMessage(3),
};
}
if (options.requireNumber && !/\d/.test(password)) {
return {
isValid: false,
errorMsg: getErrorMessage(4),
};
}
if (options.requireString && !/[a-zA-Z]/.test(password)) {
return {
isValid: false,
errorMsg: getErrorMessage(5),
};
}
return {
isValid: true,
Expand Down
8 changes: 6 additions & 2 deletions packages/typescript/dist/src/validatePhoneNumber.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var defaultErrorMsg = ['Phone number cannot be empty', 'Invalid phone number', 'Unknown error'];
var defaultErrorMsg = [
'Phone number cannot be empty',
'Invalid phone number',
'Unknown error',
];
function validatePhoneNumber(phoneNumber, errorMsg) {
if (errorMsg === void 0) { errorMsg = defaultErrorMsg; }
if (typeof phoneNumber !== 'string')
Expand All @@ -15,7 +19,7 @@ function validatePhoneNumber(phoneNumber, errorMsg) {
}
}
function getErrorMessage(index) {
var errorMessage = errorMsg[index];
var errorMessage = errorMsg ? errorMsg[index] : null;
return errorMessage != null ? errorMessage : defaultErrorMsg[index];
}
if (!phoneNumber) {
Expand Down
Loading

0 comments on commit fdabfb6

Please sign in to comment.