6.4.0 • Published 1 year ago

c-validator v6.4.0

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
6.4.0

1 year ago

6.3.6

1 year ago

6.3.5

1 year ago

6.3.8

1 year ago

6.3.7

1 year ago

6.3.9

1 year ago

5.3.5

1 year ago

5.3.4

1 year ago

5.3.3

2 years ago

5.3.2

2 years ago

5.2.2

3 years ago

5.2.1

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago

5.0.0

4 years ago

4.0.1

4 years ago

4.0.0

5 years ago

3.0.0

6 years ago

2.0.11

7 years ago

2.0.10

7 years ago

2.0.9

7 years ago

2.0.8

7 years ago

2.0.7

7 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.3

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago