All Projects → eggjs → Egg Validate

eggjs / Egg Validate

Licence: mit
validate plugin for egg

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Egg Validate

Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (-16.07%)
Mutual labels:  egg, egg-plugin
Egg Security
Security plugin for egg, force performance too.
Stars: ✭ 204 (-8.93%)
Mutual labels:  egg, egg-plugin
Egg Authz
egg-authz is an authorization middleware for Egg.js based on Casbin
Stars: ✭ 50 (-77.68%)
Mutual labels:  egg, egg-plugin
Egg Valid
👮Validation plugin for eggjs
Stars: ✭ 10 (-95.54%)
Mutual labels:  egg, egg-plugin
Egg Oauth2 Server
🌟 OAuth2 server plugin for egg.js based on node-oauth2-server
Stars: ✭ 174 (-22.32%)
Mutual labels:  egg, egg-plugin
Egg View
Stars: ✭ 35 (-84.37%)
Mutual labels:  egg, egg-plugin
Egg Router Plus
The missing router feature for eggjs
Stars: ✭ 117 (-47.77%)
Mutual labels:  egg, egg-plugin
Egg Mongoose
Stars: ✭ 386 (+72.32%)
Mutual labels:  egg, egg-plugin
Egg Multipart
multipart plugin for egg
Stars: ✭ 145 (-35.27%)
Mutual labels:  egg, egg-plugin
Egg Schedule
Schedule plugin for egg
Stars: ✭ 76 (-66.07%)
Mutual labels:  egg, egg-plugin
Egg Sequelize
Sequelize for Egg.js
Stars: ✭ 540 (+141.07%)
Mutual labels:  egg, egg-plugin
Egg Socket.io
socket.io plugin for eggjs.
Stars: ✭ 209 (-6.7%)
Mutual labels:  egg, egg-plugin
Egg Restfulapi
🏅 基于Egg.js 2.0 & {mongoose,jwt}RESTful API 模板,用于快速集成开发RESTful前后端分离的服务端。
Stars: ✭ 524 (+133.93%)
Mutual labels:  egg, egg-plugin
Egg Cancan
cancancan like authorization plugin for Egg.js
Stars: ✭ 47 (-79.02%)
Mutual labels:  egg, egg-plugin
Egg 24time
A Twitter-like news and social server for Egg. 微信小程序社区全栈解决方案
Stars: ✭ 493 (+120.09%)
Mutual labels:  egg, egg-plugin
Egg View Ejs
egg view plugin for ejs.
Stars: ✭ 54 (-75.89%)
Mutual labels:  egg, egg-plugin
Egg Mysql
MySQL plugin for egg
Stars: ✭ 276 (+23.21%)
Mutual labels:  egg, egg-plugin
Egg Graphql
Stars: ✭ 345 (+54.02%)
Mutual labels:  egg, egg-plugin
Egg View React Ssr
Egg React Server Side Render (SSR) Plugin
Stars: ✭ 55 (-75.45%)
Mutual labels:  egg, egg-plugin
Egg Passport
passport plugin for egg
Stars: ✭ 98 (-56.25%)
Mutual labels:  egg, egg-plugin

egg-validate

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Validate plugin for egg.

See parameter for more information such as custom rule.

Install

$ npm i egg-validate --save

Usage

// config/plugin.js
exports.validate = {
  enable: true,
  package: 'egg-validate',
};

Configurations

egg-validate support all parameter's configurations, check parameter documents to get more infomations.

// config/config.default.js
exports.validate = {
  // convert: false,
  // validateRoot: false,
};

Validate Request Body

// app/controller/home.js
const Controller = require('egg').Controller;
class HomeController extends Controller {
  async index() {
    const { ctx, app } = this;
    ctx.validate({ id: 'id' }); // will throw if invalid
    // or
    const errors = app.validator.validate({ id: 'id' }, ctx.request.body);
  }
}
module.exports = HomeController;

Extend Rules

  • app.js
app.validator.addRule('jsonString', (rule, value) => {
  try {
    JSON.parse(value);
  } catch (err) {
    return 'must be json string';
  }
});

Questions & Suggestions

Please open an issue here.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].