5.3.3 • Published 1 year ago

c-validator v5.3.3

Weekly downloads
14
License
ISC
Repository
github
Last release
1 year ago

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

ValidatorDescription
requiredcheck if value is not empty or none
incheck if value is in the options in:pending,paid
phonecheck if value is a phone number
emailcheck if value is an email
datetimecheck if value is a valid datetime datetime:YYYY-MM-DD
integercheck if value is a integer
floatcheck if value is a float
booleancheck 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