{"id":41362648,"url":"https://github.com/JohnKimDev/sails-hook-req-validate","last_synced_at":"2026-02-01T19:00:30.833Z","repository":{"id":46256087,"uuid":"165903591","full_name":"JohnKimDev/sails-hook-req-validate","owner":"JohnKimDev","description":"Ultimate Request Validator Hook for SailsJS","archived":false,"fork":false,"pushed_at":"2023-01-04T21:37:54.000Z","size":310,"stargazers_count":4,"open_issues_count":10,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-30T11:55:13.107Z","etag":null,"topics":["req-validate","req-validation","req-validator","request-validate","request-validation","request-validator","sails","sails-hook","sailsjs","validation","validation-plugin","validator"],"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/JohnKimDev.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-15T18:37:24.000Z","updated_at":"2023-07-11T09:39:23.000Z","dependencies_parsed_at":"2023-02-02T20:45:16.925Z","dependency_job_id":null,"html_url":"https://github.com/JohnKimDev/sails-hook-req-validate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JohnKimDev/sails-hook-req-validate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnKimDev%2Fsails-hook-req-validate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnKimDev%2Fsails-hook-req-validate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnKimDev%2Fsails-hook-req-validate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnKimDev%2Fsails-hook-req-validate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JohnKimDev","download_url":"https://codeload.github.com/JohnKimDev/sails-hook-req-validate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnKimDev%2Fsails-hook-req-validate/sbom","scorecard":{"id":73698,"data":{"date":"2025-08-11","repo":{"name":"github.com/JohnKimDev/sails-hook-req-validate","commit":"50ca3751fdb3377c426ca18dfe6332830dc94334"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Code-Review","score":0,"reason":"Found 2/28 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"36 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-phwq-j96m-2c2q","Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-x55w-vjjp-222r","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-76c9-3jph-rj3q","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-35q2-47q7-3pc3","Warn: Project is vulnerable to: GHSA-gpw9-fwm8-7rx7","Warn: Project is vulnerable to: GHSA-8v3j-jfg3-v3fv","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-qgmg-gppg-76g5","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-15T04:22:51.679Z","repository_id":46256087,"created_at":"2025-08-15T04:22:51.680Z","updated_at":"2025-08-15T04:22:51.680Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28986317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T18:17:03.387Z","status":"ssl_error","status_checked_at":"2026-02-01T18:16:57.287Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["req-validate","req-validation","req-validator","request-validate","request-validation","request-validator","sails","sails-hook","sailsjs","validation","validation-plugin","validator"],"created_at":"2026-01-23T08:00:35.462Z","updated_at":"2026-02-01T19:00:30.815Z","avatar_url":"https://github.com/JohnKimDev.png","language":"JavaScript","funding_links":[],"categories":["Hooks"],"sub_categories":["Free"],"readme":"[![Build Status](https://travis-ci.org/JohnKimDev/sails-hook-req-validate.svg?branch=master)](https://travis-ci.org/JohnKimDev/sails-hook-req-validate)\n![dependencies](https://img.shields.io/david/johnkimdev/sails-hook-req-validate.svg)\n![dev dependencies](https://img.shields.io/david/dev/johnkimdev/sails-hook-req-validate.svg)\n\n![Downloads](https://img.shields.io/npm/dm/sails-hook-req-validate.svg)\n![Downloads](https://img.shields.io/npm/dt/sails-hook-req-validate.svg)\n![npm version](https://img.shields.io/npm/v/sails-hook-req-validate.svg)\n![License](https://img.shields.io/npm/l/sails-hook-req-validate.svg)\n\n---\n\n## Ultimate Request Validator Hook for SailsJS\n### **Over 160 Validator Types \u0026 17 Converters + Flexible Usages \u0026 Custom Options and Configurations**\nThis `sails-hook-req-validate` package uses **req.allParams()** ([Sails Document](https://sailsjs.com/documentation/reference/request-req/req-all-params)). \n\nFYI, sails' req.allParams() returns the value of all parameters sent in the request which includes ***querystring*** and ***url path***. Which means passing parameters may be string type, use ***converter*** to convert the type to an expected value type. But please note that some validation types have build-in converters, check [validation type list](https://github.com/JohnKimDev/sails-hook-req-validate/blob/master/lib/validationTypes.js) for more information.\n\nFor example: `/api/user/:age/:ismale` or `/api/user?age=12\u0026ismale=true`. req.allParams() returns all parameters as ***string***, however `sails-hook-req-validate` can correctly validate the type and convert to the correct output type in most cases. \n\n## Installation\n```javascript\n  npm install sails-hook-req-validate --save \n```\nThis is it! Once you `npm install` the hook will be automatically activated. However, if you want more control, see below for the `config/validate.js` setting.  \n\n## Report Bug \u0026 Suggest Improvement\nPlease feel free to leave any comment and suggestion .\nhttps://github.com/JohnKimDev/sails-hook-req-validate/issues/new\n\n---\n---\n\u003cbr\u003e\n\n## Optional Global Setting (config/validate.js)\nYou can create a `config/validate.js` file in TWO different ways. \nPlease note that the local, (req.validate() configuration) can overwrite the global configuration.\n\n***OPTION 1***: Simple Object Notation (no response \u0026 request objects will be passed)\n```javascript\n/**\n * Sails-Hook-Req-Validate Global Configuration\n * \n * For more information on the settings in this file, see:\n * https://github.com/JohnKimDev/sails-hook-req-validate/blob/master/readme.md\n **/\n\nmodule.exports.validate = {\n  /***************************************************************************\n  * When validation error occurs, the program can send theres.badRequest \n  * response automatically. \n  * \n  * By Default, `sendResponse` is enabled.\n  ***************************************************************************/\n  // sendResponse: true,\n\n  /***************************************************************************\n  * After the validation check, the program returns data as object or you \n  * can use a callback. But it can return the data as a PROMISE if you set\n  * `usePromise` as true.\n  * \n  * By Default, `usePromise` is disabled.\n  ***************************************************************************/\n  // usePromise: false,\n\n  /***************************************************************************\n  * When there are more incoming request parameters than listed in the\n  * `req.validate` option, by default, it will return all incoming parameters\n  * If you disable `returnAllParams` option, it will filter parameters and only\n  * return the parameters that are listed in the `req.validate` validate option\n  * \n  * By Default, `returnAllParams` is enabled.\n  ***************************************************************************/\n  // returnAllParams: true,\n\n  /***************************************************************************\n  * Error output format \n  * errMessage : ((string)) short explanation of a reason for the invalidation\n  * invalidKeys : ((array))[string] list of invalid parameter key(s)\n  * \n  * Output can be any format you want. The return value from `onErrorOutput` \n  * will be passed to the final error return.\n  ***************************************************************************/\n  // onErrorOutput: function (errMessage, invalidKeys) {\n  //   return { message: errMessage, invalid: invalidKeys };\n  // },\n\n  /***************************************************************************\n  * Required error message output\n  * keys : ((string)) or ((array))[string] one or more list of invalid \n  *        parameter key(s)\n  * \n  * [output] ((string)) \n  ***************************************************************************/\n  // requiredErrorMessage: function(keys) {\n  //   keys = keys || [];\n  //   let isare = (keys.length \u003e 1) ? 'are' : 'is';\n  //   let s = (keys.length \u003e 1) ? 's' : ''\n  //   return `The \"${keys.join('\", \"')}\" parameter${s} ${isare} required.`;\n  // },\n\n  /***************************************************************************\n  * req.validate validation format error message output\n  * key : ((string)) invalid parameter key\n  * \n  * [output] ((string)) \n  ***************************************************************************/\n  // formatErrorMessage: function(key) {\n  //   return `The \"${key}\" parameter has an invalid format.`;\n  // },\n\n  /***************************************************************************\n  * Validation configuration format error message output\n  * key : ((string)) invalid parameter key\n  * typeMessage: ((string)) types[key].message from `validationTypes.js`\n  * https://github.com/JohnKimDev/sails-hook-req-validate/blob/master/lib/validationTypes.js\n  * \n  * [output] ((string)) \n  ***************************************************************************/\n  // typeErrorMessage: function(key, typeMessage) {\n  //   let a = (typeMessage \u0026\u0026 typeMessage.length) ? /[aeiouAEIOU]/.test(typeMessage.charAt(0)) ? 'an' : 'a' : '';\n  //   return `The \"${key}\" parameter should be ${a} ${typeMessage}.`;\n  // },\n\n  /***************************************************************************\n  * Incoming request parameter invalid error message output\n  * key : ((string)) invalid parameter key\n  * typeMessage: ((string)) types[key].message from `validationTypes.js`\n  * https://github.com/JohnKimDev/sails-hook-req-validate/blob/master/lib/validationTypes.js\n  * \n  * [output] ((string)) \n  ***************************************************************************/\n  // inputErrorMessage: function(key, typeMessage) {\n  //   let a = (typeMessage \u0026\u0026 typeMessage.length) ? /[aeiouAEIOU]/.test(typeMessage.charAt(0)) ? 'an' : 'a' : '';\n  //   return `The \"${key}\" parameter has an invalid input type` + (typeMessage ? `, it should be ${a} ${typeMessage}` : '') + '.';\n  // },\n\n  /***************************************************************************\n  * Incoming request parameter invalid error message output of OR validation\n  * example: 'string|number`\n  * orKey : ((string)) invalid parameter key\n  * orTypeMessages: ((string)) combined types[key].message from `validationTypes.js`\n  * https://github.com/JohnKimDev/sails-hook-req-validate/blob/master/lib/validationTypes.js\n  * \n  * [output] ((string)) \n  ***************************************************************************/\n  // orInputErrorMessage: function(orKey, orTypeMessages) {\n  //   return `Invalid input type, it should be one of the following types; ${orTypeMessages}.`;\n  // }\n};\n```\n\n***OPTION 2***: Function return (response \u0026 request objects will be passed)\n```javascript\n/**\n * Sails-Hook-Req-Validate Global Configuration\n * \n * For more information on the settings in this file, see:\n * https://github.com/JohnKimDev/sails-hook-req-validate/blob/master/readme.md\n * \n * The response and request objects will be passed to the configuration function when initializes\n **/\n\nmodule.exports.validate = function(req, res) {\n  return {\n    /***************************************************************************\n    * When `sendResponse` is enabled. The program will use this `responseMethod`\n    * to send the error data out. By default, it will use res.badRequest. \n    * The `res` object is from the passing parameter with is a response object\n    * from the controller.\n    * \n    * You can overwrite the `responseMethod` with another response function or \n    * create your own response handler.\n    * example: \n    *    responseMethod: (data) =\u003e {\n    *       sails.log.error(data);\n    *       res.set(400).send(data);\n    *    }\n    ***************************************************************************/\n    // responseMethod: res.badRequest\n\n    /**\n     * You can use all other configurations from the OPTION 1 example\n     **/\n  };\n};\n```\n\n---\n\u003cbr\u003e\n\n## USAGE - Validator\n**sails-hook-req-validate** is very flexible and can be used in many different formats and configurations. \n\n---\n*New in 2.8.x*\n\nFunction Validation\n\n```javascript\nconst params = req.validate({\n  'evenNum': (val) =\u003e { return (val % 2 === 0); }   // you can also use a function instead of an arrow function\n}); \n\n// PRO TIP: (val) =\u003e { return (val % 2 === 0); } can be shorten to (val) =\u003e (val % 2 === 0) \n```\n\n---\n\nSingle parameter\n```javascript\nconst params = req.validate('id'); \n```\nMultiple parameters\n```javascript\nconst params = req.validate(['id', 'firstname', 'lastname']); \n```\nSimple validator\n```javascript\nconst params = req.validate({\n  'id': 'base64|number|boolean' // OR operation\n  'name': ['string', 'email'],  // AND operation\n  'email?': 'email',            // OPTIONAL parameter\n  'zipcode': 'postalcode'\n}); \n```\nCombined validators\n```javascript\nconst params = req.validate({\n  'name': ['string', { default: 'John Doe' }],  // default value if missing \n  'email?': ['email', { converter: 'normalizeEmail' }],   // optional parameter \u0026 with converter \n  'type': { enum: ['user', 'admin', 'manager'], default: 'user' } \n}); \n```\nCombined validators as array\n```javascript\nconst params = req.validate([\n  { 'name': ['string', { default: 'John Doe' }] },  // default value if missing \n  { 'email?': ['email', { converter: 'normalizeEmail' }] },   // optional parameter \u0026 with converter \n  { 'type': { enum: ['user', 'admin', 'manager'], default: 'user' } }\n]); \n```\nMultiple converters\n```javascript\nconst params = req.validate({\n  'email': ['any', { converter: ['string', 'normalizeEmail'] }]\n}); \n// not a good example but I hope you get the idea\n```\n\nCustom converter (set **FUNCTION** to `converter`)\n```javascript\nconst params = req.validate({\n  'phone':  { converter: (val) =\u003e { \n    var match = val.replace(/\\D/g, '').match(/^(\\d{3})(\\d{3})(\\d{4})$/);\n    return '(' + match[1] + ') ' + match[2] + '-' + match[3]; // (123) 456-7890\n  }}\n}); \n``` \n\u003cbr\u003e\n\n# Validator \u0026 Converter Options\n\nOption                                  | Description\n--------------------------------------- | --------------------------------------\n**enum**                                | ((array)) any combination of expected values\n**default**                             | ((string\\|number\\|boolean)) default value if the parameter is missing\n**converter**                           | ((array\\|function)) converter name as string or array of string can be used. You can pass `function` for custom converter.\u003cbr\u003eYou can also mixed types + functions in an array. \n**validator**                          | ((function)) if you need a custom validator, use this option\u003cbr\u003e\u003cbr\u003e@param `param` ((any)): passing parameter\u003cbr\u003e@return ((boolean)): return `true` if valid, `false` otherwise.\n\u003cbr\u003e\n---\n\n# More Usage Examples With Options\nYou can use with any of validator combination above.\u003cbr\u003e\n`req.validate(\u003cTYPE_VALIDATOR\u003e, \u003cCALLBACK\u003e)`\u003cbr\u003eor\u003cbr\u003e`req.validate(\u003cTYPE_VALIDATOR\u003e, \u003cOPTION\u003e, \u003cCALLBACK\u003e)`\n\n## USAGE (synchronous) - DIRECT \nOnly for `direct` method, ***`onErrorOutput`*** will be ignored! When an error occurs, ***false*** will be returned. \n```javascript\nconst params = req.validate('id');\nif (params === false) { \n  sails.log.error('The validation failed');\n} else {\n  sails.log.info('ID:', params.id);\n}\n```\n\n## USAGE (asynchronous) - CALLBACK (error, params)\n\n```javascript\nreq.validate('id', (err, params) =\u003e {\n  // callback\n  if (err) {                    // err object is the output of `onErrorOutput`\n    sails.log.error('The validation failed.', err.message); \n  } else {\n    sails.log.info(params.id);   // callback data\n  }\n});\n```\n\n---\n\n## USAGE (asynchronous) - PROMISE\nYou can use the local configuration to enable promise return or use the global configuration.\n\nES5 Promise\n```javascript\nreq.validate('id', {\n  usePromise: true  \n})\n.then(params =\u003e {\n  // callback\n  sails.log.info(params.id); // forwarded parameters if the validation passes\n})\n.catch(err =\u003e {\n  sails.log.error(err);     // err object is the output of `onErrorOutput`\n});\n```\nES6 Async/Await Promise\n```javascript\ntry {\n  const params = await req.validate('id', {\n    usePromise: true        // or use the global setting\n  });\n  sails.log.info(params.id);\ncatch (err) {\n  sails.log.error(err);     // err object is the output of `onErrorOutput`\n}  \n```\n---\n\n## My Personal Favorite Usage Method\nI like to wrap the controller codes with try-catch in case of unexpected error and use promise for `sails-hook-req-validate` \n```javascript\n// config/validate.js\nmodule.exports.validate = {\n  sendResponse: false,\n  usePromise: true,\n  returnAllParams: false,\n  onErrorOutput: (errMessage, invalidKeys) =\u003e errMessage\n};\n\n// in someController.js\nmodule.exports = {\n  index: async (req, res) =\u003e {\n    try {\n      const params = await req.validate({\n        'id': 'string',\n        'name': 'string'\n      });\n      console.log(params.id, params.name);\n      return res.ok();\n    } catch (err) {\n      return res.serverError(err);\n    }\n  }\n};\n```\n\n---\n\u003cbr\u003e\n\n## Setting Options / Configurations\n\nOption                                  | Description\n--------------------------------------- | --------------------------------------\n**responseMethod**                      | ((function)) method/function to call when a validation error occurs\u003cbr\u003e\u003cbr\u003e***default***: `res.badRequest`\u003cbr\u003e\u003cbr\u003e@param errorOutput : output from `onErrorOutput` option\n**sendResponse**                        | ((boolean)) toggle the `responseMethod` call when a validation error occurs\u003cbr\u003e\u003cbr\u003e***default***: `true`\n**usePromise**                          | ((boolean)) enable PROMISE response instead of callback\u003cbr\u003e\u003cbr\u003e***default***: `false`\n**returnAllParams**                     | ((boolean)) if ther are more passing params than listed in the req.validate, you can choose to pass-though all or filter to only listed params.\u003cbr\u003e\u003cbr\u003e***default***: `true`\n**onErrorOutput**                      | ((function)) when a validation error occurs, it will be called to generate the error output\u003cbr\u003e\u003cbr\u003e***default***: see above config/validation.js example\u003cbr\u003e\u003cbr\u003e@param `errMessage` ((string)): combined error message(s)\u003cbr\u003e@param `invalidKeys` ((string[])): list of invalid param keys\u003cbr\u003e@return : any form you want\n**requiredErrorMessage**              | ((function)) output message for param required error message\u003cbr\u003e\u003cbr\u003e***default***: see above config/validation.js example\u003cbr\u003e\u003cbr\u003e@param `keys` ((string \\| string[])): list of invalid param key(s).\u003cbr\u003e@return ((string)): formated error messgae as string type\n**formatErrorMessage**              | ((function)) output message for a validator format error message for param key\u003cbr\u003e\u003cbr\u003e***default***: see above config/validation.js example\u003cbr\u003e\u003cbr\u003e@param `key` ((string)): invalid param key.\u003cbr\u003e@param `typeMessage` ((string)): type error message, see `message` for each type of the [validationType](https://github.com/JohnKimDev/sails-hook-req-validate/blob/master/lib/validationTypes.js) file\u003cbr\u003e@return ((string)): formated error messgae as string type\n**typeErrorMessage**              | ((function)) output message for a parm type error message\u003cbr\u003e\u003cbr\u003e***default***: see above config/validation.js example\u003cbr\u003e\u003cbr\u003e@param `key` ((string)): invalid param key.\u003cbr\u003e@param `typeMessage` ((string)): type error message, see `message` for each type of the [validationType](https://github.com/JohnKimDev/sails-hook-req-validate/blob/master/lib/validationTypes.js) file\u003cbr\u003e@return ((string)): formated error messgae as string type\n**inputErrorMessage**              | ((function)) output message for a parm input error message\u003cbr\u003e\u003cbr\u003e***default***: see above config/validation.js example\u003cbr\u003e\u003cbr\u003e@param `key` ((string)): invalid param key.\u003cbr\u003e@param `typeMessage` ((string)): type error message, see `message` for each type of the [validationType](https://github.com/JohnKimDev/sails-hook-req-validate/blob/master/lib/validationTypes.js) file\u003cbr\u003e@return ((string)): formated error messgae as string type\n**orInputErrorMessage**              | ((function)) output message for a parm input error message with OR opertation. The error message for each OR validation wil be combined\u003cbr\u003e\u003cbr\u003e***default***: see above config/validation.js example\u003cbr\u003e\u003cbr\u003e@param `orKey` ((string)): invalid OR param key. (ex: 'string\\|email')\u003cbr\u003e@param `orTypeMessage` ((string)): combined type error messages, see `message` for each type of the [validationType](https://github.com/JohnKimDev/sails-hook-req-validate/blob/master/lib/validationTypes.js) file\u003cbr\u003e@return ((string)): formated error messgae as string type\n\n---\n\u003cbr\u003e\n\n## Validators\n\nList of preset available validators.\n\nNOTE: all validators are **case insensitive**\n\nValidator                               | Description\n--------------------------------------- | --------------------------------------\n**alpha**                               | check if the string contains only letters (a-zA-Z).\n**alphanumeric**                        | check if the string contains only letters and numbers.\n**ascii**                               | check if the string contains ASCII chars only.\n**array**                               | check if the value is array format. The validator uses lodash [_.isArray](https://lodash.com/docs/4.17.11#isArray) to validate the type.\n**any**                                 | return true for any type except undefined.\n**base64**                              | check if a string is base64 encoded.\n**bolean**                              | check if a string is a boolean.\n**byteLength**                          | check if the string's length (in UTF-8 bytes) falls in a range.\n**creditcard**                          | check if the string is a credit card.\n**currency**                            | check if the string is a valid currency amount. Currency symbol is optional.\n**currencyWithSymbol**                  | check if the string is a valid currency amount. Currency symbol is required.\n**dataURI**                             | check if the string is a [data uri format](https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs).\n**magnetURI**                           | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme).\n**email**                               | check if the string is an valid email address.\n**FQDN**                                | check if the string is a fully qualified domain name (e.g. domain.com)\n**float**                               | check if the string is a float.\n**hash**                                | check if the string is a hash of type algorithm.\u003cbr/\u003e\u003cbr/\u003eAlgorithm is one of `['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']`\n**hexColor**                            | check if the string is a hexadecimal color.\n**hexadecimal**                         | check if the string is a hexadecimal number.\n**ip**                                  | check if the string is an IP (either version 4 or 6).\n**ipv4**                                | check if the string is an IP version 4 only).\n**ipv6**                                | check if the string is an IP version 6 only.\n**ISBN**                                | check if the string is an ISBN (either version 10 or 13).\n**ISBN10**                              | check if the string is an ISBN version 10 only.\n**ISBN13**                              | check if the string is an ISBN version 13 only.\n**ISSN**                                | check if the string is an [ISSN](https://en.wikipedia.org/wiki/International_Standard_Serial_Number).\n**ISIN**                                | check if the string is an [ISIN][ISIN] (stock/security identifier).\n**ISO8601**                             | check if the string is a valid [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date\n**RFC3339**                             | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date.\n**ISO31661Alpha2**                     | check if the string is a valid [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) officially assigned country code.\n**ISO31661Alpha3**                     | check if the string is a valid [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) officially assigned country code.\n**ISRC**                                | check if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code).\n**int**                                 | check if the string is an integer.\u003cbr\u003e\u003cbr\u003e***Built-In Converter: int***\n**JSON**                                | check if the string is valid JSON(note: uses JSON.parse).\n**JWT**                                 | check if the string is valid JWT token.\n**LatLong**                             | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.\n**lowercase**                           | check if the string is lowercase.\n**MACAddress**                          | check if the string is a MAC address.\n**MD5**                                 | check if the string is a MD5 hash.\n**MimeType**                            | check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format\n**mobilePhone**                         | check if the string is a mobile phone number (all locales).\n**mobilephone-ar-AE**                   | check if the string is a mobile phone number of ar-AE locale\n**mobilephone-ar-DZ**                   | check if the string is a mobile phone number of ar-DZ locale\n**mobilephone-ar-EG**                   | check if the string is a mobile phone number of ar-EG locale\n**mobilephone-ar-IQ**                   | check if the string is a mobile phone number of ar-IQ locale\n**mobilephone-ar-JO**                   | check if the string is a mobile phone number of ar-JO locale\n**mobilephone-ar-KW**                   | check if the string is a mobile phone number of ar-KW locale\n**mobilephone-ar-SA**                   | check if the string is a mobile phone number of ar-SA locale\n**mobilephone-ar-SY**                   | check if the string is a mobile phone number of ar-SY locale\n**mobilephone-ar-TN**                   | check if the string is a mobile phone number of ar-TN locale\n**mobilephone-be-BY**                   | check if the string is a mobile phone number of be-BY locale\n**mobilephone-bg-BG**                   | check if the string is a mobile phone number of bg-BG locale\n**mobilephone-bn-BD**                   | check if the string is a mobile phone number of bn-BD locale\n**mobilephone-cs-CZ**                   | check if the string is a mobile phone number of cs-CZ locale\n**mobilephone-de-DE**                   | check if the string is a mobile phone number of de-DE locale\n**mobilephone-da-DK**                   | check if the string is a mobile phone number of da-DK locale\n**mobilephone-el-GR**                   | check if the string is a mobile phone number of el-GR locale\n**mobilephone-en-AU**                   | check if the string is a mobile phone number of en-AU locale\n**mobilephone-en-CA**                   | check if the string is a mobile phone number of en-CA locale\n**mobilephone-en-GB**                   | check if the string is a mobile phone number of en-GB locale\n**mobilephone-en-GH**                   | check if the string is a mobile phone number of en-GH locale\n**mobilephone-en-HK**                   | check if the string is a mobile phone number of en-HK locale\n**mobilephone-en-IE**                   | check if the string is a mobile phone number of en-IE locale\n**mobilephone-en-IN**                   | check if the string is a mobile phone number of en-IN locale\n**mobilephone-en-KE**                   | check if the string is a mobile phone number of en-KE locale\n**mobilephone-en-MU**                   | check if the string is a mobile phone number of en-MU locale\n**mobilephone-en-NG**                   | check if the string is a mobile phone number of en-NG locale\n**mobilephone-en-NZ**                   | check if the string is a mobile phone number of en-NZ locale\n**mobilephone-en-RW**                   | check if the string is a mobile phone number of en-RW locale\n**mobilephone-en-SG**                   | check if the string is a mobile phone number of en-SG locale\n**mobilephone-en-UG**                   | check if the string is a mobile phone number of en-UG locale\n**mobilephone-en-US**                   | check if the string is a mobile phone number of en-US locale\n**mobilephone-en-TZ**                   | check if the string is a mobile phone number of en-TZ locale\n**mobilephone-en-ZA**                   | check if the string is a mobile phone number of en-ZA locale\n**mobilephone-en-ZM**                   | check if the string is a mobile phone number of en-ZM locale\n**mobilephone-en-PK**                   | check if the string is a mobile phone number of en-PK locale\n**mobilephone-es-ES**                   | check if the string is a mobile phone number of es-ES locale\n**mobilephone-es-MX**                   | check if the string is a mobile phone number of es-MX locale\n**mobilephone-es-UY**                   | check if the string is a mobile phone number of es-UY locale\n**mobilephone-et-EE**                   | check if the string is a mobile phone number of et-EE locale\n**mobilephone-fa-IR**                   | check if the string is a mobile phone number of fa-IR locale\n**mobilephone-fi-FI**                   | check if the string is a mobile phone number of fi-FI locale\n**mobilephone-fr-FR**                   | check if the string is a mobile phone number of fr-FR locale\n**mobilephone-he-IL**                   | check if the string is a mobile phone number of he-IL locale\n**mobilephone-hu-HU**                   | check if the string is a mobile phone number of hu-HU locale\n**mobilephone-it-IT**                   | check if the string is a mobile phone number of it-IT locale\n**mobilephone-ja-JP**                   | check if the string is a mobile phone number of ja-JP locale\n**mobilephone-kk-KZ**                   | check if the string is a mobile phone number of kk-KZ locale\n**mobilephone-ko-KR**                   | check if the string is a mobile phone number of ko-KR locale\n**mobilephone-lt-LT**                   | check if the string is a mobile phone number of lt-LT locale\n**mobilephone-ms-MY**                   | check if the string is a mobile phone number of ms-MY locale\n**mobilephone-nb-NO**                   | check if the string is a mobile phone number of nb-NO locale\n**mobilephone-nn-NO**                   | check if the string is a mobile phone number of nn-NO locale\n**mobilephone-pl-PL**                   | check if the string is a mobile phone number of pl-PL locale\n**mobilephone-pt-PT**                   | check if the string is a mobile phone number of pt-PT locale\n**mobilephone-pt-BR**                   | check if the string is a mobile phone number of pt-BR locale\n**mobilephone-ro-RO**                   | check if the string is a mobile phone number of ro-RO locale\n**mobilephone-ru-RU**                   | check if the string is a mobile phone number of ru-RU locale\n**mobilephone-sl-SI**                   | check if the string is a mobile phone number of sl-SI locale\n**mobilephone-sk-SK**                   | check if the string is a mobile phone number of sk-SK locale\n**mobilephone-sr-RS**                   | check if the string is a mobile phone number of sr-RS locale\n**mobilephone-sv-SE**                   | check if the string is a mobile phone number of sv-SE locale\n**mobilephone-th-TH**                   | check if the string is a mobile phone number of th-TH locale\n**mobilephone-tr-TR**                   | check if the string is a mobile phone number of tr-TR locale\n**mobilephone-uk-UA**                   | check if the string is a mobile phone number of uk-UA locale\n**mobilephone-vi-VN**                   | check if the string is a mobile phone number of vi-VN locale\n**mobilephone-zh-CN**                   | check if the string is a mobile phone number of zh-CN locale\n**mobilephone-zh-HK**                   | check if the string is a mobile phone number of zh-HK locale\n**mobilephone-zh-TW**                   | check if the string is a mobile phone number of zh-TW locale\n**mongoId**                             | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].\n**multibyte**                           | check if the string contains one or more multibyte chars.\n**numeric**                             | check if the string contains only numbers. Some symbols are allow (e.g. `+`, `-`, or `.`).\n**numericOnly**                         | check if the string contains only numbers [0-9]. No symbol allow.\n**number**                              | same as `numeric`\n**object**                              | check if value is a plain object. The validator uses lodash [_.isPlainObject](https://lodash.com/docs/4.17.11#isPlainObject) to validate the type.\n**port**                                | check if the string is a valid port number.\n**postalCode**                          | check if the string is a postal code (all locales).\n**postalCode-AD**                       | check if the string is a postal code of AD\n**postalCode-AT**                       | check if the string is a postal code of AT\n**postalCode-AU**                       | check if the string is a postal code of AU\n**postalCode-BE**                       | check if the string is a postal code of BE\n**postalCode-BG**                       | check if the string is a postal code of BG\n**postalCode-CA**                       | check if the string is a postal code of CA\n**postalCode-CH**                       | check if the string is a postal code of CH\n**postalCode-CZ**                       | check if the string is a postal code of CZ\n**postalCode-DE**                       | check if the string is a postal code of DE\n**postalCode-DK**                       | check if the string is a postal code of DK\n**postalCode-DZ**                       | check if the string is a postal code of DZ\n**postalCode-ES**                       | check if the string is a postal code of ES\n**postalCode-FI**                       | check if the string is a postal code of FI\n**postalCode-FR**                       | check if the string is a postal code of FR\n**postalCode-GB**                       | check if the string is a postal code of GB\n**postalCode-GR**                       | check if the string is a postal code of GR\n**postalCode-IL**                       | check if the string is a postal code of IL\n**postalCode-IS**                       | check if the string is a postal code of IS\n**postalCode-IT**                       | check if the string is a postal code of IT\n**postalCode-JP**                       | check if the string is a postal code of JP\n**postalCode-KE**                       | check if the string is a postal code of KE\n**postalCode-LI**                       | check if the string is a postal code of LI\n**postalCode-MX**                       | check if the string is a postal code of MX\n**postalCode-NL**                       | check if the string is a postal code of NL\n**postalCode-NO**                       | check if the string is a postal code of NO\n**postalCode-PL**                       | check if the string is a postal code of PL\n**postalCode-PT**                       | check if the string is a postal code of PT\n**postalCode-RO**                       | check if the string is a postal code of RO\n**postalCode-RU**                       | check if the string is a postal code of RU\n**postalCode-SA**                       | check if the string is a postal code of SA\n**postalCode-SE**                       | check if the string is a postal code of SE\n**postalCode-TW**                       | check if the string is a postal code of TW\n**postalCode-US**                       | check if the string is a postal code of US\n**postalCode-ZA**                       | check if the string is a postal code of ZA\n**postalCode-ZM**                       | check if the string is a postal code of ZM\n**surrogatePair**                       | check if the string contains any surrogate pairs chars.\n**string**                              | check if value is string. **BE CAUTIOUS** of using this type! May return invalid result. For the parameter values from a querystring and a URL path are always `STRING` type, using this validator type may have an unexpected result.\n**URL**                                 | check if the string is an URL. allow protocols 'http', 'https', 'ftp'.\n**UUID**                                | check if the string is a UUID (version 3, 4 or 5).\n**UUIDv3**                              | check if the string is a UUID version 3\n**UUIDv4**                              | check if the string is a UUID version 4\n**UUIDv5**                              | check if the string is a UUID version 5\n**uppercase**                           | check if the string is uppercase.\n\u003cbr\u003e\n\n---\n\u003cbr\u003e\n\n## Converters\n\nList of converters available.\n\nNOTE: all converters are **case insenstive**\n\nConverter                              | Description\n-------------------------------------- | -------------------------------\n**boolean**                            | convert the input string to a boolean. Everything except for `'0'`, `'false'` and `''` returns `true`. In strict mode only `'1'` and `'true'` return `true`.\n**date**                               | convert the input string to a date, or `null` if the input is not a date.\n**escape**                             | replace `\u003c`, `\u003e`, `\u0026`, `'`, `\"` and `/` with HTML entities.\n**unescape**                           | replaces HTML encoded entities with `\u003c`, `\u003e`, `\u0026`, `'`, `\"` and `/`.\n**JSON**                               | convert to JSON using JSON.parse\n**JSON5**                              | convert to JSON using JSON5.parse\n**ltrim**                              | trim characters from the left-side of the input.\n**rtrim**                              | trim characters from the right-side of the input.\n**removeHTML**                         | strip HTML codes from the string\n**removeSpace**                        | remove all white space from the string\n**removeLineBreak**                    | remove all line breaks from the string, \\r\\n\\t, \\n, \\t\\t\n**normalizeEmail**                     | canonicalizes an email address. (This doesn't validate that the input is an email, if you want to validate the email use `email` validator beforehand).\n**lowercase**                          | convert to lower case\n**string**                             | convert to string\n**int**                                | convert the input string to an integer, or `NaN` if the input is not an integer.\n**float**                              | convert the input string to a float, or `NaN` if the input is not a float.\n**trim**                               | trim characters (whitespace by default) from both sides of the input.\n**uppercase**                          | convert to upper case\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJohnKimDev%2Fsails-hook-req-validate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJohnKimDev%2Fsails-hook-req-validate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJohnKimDev%2Fsails-hook-req-validate/lists"}