Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miaowing/koa-validator-middleware
https://github.com/miaowing/koa-validator-middleware
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/miaowing/koa-validator-middleware
- Owner: miaowing
- Created: 2017-06-06T17:45:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-22T04:31:06.000Z (almost 7 years ago)
- Last Synced: 2024-10-01T02:21:56.979Z (about 2 months ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# koa-validator-middleware
A collection of validation middlewares for koa.
## Usage
```javascript
import {NotEmpty, Size} from 'koa-validator-middleware';
import KoaRouter from 'koa-router';const router = new KoaRouter();
router.post('/users',
NotEmpty('request.body.username'),
Size('request.body.password', 6, 20),
function (ctx) {
if(!ctx.validation.pass) {
console.log(ctx.validation.errors);
console.log(ctx.validation.error.username);
console.log(ctx.validation.error.password);
}
}
);
```## API
### NotEmpty(path)
### NotInteger(path)
### NotNumber(path)
### NotNull(path)
### Min(path, min)
### Max(path, max)
### Size(path, min, max)
### Pattern(path, regExp)
### Default(path, defaultValue)