Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Object.keys(validations).forEach(validation => {
const validationValue = validations[validation];
if (
!!validationValue ||
((!isBoolean(validationValue) &&
Number.isInteger(Math.floor(validationValue))) ||
validationValue === 0)
) {
switch (validation) {
case 'required':
schema = schema.required(errorsTrads.required);
break;
case 'max':
schema = schema.max(validationValue, errorsTrads.max);
break;
case 'maxLength':
schema = schema.max(validationValue, errorsTrads.maxLength);
break;
case 'min':
schema = schema.min(validationValue, errorsTrads.min);
break;
case 'minLength':
schema = schema.min(validationValue, errorsTrads.minLength);
break;
case 'regex':
schema = schema.matches(validationValue, errorsTrads.regex);
break;
case 'lowercase':
if (['text', 'textarea', 'email', 'string'].includes(type)) {
schema = schema.strict().lowercase();
Object.keys(validations).forEach(validation => {
const validationValue = validations[validation];
if (
!!validationValue ||
((!isBoolean(validationValue) &&
Number.isInteger(Math.floor(validationValue))) ||
validationValue === 0)
) {
switch (validation) {
case 'required':
schema = schema.required(errorsTrads.required);
break;
case 'max': {
if (type === 'biginteger') {
schema = schema.isInferior(errorsTrads.max, validationValue);
} else {
schema = schema.max(validationValue, errorsTrads.max);
}
break;
}
case 'maxLength':
schema = schema.max(validationValue, errorsTrads.maxLength);
break;
case 'min': {
if (type === 'biginteger') {
schema = schema.isSuperior(errorsTrads.min, validationValue);
} else {
schema = schema.min(validationValue, errorsTrads.min);
}
break;
}