Skip to content

nexys-system/validation

Repository files navigation

Validation

Test Package Publish NPM package NPM package Bundleophobia Prettier

Simple, flexible and typesafe validation helpers

Get started

yarn add @nexys/validation

import Validation, {Type, Utils} from '@nexys/validation';

Examples

see tests

Koa example

import Router from 'koa-router';
import bodyParser from 'koa-body';
import Validation, { Utils as VU } from '@nexys/validation';

const router = new Router();

router.post(
  '/update',
  bodyParser(),
  Validation.isShapeMiddleware({
    uuid: { extraCheck: VU.checkUuid },
    name: {}
  }),
  async ctx => {
    // now that the body has been validated this can be safely typed/cast to the expected type.
    // Note that the type should match the validation shape
    const { uuid, name }: { uuid: Uuid; name: string } = ctx.request.body;
    ctx.body = await myFunc(uuid, name);
  }
);


export default router.routes();