@zenweb/validation
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

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
}

Package Sidebar

Install

npm i @zenweb/validation

Weekly Downloads

49

Version

3.0.1

License

MIT

Unpacked Size

4.81 kB

Total Files

6

Last publish

Collaborators

  • yefei777