alp-params
    TypeScript icon, indicating that this package has built-in type declarations

    3.2.2 • Public • Published

    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);
        },

    Keywords

    Install

    npm i alp-params

    DownloadsWeekly Downloads

    33

    Version

    3.2.2

    License

    ISC

    Unpacked Size

    136 kB

    Total Files

    49

    Last publish

    Collaborators

    • churpeau