JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q33985F
  • License MIT

zenweb validation module

Package Exports

  • @zenweb/validation

Readme

zenweb-validation

zenweb validation module

Quick start

$ npm i @zenweb/validation

app.js

'use strict';

const { default: validation } = require('@zenweb/validation');
const app = module.exports = require('zenweb').create();

app.setup(validation());
app.start();

app/controller/simple.js

const app = require('../../app');

app.router.post('/simple', ctx => {
  ctx.validate('simple'); // default data: ctx.request.body
  ctx.body = 'ok';
});

app/validation/simple.schema.json

{
  "type": "object",
  "properties": {
    "foo": { "type": "number", "minimum": 0 },
    "bar": { "type": "string", "maxLength": 10, "minLength": 2 }
  },
  "required": ["foo", "bar"],
  "additionalProperties": false
}