{"id":17931055,"url":"https://github.com/hodfords-solutions/nestjs-validation","last_synced_at":"2025-07-23T01:34:22.152Z","repository":{"id":257792962,"uuid":"861501754","full_name":"hodfords-solutions/nestjs-validation","owner":"hodfords-solutions","description":"A utility for simplifying validation and providing translated error messages in NestJS applications","archived":false,"fork":false,"pushed_at":"2025-03-20T03:04:20.000Z","size":373,"stargazers_count":49,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-19T15:06:04.286Z","etag":null,"topics":["nestjs","nodejs","validation"],"latest_commit_sha":null,"homepage":"https://opensource.hodfords.uk/nestjs-validation","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hodfords-solutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2024-09-23T02:53:53.000Z","updated_at":"2025-03-20T02:25:29.000Z","dependencies_parsed_at":"2025-01-08T22:21:45.267Z","dependency_job_id":"e344db2f-a94f-47c5-bbc4-50075f24cc5a","html_url":"https://github.com/hodfords-solutions/nestjs-validation","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"bd16a8da646c954436a5fe89ae649cf10075dfeb"},"previous_names":["hodfords-solutions/nestjs-validation"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/hodfords-solutions/nestjs-validation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hodfords-solutions%2Fnestjs-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hodfords-solutions%2Fnestjs-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hodfords-solutions%2Fnestjs-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hodfords-solutions%2Fnestjs-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hodfords-solutions","download_url":"https://codeload.github.com/hodfords-solutions/nestjs-validation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hodfords-solutions%2Fnestjs-validation/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266602820,"owners_count":23954696,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["nestjs","nodejs","validation"],"created_at":"2024-10-28T21:19:19.314Z","updated_at":"2025-07-23T01:34:22.128Z","avatar_url":"https://github.com/hodfords-solutions.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://opensource.hodfords.uk\" target=\"blank\"\u003e\u003cimg src=\"https://opensource.hodfords.uk/img/logo.svg\" width=\"320\" alt=\"Hodfords Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e \u003cb\u003enestjs-validation\u003c/b\u003e enhances validation in your NestJS projects by providing a customized \u003cb\u003eValidationPipe\u003c/b\u003e that returns custom error messages. This library simplifies error handling by offering localized and user-friendly responses\u003c/p\u003e\n\n## Installation 🤖\n\nInstall the `nestjs-validation` package with:\n\n```bash\nnpm install @hodfords/nestjs-validation --save\n```\n\n## Usage 🚀\n\nFirst, create an instance of `ValidationPipe` with the desired configuration:\n\n```typescript\nimport { ValidationPipe } from '@hodfords/nestjs-validation';\nimport { ValidateException } from '@hodfords/nestjs-exception';\n\nexport const validateConfig = new ValidationPipe({\n    whitelist: true,\n    stopAtFirstError: true,\n    forbidUnknownValues: false,\n    exceptionFactory: (errors): ValidateException =\u003e new ValidateException(errors)\n});\n```\n\nNext, set the validation configuration globally in your bootstrap function:\n\n```typescript\nasync function bootstrap() {\n    const app = await NestFactory.create(AppModule);\n    app.useGlobalPipes(validateConfig);\n    await app.listen(3000);\n}\n```\n\n### Customize Validation Error\n\nThe original error message provides basic information but lacks detail. With **nestjs-validation**, you can enhance these errors by adding meaningful context, such as the field’s property name, value, and target object.\n\n**Original Validation Error**\n\n```javascript\nValidationError {\n  target: AppDto { stringValue: undefined },\n  value: undefined,\n  property: 'stringValue',\n  children: [],\n  constraints: { isString: 'stringValue must be a string' }\n}\n```\n\n**Customized Validation Error**\n\n```javascript\nValidationError {\n  target: AppDto { stringValue: undefined },\n  value: undefined,\n  property: 'stringValue',\n  children: [],\n  constraints: {\n    isString: {\n      message: '$property must be a string',\n      detail: { property: 'stringValue', target: 'AppDto', value: undefined }\n    }\n  }\n}\n```\n\n### Exception\n\nWhen combined with [nestjs-exception](https://www.npmjs.com/package/@hodfords/nestjs-exception), errors are translated into localized messages:\n\n```json\n{\n    \"message\": \"Validate Exception\",\n    \"errors\": {\n        \"stringValue\": {\n            \"messages\": [\"String Value must be a string\"]\n        }\n    }\n}\n```\n\n## License 📝\n\nThis project is licensed under the MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhodfords-solutions%2Fnestjs-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhodfords-solutions%2Fnestjs-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhodfords-solutions%2Fnestjs-validation/lists"}