# egg-validate

> validate plugin for egg

Latest version **2.0.2** (published 2018-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-validate
pnpm add egg-validate
yarn add egg-validate
bun add egg-validate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2018-10-17 |
| First published | 2016-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 1 |
| Unpacked size | 11.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 262 |
| Author | dead_horse |
| Maintainers | atian25, dead_horse, eggjs, fengmk2, popomore |
| Keywords | egg, eggPlugin, egg-plugin, validate |

## Links

- npm: https://www.npmjs.com/package/egg-validate
- Repository: https://github.com/eggjs/egg-validate
- Homepage: https://github.com/eggjs/egg-validate#readme
- Issues: https://github.com/eggjs/egg/issues
- npm.io page: https://npm.io/package/egg-validate

## Dependencies (1)

- [parameter](https://npm.io/package/parameter.md) ^3.0.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2018-10-17
- 1.1.2 (latest-1) — 2021-09-28
- 2.0.1 — 2018-09-04
- 2.0.0 — 2018-08-30
- 1.1.1 — 2018-08-08
- 1.1.0 — 2018-08-03
- 1.0.0 — 2016-11-03
- 0.0.2 — 2016-07-17
- 0.0.1 — 2016-05-26

## README

# egg-validate

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-validate.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-validate
[travis-image]: https://img.shields.io/travis/eggjs/egg-validate.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-validate
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-validate.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-validate?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-validate.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-validate
[snyk-image]: https://snyk.io/test/npm/egg-validate/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-validate
[download-image]: https://img.shields.io/npm/dm/egg-validate.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-validate

Validate plugin for egg.

See [parameter](https://github.com/node-modules/parameter) for more information such as custom rule.

## Install

```bash
$ npm i egg-validate --save
```

## Usage

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

### Configurations

egg-validate support all parameter's configurations, check [parameter documents](https://github.com/node-modules/parameter) to get more infomations.

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

### Validate Request Body

```js
// app/controller/home.js
exports.index = function* () {
  this.validate({ id: 'id' }); // will throw if invalid
  // or
  const errors = this.app.validator.validate({ id: 'id' }, this.request.body);
};
```

### Extend Rules

- app.js

```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](https://github.com/eggjs/egg/issues).

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/egg-validate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
