5.3.3 • Published 1 year ago
c-validator v5.3.3
c-validator-js
Example
import Validate from 'c-validator'
const schema = {
name: 'required',
age: 'required|integer',
contact: {
email: 'required|email'
}
}
const [value, errors] = Validate(schema, data)
...
Sample value
{
name: 'xxx',
age: 20,
contact: {
email: 'xxx'
}
}
Sample errors
[
{ path: 'name', message: '{name} is required' },
{ path: 'contact.email', message: '{name} not valid email' }
]
Validators
Validator | Description |
---|---|
required | check if value is not empty or none |
in | check if value is in the options in:pending,paid |
phone | check if value is a phone number |
check if value is an email | |
datetime | check if value is a valid datetime datetime:YYYY-MM-DD |
integer | check if value is a integer |
float | check if value is a float |
boolean | check if value is a boolean |
Advanced
const schema = {
posts: (path, value) => {
// custom
return [value, errors]
}
}
Tests
$ npm run test
5.3.3
1 year ago
5.3.2
1 year ago
5.2.2
2 years ago
5.2.1
3 years ago
5.1.1
3 years ago
5.1.0
3 years ago
5.0.0
3 years ago
4.0.1
3 years ago
4.0.0
4 years ago
3.0.0
5 years ago
2.0.11
6 years ago
2.0.10
6 years ago
2.0.9
6 years ago
2.0.8
6 years ago
2.0.7
6 years ago
2.0.6
7 years ago
2.0.5
7 years ago
2.0.4
7 years ago
2.0.3
7 years ago
2.0.2
7 years ago
2.0.1
7 years ago
2.0.0
7 years ago
1.0.3
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago