Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stanleymasinde/mevn-validator
simple validator for express js
https://github.com/stanleymasinde/mevn-validator
express express-middleware
Last synced: 1 day ago
JSON representation
simple validator for express js
- Host: GitHub
- URL: https://github.com/stanleymasinde/mevn-validator
- Owner: StanleyMasinde
- License: mit
- Created: 2020-02-11T22:11:57.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T20:05:52.000Z (almost 2 years ago)
- Last Synced: 2024-12-17T17:42:11.826Z (8 days ago)
- Topics: express, express-middleware
- Language: TypeScript
- Homepage:
- Size: 252 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![npm version](https://badge.fury.io/js/mevn-validator.svg)](https://badge.fury.io/js/mevn-validator)
## Validator For Express* Install the package `npm i mevn-validator`
* The Validator must be instatiated with the `new KeyWord`
```javascript
const Validator = require('mevn-validator')// Create a validator instance
let validate = new Validator(fields: Object, rules: Object)
validate.validate()
.then(valid => {
// do something when the validation passes
})
.catch(messages => {
// You would probably need to send this to the user
// the messages contains the error messages
})// OR like a cool kid 😎
new Validator(fields: Object, rules: Object).then(....).catch(...).finally(...)
```
* Rules are separted by **|** e.g `field: required|email`. The field under validation must be available and be a valid E-mail Address### Available rules
1. #### Required
* Ensures that the field under validation is available `field: required`
2. #### String
* The field under validation must be a valid String `field: string`
3. #### Email
* The field under validation must be a valid String `field: email`
4. #### Min:length
* The field under validation must be more than the given length `field: min:10`
5. #### Max:length
* The field under validation must be less than the given length `field: max:20`__More rules and Docs coming soon. Contributions are welcome__