{"id":14975551,"url":"https://github.com/ladjs/mongoose-validation-error-transform","last_synced_at":"2025-03-29T08:31:56.002Z","repository":{"id":42367814,"uuid":"99631535","full_name":"ladjs/mongoose-validation-error-transform","owner":"ladjs","description":"Automatically transform Mongoose validation error message(s) to a humanized and readable format","archived":false,"fork":false,"pushed_at":"2024-04-15T15:53:27.000Z","size":260,"stargazers_count":8,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-30T08:03:59.399Z","etag":null,"topics":["beautiful","error","handling","messages","mongo","mongodb","mongoose","mongoosejs","parser","parsing","pretty","transform","validation"],"latest_commit_sha":null,"homepage":null,"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/ladjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"niftylettuce","patreon":"niftylettuce"}},"created_at":"2017-08-08T00:09:43.000Z","updated_at":"2024-05-31T16:58:55.000Z","dependencies_parsed_at":"2024-06-20T23:22:56.512Z","dependency_job_id":"0c068fe0-897a-4573-9d5e-a440955d515f","html_url":"https://github.com/ladjs/mongoose-validation-error-transform","commit_stats":null,"previous_names":["niftylettuce/mongoose-validation-error-transform"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmongoose-validation-error-transform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmongoose-validation-error-transform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmongoose-validation-error-transform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmongoose-validation-error-transform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ladjs","download_url":"https://codeload.github.com/ladjs/mongoose-validation-error-transform/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222476287,"owners_count":16990492,"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":["beautiful","error","handling","messages","mongo","mongodb","mongoose","mongoosejs","parser","parsing","pretty","transform","validation"],"created_at":"2024-09-24T13:52:11.853Z","updated_at":"2024-10-31T20:09:03.293Z","avatar_url":"https://github.com/ladjs.png","language":"JavaScript","readme":"# mongoose-validation-error-transform\n\n[![Slack Status][slack-image]][slack-url]\n[![NPM version][npm-image]][npm-url]\n[![Standard JS Style][standard-image]][standard-url]\n[![MIT License][license-image]][license-url]\n\n\u003e Automatically transform [Mongoose][mongoose] validation error message(s) to a humanized and readable format, built for [CrocodileJS][crocodile-url].\n\n\n## Index\n\n* [Install](#install)\n* [Usage](#usage)\n* [License](#license)\n\n\n## Install\n\n```bash\nnpm install --save mongoose-validation-error-transform\n```\n\n\u003e You may also want to use [mongoose-beautiful-unique-validation][mongoose-beautiful-unique-validation] too (see [this comment][comment])!\n\n\n## Usage\n\n```js\nconst mongooseValidationErrorTransform = require('mongoose-validation-error-transform');\n\nmongoose.plugin(mongooseValidationErrorTransform, {\n\n  //\n  // these are the default options you can override\n  // (you don't need to specify this object otherwise)\n  //\n\n  // should we capitalize the first letter of the message?\n  capitalize: true,\n\n  // should we convert `full_name` =\u003e `Full name`?\n  humanize: true,\n\n  // how should we join together multiple validation errors?\n  transform: function(messages) {\n    return messages.join(', ');\n  }\n\n});\n```\n\nIf you have a Mongoose schema defined with a required String field `full_name`,\nand if there is an error with a missing `full_name` on a document - then it will\nautomatically rewrite the message of `full_name is required` to\n`Full name is required`.\n\nIf there are multiple validation error messages, such as:\n\n* `full_name is required`\n* `age is not at least (18)`\n\nThen it will rewrite the error message to `Full name is required, Age is not at least (18)`.\n\nOf course - by modifying the options mentioned above, you can transform the messages however you'd like.\n\nFor example, if you'd like to output a `\u003cul\u003e` HTML tag with `\u003cli\u003e` for each error (but only of course if there's more than one error):\n\n```js\nmongoose.plugin(mongooseValidationErrorTransform, {\n  transform: function(messages) {\n    if (messages.length === 1) return messages[0];\n    return `\u003cul\u003e\u003cli\u003e${messages.join('\u003c/li\u003e\u003cli\u003e')}\u003c/li\u003e\u003c/ul\u003e`;\n  }\n});\n```\n\nThis would output the following for the previous example:\n\n```html\n\u003cul\u003e\u003cli\u003eFull name is required\u003c/li\u003e\u003cli\u003eAge is not at least (18)\u003c/li\u003e\u003c/ul\u003e\n```\n\n\n## License\n\n[MIT](LICENSE) © Nick Baugh\n\n\n## \n\n[license-image]: http://img.shields.io/badge/license-MIT-blue.svg\n\n[license-url]: LICENSE\n\n[npm-image]: https://img.shields.io/npm/v/mongoose-validation-error-transform.svg\n\n[npm-url]: https://npmjs.org/package/mongoose-validation-error-transform\n\n[crocodile-url]: https://crocodilejs.com\n\n[standard-image]: https://img.shields.io/badge/code%20style-standard%2Bes7-brightgreen.svg\n\n[standard-url]: https://github.com/crocodilejs/eslint-config-crocodile\n\n[slack-image]: https://img.shields.io/badge/chat-join%20slack-brightgreen\n\n[slack-url]: https://join.slack.com/t/ladjs/shared_invite/zt-fqei6z11-Bq2trhwHQxVc5x~ifiZG0g\n\n[mongoose]: https://github.com/Automattic/mongoose\n\n[comment]: https://github.com/Automattic/mongoose/issues/2284#issuecomment-320810641\n\n[mongoose-beautiful-unique-validation]: https://github.com/matteodelabre/mongoose-beautiful-unique-validation\n","funding_links":["https://github.com/sponsors/niftylettuce","https://patreon.com/niftylettuce"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fmongoose-validation-error-transform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladjs%2Fmongoose-validation-error-transform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fmongoose-validation-error-transform/lists"}