Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/miaowing/koa-validator-middleware


https://github.com/miaowing/koa-validator-middleware

Last synced: about 1 month ago
JSON representation

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)