0.0.7 • Published 8 years ago

egg-antd-form-validator v0.0.7

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

egg-antd-form-validator

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

Sharing validator scheme between frontend and backend with Ant Design style

Install

$ npm i egg-antd-form-validator --save

Usage

// {app_root}/config/plugin.js
exports['egg-antd-form-validator'] = {
  package: 'egg-antd-form-validator',
};

Validate Request Body

More Scheme reference async-validator

// {app_root}/app/controller/home.js

const scheme = {
  id: [{
    type: 'string',
    required: true,
  }]
};

exports.index = function* () {
  const error = this.validate(scheme)(this.request.body);
  if (error) {
    // [{ fields: 'id', message: 'why it fail' }]
    // throw manually
  }
};

typings

import { IErrorField, ISchemeOptions } from 'egg-antd-form-validator';
declare module 'chair' {
  export interface Context {
    validate: (scheme: any, options?: ISchemeOptions) => (values: any) => Promise<IErrorField[] | null>
  }
}

use it standalone without egg.js

import { validate } from 'egg-antd-form-validator';

if (await validate(scheme)(values)) {
  // throw
}
0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago