@hakcolt/validator
v1.2.0
Published
Validate external properties to avoid errors
Downloads
5
Maintainers
Readme
Validator
The validator is a dynamic tool and with it you will be able to validate any type of object and/or parameters that your use case requires as input, in addition to also being able to validate email, passwords and so on.
How To Use
/*...*/
const missingAttributes = validation.validateObject(this, ["firstName:string", "lastName:string", "email:string", "gender:string", "password:string"])
if (missingAttributes.length) {
result.setError(resources.getWithParams(plurals.MISSING_ATRIBUTES, validation.formatMissingAttributes(missingAttributes)), 400)
return false
}
if (!validation.validatePassword(this.password)) {
result.setError(resources.get(strings.INVALID_PASSWORD), 400)
return false
}
const genders = Object.values(Gender)
if (!genders.includes(this.gender as Gender)) {
result.setError(resources.get(strings.INVALID_GENDER), 400)
return false
}
if (!validation.validateEmail(this.email)) {
result.setError(resources.get(strings.INVALID_EMAIL), 400)
return false
}
return true
/*...*/