0.0.6 • Published 7 years ago

koa-validator-middleware v0.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

koa-validator-middleware

A collection of validation middlewares for koa.

Usage

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)

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago