{"_id":"joi-errors-for-forms","_rev":"9-3af529fd4add27559604468314354f4c","name":"joi-errors-for-forms","description":"Convert Joi errors to form UI or Mongoose schemas, optionally changing the message text.","dist-tags":{"latest":"0.2.6"},"versions":{"0.0.1":{"name":"joi-errors-for-forms","version":"0.0.1","description":"Convert Joi errors to the { name1: text, name2: text } format commonly used with forms.","main":"index.js","scripts":{"test":"node ./test1.js"},"repository":{"type":"git","url":"git+https://github.com/eddyystop/joi-errors-for-forms.git"},"keywords":["joi","error","errors","form","forms"],"author":{"name":"John Szwaronek","email":"johnsz9999@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/eddyystop/joi-errors-for-forms/issues"},"homepage":"https://github.com/eddyystop/joi-errors-for-forms#readme","engines":{"node":">4.2.4"},"gitHead":"7f7969cfc8ab17dbcfb1d816dc9abe57a1275b2a","_id":"joi-errors-for-forms@0.0.1","_shasum":"fa3f99533d4795105ee47f139bdcdddb158de953","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.2.2","_npmUser":{"name":"eddystop","email":"johnsz9999@gmail.com"},"dist":{"shasum":"fa3f99533d4795105ee47f139bdcdddb158de953","tarball":"https://registry.npmjs.org/joi-errors-for-forms/-/joi-errors-for-forms-0.0.1.tgz","integrity":"sha512-LewTZi2BJQemXvmA5rz73gkdS6hYMu7uZ2ZsCx7WdLJECXEBuBhRp1Jka6MTxAXTUXluj3E+oAEuJETMh+I+1w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDzarRLBEGWPv27RA3cXne97VTlC3zzu0iA1L9yoKTe/QIhAMecmMpHVEGCqELNKQdqzrtRf6eblySXLwOfPjen5h+Z"}]},"maintainers":[{"name":"eddystop","email":"johnsz9999@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/joi-errors-for-forms-0.0.1.tgz_1468096188323_0.07050551334396005"},"directories":{}},"0.2.2":{"name":"joi-errors-for-forms","version":"0.2.2","description":"Convert Joi errors to form UI or Mongoose schemas, optionally changing the message text.","main":"index.js","scripts":{"test":"node test1.js"},"repository":{"type":"git","url":"git+https://github.com/eddyystop/joi-errors-for-forms.git"},"keywords":["joi","error","errors","form","forms","i18n"],"author":{"name":"John Szwaronek","email":"johnsz9999@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/eddyystop/joi-errors-for-forms/issues"},"homepage":"https://github.com/eddyystop/joi-errors-for-forms#readme","engines":{"node":">4.2.4"},"gitHead":"d51155e013520b9cdad34f39bbc064a0b1e1f0e6","_id":"joi-errors-for-forms@0.2.2","_shasum":"e3c3aa1ba1c6eb5c28eb402bbe43ec0247c6104a","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.2.2","_npmUser":{"name":"eddystop","email":"johnsz9999@gmail.com"},"dist":{"shasum":"e3c3aa1ba1c6eb5c28eb402bbe43ec0247c6104a","tarball":"https://registry.npmjs.org/joi-errors-for-forms/-/joi-errors-for-forms-0.2.2.tgz","integrity":"sha512-yWM2T4c75uUdGyf81yvzlgpAcjQ2yhiC/FO9IE2c1XfpuYYAAzVOqQuMY67Frka+jsfsWO2H5sb3mdTNaX2zNQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFsJkoBvrQUtQm7Hq2CbaDa6EEImbhaHc8Ixr2CRR4U8AiEA4EnIDH4DT+sc6Bijok6HRnPKDlbSB4vIUTJXLHjw0ik="}]},"maintainers":[{"name":"eddystop","email":"johnsz9999@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/joi-errors-for-forms-0.2.2.tgz_1468234192311_0.3375378274358809"},"directories":{}},"0.2.3":{"name":"joi-errors-for-forms","version":"0.2.3","description":"Convert Joi errors to form UI or Mongoose schemas, optionally changing the message text.","main":"index.js","scripts":{"test":"node test/test1.js"},"repository":{"type":"git","url":"git+https://github.com/eddyystop/joi-errors-for-forms.git"},"keywords":["joi","error","errors","form","forms","i18n"],"author":{"name":"John Szwaronek","email":"johnsz9999@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/eddyystop/joi-errors-for-forms/issues"},"homepage":"https://github.com/eddyystop/joi-errors-for-forms#readme","engines":{"node":">4.2.4"},"gitHead":"5e3901ff985b0b24299cb7b8dd7546c3dd6bb7d7","_id":"joi-errors-for-forms@0.2.3","_shasum":"3567673a6dfea1a6ff9e9d287d3b50e66ba39793","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.2.2","_npmUser":{"name":"eddystop","email":"johnsz9999@gmail.com"},"dist":{"shasum":"3567673a6dfea1a6ff9e9d287d3b50e66ba39793","tarball":"https://registry.npmjs.org/joi-errors-for-forms/-/joi-errors-for-forms-0.2.3.tgz","integrity":"sha512-3LUfoN3W6ze0ivyQEEMdrN/uuU42m17tOYRrwHmr6rjKdwK7zAFCKTFZGrePz3F3bdkkIlMPeEuTrRV75c1JsQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFCKTCyIpc+yBEddmz8P1fQGOYTRvdO4gsyDB2bY0jb7AiEA8ICEHHpgSkUvfD6ohtqkqzkBWWy3zOk4Qdr72GgXnUs="}]},"maintainers":[{"name":"eddystop","email":"johnsz9999@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/joi-errors-for-forms-0.2.3.tgz_1468332192895_0.795562356011942"},"directories":{}},"0.2.4":{"name":"joi-errors-for-forms","version":"0.2.4","description":"Convert Joi errors to form UI or Mongoose schemas, optionally changing the message text.","main":"index.js","scripts":{"test":"node test/test1.js"},"repository":{"type":"git","url":"git+https://github.com/eddyystop/joi-errors-for-forms.git"},"keywords":["joi","error","errors","form","forms","i18n"],"author":{"name":"John Szwaronek","email":"johnsz9999@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/eddyystop/joi-errors-for-forms/issues"},"homepage":"https://github.com/eddyystop/joi-errors-for-forms#readme","engines":{"node":">4.2.4"},"gitHead":"9c494599facb2015b39c055c54cff1ad75b5ecc7","_id":"joi-errors-for-forms@0.2.4","_shasum":"c18a5df446079a0b7f18a4e8a43d273d230e077a","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.2.2","_npmUser":{"name":"eddystop","email":"johnsz9999@gmail.com"},"dist":{"shasum":"c18a5df446079a0b7f18a4e8a43d273d230e077a","tarball":"https://registry.npmjs.org/joi-errors-for-forms/-/joi-errors-for-forms-0.2.4.tgz","integrity":"sha512-4hKRu20RATf0yD5lXNWlBteOaDz1DBsjNpB6xYqr+Avc++o7FLJ9J+n1jGptqPirKppd4bFpNo7ztzY+5V6idQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCHohFLqwZl9drN5q2pixC7SMXeahczp7psBJio70Y/mAIhALDJS1mfhTh2bMXTmuPrv6UX/C2pv4tc55QddU+TZ30J"}]},"maintainers":[{"name":"eddystop","email":"johnsz9999@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/joi-errors-for-forms-0.2.4.tgz_1468346976442_0.14935369906015694"},"directories":{}},"0.2.5":{"name":"joi-errors-for-forms","version":"0.2.5","description":"Convert Joi errors to form UI or Mongoose schemas, optionally changing the message text.","main":"index.js","scripts":{"test":"node test/test1.js"},"repository":{"type":"git","url":"git+https://github.com/eddyystop/joi-errors-for-forms.git"},"keywords":["joi","error","errors","form","forms","i18n"],"author":{"name":"John Szwaronek","email":"johnsz9999@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/eddyystop/joi-errors-for-forms/issues"},"homepage":"https://github.com/eddyystop/joi-errors-for-forms#readme","engines":{"node":">4.2.4"},"gitHead":"814f44f4b4f592e662327e1af5091c131f8ea370","_id":"joi-errors-for-forms@0.2.5","_shasum":"6098a1a6fe224f4c635c1b8815dc85cccae05029","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.2.2","_npmUser":{"name":"eddystop","email":"johnsz9999@gmail.com"},"dist":{"shasum":"6098a1a6fe224f4c635c1b8815dc85cccae05029","tarball":"https://registry.npmjs.org/joi-errors-for-forms/-/joi-errors-for-forms-0.2.5.tgz","integrity":"sha512-BbhqtTJuVyRWQKVh8M0wxSFEOS0g6AS1x6Z5va3ZC9skFkFuaZiydu5VJG4ymnobRV9qtmXfVnoxR7RJy3R6Cg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC8NKBB48MLJ1Un/yyyjVhaAhKk3Hzde9HZycE+yUH8yAIhAKxmHUiAmjIylUQ16UFlvcGaJSeXhxCFqazaIBQC5rru"}]},"maintainers":[{"name":"eddystop","email":"johnsz9999@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/joi-errors-for-forms-0.2.5.tgz_1468347309458_0.9120646324008703"},"directories":{}},"0.2.6":{"name":"joi-errors-for-forms","version":"0.2.6","description":"Convert Joi errors to form UI or Mongoose schemas, optionally changing the message text.","main":"index.js","scripts":{"test":"node test/test1.js"},"repository":{"type":"git","url":"git+https://github.com/eddyystop/joi-errors-for-forms.git"},"keywords":["joi","error","errors","form","forms","i18n"],"author":{"name":"John Szwaronek","email":"johnsz9999@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/eddyystop/joi-errors-for-forms/issues"},"homepage":"https://github.com/eddyystop/joi-errors-for-forms#readme","engines":{"node":">4.2.4"},"gitHead":"8511c3455a950545cdc297686bc8844ee6f292da","_id":"joi-errors-for-forms@0.2.6","_npmVersion":"5.6.0","_nodeVersion":"8.6.0","_npmUser":{"name":"eddystop","email":"johnsz9999@gmail.com"},"dist":{"integrity":"sha512-9jgUVquSg4mUIYOYmYauJhK3l9VeAFAWuzVVm5hNB9Y1BQ48YNVW01/ZUFLi1kP34NE5qnH4RbF0OI48kOhEEg==","shasum":"b5aba9eb08177d8e6f46405669d208b93f20d0e6","tarball":"https://registry.npmjs.org/joi-errors-for-forms/-/joi-errors-for-forms-0.2.6.tgz","fileCount":15,"unpackedSize":50447,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCMZjhP/vBXuxrGE73T2LLwEdbG5VmBpKWiCv9V8FmgrAIhAP7q7YK9pwfWHyeSp7sLiPzhbym66yTPFjHZZ9zMYFrt"}]},"maintainers":[{"name":"eddystop","email":"johnsz9999@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/joi-errors-for-forms_0.2.6_1520463630187_0.7758699070353343"},"_hasShrinkwrap":false}},"readme":"## joi-errors-for-forms\n\nIn order to keep a consistent validation API in your apps,\nconvert the error objects returned by [Joi](https://github.com/hapijs/joi) to either\n\n- the `{ name1: text, name2: text }` schema commonly used with form UIs, or\n- the Mongoose schema\n`{ name1: { message: ..., name: 'ValidatorError', path: ..., type: ... } }`.\n\nThe Joi error messages may be replaced either for internationalization or clarity.\n\nThe package has no dependencies.\n\n[![Build Status](https://travis-ci.org/eddyystop/joi-errors-for-forms.svg?branch=master)](https://travis-ci.org/eddyystop/joi-errors-for-forms)\n\n## Code Examples\n\nFor the following Joi schema:\n\n```javascript\nconst Joi = require('joi');\nconst name = Joi.string().trim().regex(/^[\\sa-zA-Z0-9]{5,30}$/).required();\nconst password = Joi.string().trim().min(2).max(30).required();\nconst schema = Joi.object().keys({\n  name,\n  password,\n  confirmPassword: password.label('Confirm password'),\n});\nconst joiOptions = { convert: true, abortEarly: false };\n\nconst values = { name: 'j', password: 'z', confirmPassword: 'z' };\n```\n\n(1) Convert the Joi messages to the form UI schema, retaining the original message text.\n\n```javascript\nconst joiToForms = require('joi-errors-for-forms').form;\nconst convertToForms = joiToForms();\n\nJoi.validate(values, schema, joiOptions, (errs, convertedValues) => {\n  console.log(convertToForms(errs));\n  // { name: '\"name\" with value \"j\" fails to match the required pattern: /^[\\\\sa-zA-Z0-9]{5,30}$/',\n  //   password: '\"password\" length must be at least 2 characters long',\n  //   confirmPassword: '\"Confirm password\" length must be at least 2 characters long'\n  // }\n  // or null if no errors.\n});\n```\n\n\n(2) Convert to the form UI schema. Replace Joi messages using Joi error types. (Recommended.)\n\n```javascript\nconst joiToForms = require('joi-errors-for-forms').form;\nconst convertToForms = joiToForms({\n  'string.min': () => i18n('\"${key}\" must be ${limit} or more chars.'),\n  'string.regex.base': (context) => {\n    switch (context.pattern.toString()) {\n      case /^[\\sa-zA-Z0-9]{5,30}$/.toString():\n        return i18n('\"${key}\" must consist of letters, digits or spaces.');\n    }\n  }\n});\n\nJoi.validate(values, schema, joiOptions, (errs, convertedValues) => {\n  console.log(convertToForms(errs));\n  // { name: '\"name\" must consist of letters, digits or spaces.',\n  //   password: '\"password\" must be 2 or more chars.',\n  //   confirmPassword: '\"Confirm password\" must be 2 or more chars.'\n  // }\n});\n\nfunction i18n(str) { return str; } // internationalization\n\n```\n\nor convert to the Mongoose schema.\n\n```javascript\nconst joiToMongoose = require('joi-errors-for-forms').mongoose;\nconst convertToMongoose = joiToMongoose({\n  ... same as above ...\n});\n\nJoi.validate(values, schema, joiOptions, (errs, convertedValues) => {\n  console.log(convertToMongoose(errs));\n  // { name: \n  //     { message: '\"name\" must consist of letters, digits or spaces.',\n  //       name: 'ValidatorError',\n  //       path: 'name',\n  //       type: 'string.regex.base' },\n  //   password: \n  //     { message: '\"password\" must be 2 or more chars.',\n  //       name: 'ValidatorError',\n  //       path: 'password',\n  //       type: 'string.min' },\n  //   confirmPassword: \n  //     { message: '\"Confirm password\" must be 2 or more chars.',\n  //       name: 'ValidatorError',\n  //       path: 'confirmPassword',\n  //       type: 'string.min' }\n  // }\n});\n\n```\n\nList of substitution tokens. Refer to Joi documentation for more information.\n\n- `${key}` prop name, or label if `.label('...')` was used.\n- `${value}` prop value. Its rudimentally converted to a string.\n- `${pattern}` regex value if `.regex(...)` was involved in the error. Its converted to a string.\n- `${limit}` allowed length of string.\n- `${encoding}` string encoding. Could be `undefined`. Its converted to a string.\n\nNote that `type` retains the Joi value in the Mongoose schema.\nIt is not converted to what Mongoose would return.\n\n\n(3) Replace Joi messages with a generic error message.\n\n```javascript\nconst convertToForms = joiToForms('\"${key}\" is badly formed.');\n\nJoi.validate(values, schema, joiOptions, (errs, convertedValues) => {\n  console.log(convertToForms(errs));\n  // { name: '\"name\" is badly formed.',\n  //   password: '\"password\" is badly formed.',\n  //   confirmPassword: '\"Confirm password\" is badly formed.'\n  // }\n});\n\n```\n\n\n(4) Replace Joi messages, by searching for substrings in Joi messages.\n\n```javascript\nconst convertToForms = joiToForms([\n  { regex: 'at least 2 characters long',\n    message: '\"${key}\" must be 2 or more chars.'\n  },\n  { regex: /required pattern/,\n    message: '\"${key}\" is badly formed.'\n  }\n]);\n\nJoi.validate(values, schema, joiOptions, (errs, convertedValues) => {\n  console.log(convertToForms(errs));\n  // { name: '\"name\" is badly formed.',\n  //   password: '\"password\" must be 2 or more chars.',\n  //   confirmPassword: '\"Confirm password\" must be 2 or more chars.'\n  // }\n});\n\n```\n\n## Motivation\n\n[Joi](https://github.com/hapijs/joi) is an enterprise strength schema validator and sanitizer\noriginally developed by Walmart.\n\nThe error object it returns, however, usually has to be reformatted for use within web/mobile apps.\nIts error messages may also have to be converted for internationalization or for clarity.\n\nThis package helps with both needs.\n\n## Installation\n\nInstall [Nodejs](https://nodejs.org/en/).\n\nRun `npm install joi-errors-for-forms --save` in your project folder.\n\nYou can then require the package.\n\n```javascript\n// ES5\nvar joiErrorsToForms = require('joi-errors-for-forms');\nvar joiToForms = joiErrorsToForms.form;\nvar joiToMongoose = joiErrorsToForms.mongoose;\n// or ES6\nimport { form as joiToForms, mongoose as joiToMongoose } from 'joi-errors-for-forms';\n```\n\n## API Reference\n\nSee Code Examples.\n\n## Tests\n\n`npm test` to run tests.\n\n## A Note on Internationalization\n\nThe `options` in `Joi.validate(value, schema, options, cb)`supports a\n[`language` option](https://github.com/hapijs/joi/blob/v9.0.0/API.md#validatevalue-schema-options-callback)\nwith which you can change\n[Joi error messages](https://github.com/hapijs/joi/blob/v9.0.0/lib/language.js)\nin bulk.\n\nYou can then internationalize your field names and regex descriptions in the schema, e.g.\n\n```javascript\nJoi.string().regex(/^[\\sa-zA-Z0-9]$/, i18n('letters, number and spaces')).label(i18n('Confirm password'))\n```\n\nThese are suitable methods to internationalize the majority of Joi error messages.\n\n## Contributors\n\n- [eddyystop](https://github.com/eddyystop)\n\n## License\n\nMIT. See LICENSE.\n","maintainers":[{"name":"eddystop","email":"johnsz9999@gmail.com"}],"time":{"modified":"2022-06-19T04:41:54.764Z","created":"2016-07-09T20:29:49.660Z","0.0.1":"2016-07-09T20:29:49.660Z","0.2.2":"2016-07-11T10:49:53.914Z","0.2.3":"2016-07-12T14:03:15.737Z","0.2.4":"2016-07-12T18:09:38.783Z","0.2.5":"2016-07-12T18:15:11.919Z","0.2.6":"2018-03-07T23:00:30.231Z"},"homepage":"https://github.com/eddyystop/joi-errors-for-forms#readme","keywords":["joi","error","errors","form","forms","i18n"],"repository":{"type":"git","url":"git+https://github.com/eddyystop/joi-errors-for-forms.git"},"author":{"name":"John Szwaronek","email":"johnsz9999@gmail.com"},"bugs":{"url":"https://github.com/eddyystop/joi-errors-for-forms/issues"},"license":"MIT","readmeFilename":"README.md"}