{"id":20875897,"url":"https://github.com/saqqdy/egg-plugin-validate","last_synced_at":"2025-03-12T16:17:59.495Z","repository":{"id":183324588,"uuid":"658004395","full_name":"saqqdy/egg-plugin-validate","owner":"saqqdy","description":"An egg plugin for validating parameters","archived":false,"fork":false,"pushed_at":"2023-09-25T11:49:45.000Z","size":644,"stargazers_count":2,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-20T05:35:36.793Z","etag":null,"topics":["egg-plugin","egg-validate","parameter","parameters","valid","validate"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saqqdy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["saqqdy"]}},"created_at":"2023-06-24T13:20:03.000Z","updated_at":"2023-06-25T15:38:56.000Z","dependencies_parsed_at":"2024-11-18T06:49:12.346Z","dependency_job_id":"5e15a9c1-0a77-4321-acf0-130aee7a1cf1","html_url":"https://github.com/saqqdy/egg-plugin-validate","commit_stats":null,"previous_names":["saqqdy/egg-plugin-validate"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saqqdy%2Fegg-plugin-validate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saqqdy%2Fegg-plugin-validate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saqqdy%2Fegg-plugin-validate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saqqdy%2Fegg-plugin-validate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saqqdy","download_url":"https://codeload.github.com/saqqdy/egg-plugin-validate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243249011,"owners_count":20260768,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["egg-plugin","egg-validate","parameter","parameters","valid","validate"],"created_at":"2024-11-18T06:49:01.536Z","updated_at":"2025-03-12T16:17:59.474Z","avatar_url":"https://github.com/saqqdy.png","language":"JavaScript","funding_links":["https://github.com/sponsors/saqqdy"],"categories":[],"sub_categories":[],"readme":"\u003cdiv style=\"text-align: center;\" align=\"center\"\u003e\n\n# egg-plugin-validate\n\nAn egg plugin for validating parameters, Forked from [egg-validate](https://github.com/eggjs/egg-validate), And added two built-in custom rules for `object` and `array`\n\n[![NPM version][npm-image]][npm-url]\n[![Codacy Badge][codacy-image]][codacy-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n[![License][license-image]][license-url]\n\n[![Sonar][sonar-image]][sonar-url]\n\n\u003c/div\u003e\n\n\u003cdiv style=\"text-align: center; margin-bottom: 20px;\" align=\"center\"\u003e\n\nSee [parameter](https://github.com/node-modules/parameter) for more information such as custom rule.\n\n\u003c/div\u003e\n\n## Install\n\n```bash\n# use pnpm\n$ pnpm install egg-plugin-validate\n\n# use yarn\n$ yarn add egg-plugin-validate\n```\n\n## Usage\n\n```js\n// {app_root}/config/plugin.js\nexports.validate = {\n  enable: true,\n  package: 'egg-plugin-validate'\n}\n```\n\n## Configurations\n\negg-plugin-validate support all parameter's configurations, check [parameter documents](https://github.com/node-modules/parameter) to get more information.\n\n```js\n// {app_root}/config/config.default.js\nexports.validate = {\n  // convert: false,\n  // validateRoot: false,\n}\n```\n\n### Validate Request Body\n\n```js\n// {app_root}/app/controller/home.js\nconst { Controller } = require('egg')\n\nclass HomeController extends Controller {\n  async index() {\n    const { ctx, app } = this\n    ctx.validate({ id: 'id' }) // will throw if invalid\n    // or\n    const errors = app.validator.validate({ id: 'id' }, ctx.request.body)\n  }\n}\n\nmodule.exports = HomeController\n```\n\n## Extend Rules\n\n- {app_root}/app.js\n\n```js\napp.validator.addRule('object', (rule, value) =\u003e {\n  try {\n    JSON.parse(value)\n  } catch (err) {\n    return 'must be json string'\n  }\n})\n```\n\n## Change logs\n\n[Change logs](./CHANGELOG.md)\n\n## Questions \u0026 Suggestions\n\nPlease open an issue [here](https://github.com/saqqdy/egg-plugin-validate/issues).\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/egg-plugin-validate.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-plugin-validate\n[codacy-image]: https://app.codacy.com/project/badge/Grade/f70d4880e4ad4f40aa970eb9ee9d0696\n[codacy-url]: https://www.codacy.com/gh/saqqdy/egg-plugin-validate/dashboard?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=saqqdy/egg-plugin-validate\u0026utm_campaign=Badge_Grade\n[snyk-image]: https://snyk.io/test/npm/egg-plugin-validate/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-plugin-validate\n[download-image]: https://img.shields.io/npm/dm/egg-plugin-validate.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-plugin-validate\n[license-image]: https://img.shields.io/badge/License-MIT-blue.svg\n[license-url]: LICENSE\n[sonar-image]: https://sonarcloud.io/api/project_badges/quality_gate?project=saqqdy_egg-plugin-validate\n[sonar-url]: https://sonarcloud.io/dashboard?id=saqqdy_egg-plugin-validate\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaqqdy%2Fegg-plugin-validate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaqqdy%2Fegg-plugin-validate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaqqdy%2Fegg-plugin-validate/lists"}