1.0.6 • Published 3 years ago
@payiz/validator v1.0.6
@payiz/validator
Validation module
How to use
const Validator = require('@payiz/validator');
const Schema = {
param: {
type: 'string',
required: true
}
};
const error = Validator.validate({ param: 'Hello world' }, Schema);
if (error) {
console.log(error);
}
Response
Validator.validate return undefined when everything is correct and an array of object when there is at least one error. The object is formatted as below:
const error = {
code: '',
field: '',
value: ''
}
Schema format
const functionSchema = {
parameter: {
type: 'string|number|...',
required: true,
...
}
};
Validation types
Rules
Boolean
- Required
- Truthy
- Falsy
Number
- Required
- min
- max
- negative
- positive
- integer
- float
String
- required
- alpha
- numeric
- alphanumeric
- length
- min
- max
- lowercase
- uppercase
- capitalize
- email WIP
- password WIP
- phone WIP
- domain WIP
- url WIP
- only TODO
Object
- required
- keys
- contains WIP