Skip to content
This repository has been archived by the owner on Feb 17, 2019. It is now read-only.
/ alp-params Public archive

Validate params from query, router or post body in koa 2 or ibex

License

Notifications You must be signed in to change notification settings

alpjs/alp-params

Repository files navigation

alp-params

Validate params from query, router or post body in koa 2 or ibex

Install

npm install --save alp-params

API

https://.github.io/alp-params/docs

Validator

.isValid()
.hasErrors()
.getErrors()
.string(name, position)

ValueStringValidator

.notEmpty()

Usage

import Koa from 'koa';
import params from 'alp-params';

const app = new Koa();
params(app);
    index(ctx) {
        const name = ctx.params.string('name').notEmpty().value;
        ctx.body = this.t('Hello %s!', ctx.params.isValid() ? name : 'World');
    },

    something(ctx) {
        // throw a 404 if the param was not found
        const name = ctx.validParams.string('name').notEmpty().value;
        ctx.body = this.t('Hello %s!', name);
    },

About

Validate params from query, router or post body in koa 2 or ibex

Resources

License

Stars

Watchers

Forks

Packages