https://github.com/stackkit/validate
https://github.com/stackkit/validate
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/stackkit/validate
- Owner: stackkit
- Created: 2020-08-02T16:21:24.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-15T14:51:32.000Z (almost 6 years ago)
- Last Synced: 2025-10-29T16:32:39.092Z (8 months ago)
- Language: JavaScript
- Size: 162 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Validate
> A simple validation util for react or vue. It works in nodejs to.
```js example
const { validate, email, length, required } = require('validate')
const rules = {
fields: {
email: {
validator: value => {
return length(value, { max: 75 }) && email(value)
},
message: ({ value }) => {
return `${value} is not valid email address or the length is to high.`
},
},
password: {
validator: value => {
return length(value, { min: 4, max: 18 })
},
message: ({ value, field }) => {
return `The length of your password is tho short it must be between 4 and 18 charters long.`
},
},
subscription: {
validator: value => {
return required(value)
},
message: `Please choose a subscription type`,
},
},
}
const { valid } = validate(fields, {
rules,
})
```
## Good the know.
No sanitizing has been done on the return value in the message function. It is your job
to use a library to achieve this.
[dompurify](https://www.npmjs.com/package/dompurify)
### Nodejs
While working on this. I found this package [express-validator](https://github.com/express-validator/express-validator) it looks like a good option for validation inside nodejs express projects.