{"id":32580964,"url":"https://github.com/daviinacio/rest-payload-validator","last_synced_at":"2026-05-18T05:46:32.011Z","repository":{"id":57354938,"uuid":"400344645","full_name":"daviinacio/rest-payload-validator","owner":"daviinacio","description":"Easy and powerful payload validator for your nodejs projects","archived":false,"fork":false,"pushed_at":"2021-09-06T01:31:49.000Z","size":63,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-28T07:51:37.234Z","etag":null,"topics":["javascript","library","npm","package","validation","validation-library","validator"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/rest-payload-validator","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/daviinacio.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":"2021-08-27T00:43:52.000Z","updated_at":"2021-09-17T19:31:56.000Z","dependencies_parsed_at":"2022-09-26T16:31:36.043Z","dependency_job_id":null,"html_url":"https://github.com/daviinacio/rest-payload-validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/daviinacio/rest-payload-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviinacio%2Frest-payload-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviinacio%2Frest-payload-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviinacio%2Frest-payload-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviinacio%2Frest-payload-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daviinacio","download_url":"https://codeload.github.com/daviinacio/rest-payload-validator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviinacio%2Frest-payload-validator/sbom","scorecard":{"id":327886,"data":{"date":"2025-08-11","repo":{"name":"github.com/daviinacio/rest-payload-validator","commit":"fbb92d62cc98980235cdfd6b915e73bfb65373aa"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"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":"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":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"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":"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":"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":"Code-Review","score":0,"reason":"Found 0/13 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":"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 'main'"],"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":"Vulnerabilities","score":0,"reason":"16 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"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-18T02:55:14.810Z","repository_id":57354938,"created_at":"2025-08-18T02:55:14.810Z","updated_at":"2025-08-18T02:55:14.810Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281653764,"owners_count":26538522,"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-10-29T02:00:06.901Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["javascript","library","npm","package","validation","validation-library","validator"],"created_at":"2025-10-29T16:28:52.782Z","updated_at":"2025-10-29T16:28:56.685Z","avatar_url":"https://github.com/daviinacio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rest Payload Validator\n[![npm](https://img.shields.io/npm/v/rest-payload-validator.svg)](https://www.npmjs.com/package/rest-payload-validator)\n\nEasy and powerful payload validator for your nodejs projects.\nThis module works server-side and client-side\n\n## Installation\nImport this module on your project\n\n*Using NPM*\n```shell\nnpm install --save rest-payload-validator\n```\n\n*Using Yarn*\n```shell\nyarn add rest-payload-validator\n```\n## Usage\n### Basic validator structure\n```javascript\n/* Build a new instance of validator */\n\n// Using build\nValidator.build({\n  values: {},   // Input data\n  rules: {},    // Rules to validate\n  messages: {}  // Custom error messages\n})\n\n// Using builder\nValidator.builder()\n  .values({})   // Input data\n  .rules({})    // Rules to validate\n  .messages({}) // Custom error messages\n.build()\n\n\n/* Check validation result */\n\n// Using boolean condition\nif(validator_instance.alright()){\n  // ...\n}\nelse {\n  console.log(validator_instance.errors)\n}\n\n// Using fallbacks\n.alright((data) =\u003e {})\n.failed((errors) =\u003e {})\n```\n\n\n### Example: Object validation\n```javascript\nValidator.build({\n  values: {\n    name: \"abcd\",\n    age: 21,\n    email: \"example@example.com\"\n  },\n  rules: {\n    'name': \"required|string\",\n    'age': \"required|integer\",\n    'email': \"required|email\"\n  },\n  messages: {\n    'name.string': \"Custom message for 'name.string'\",\n    'name.required': \"Custom message for 'name.required'\",\n    'age.string': \"Custom message for 'age.string'\",\n    'age.required': \"Custom message for 'age.required'\",\n    'email.string': \"Custom message for 'email.string'\",\n    'email.required': \"Custom message for 'email.required'\",\n    // or\n    'name': {\n      'string': \"Custom message for 'name.string'\",\n      'required': \"Custom message for 'name.required'\",\n    },\n    'age': {\n      'string': \"Custom message for 'age.string'\",\n      'required': \"Custom message for 'age.required'\",\n    },\n    'email': {\n      'string': \"Custom message for 'email.string'\",\n      'required': \"Custom message for 'email.required'\",\n    }\n  }\n})\n.alright((data) =\u003e {\n  // ...\n})\n.failed((errors) =\u003e {\n  // ...\n})\n```\n\n### Example: Objects into object\n```javascript\nValidator.build({\n  values: {\n    user: {\n      address: {\n        street: \"abc\",\n        zip_code: 123\n      }\n    }\n  },\n  rules: {\n    'user': {\n      'address': {\n        'street': \"string\",\n        'zip_code': \"integer\"\n      }\n    }\n  },\n  messages: {\n    'user': {\n      'address': {\n        'street.string': \"Custom message for 'street.string'\",\n        'zip_code.integer': \"Custom message for 'zip_code.integer'\",\n        // or\n        'street': {\n          'string': \"Custom message for 'street.string'\"\n        },\n        'zip_code': {\n          'integer': \"Custom message for 'zip_code.integer'\"\n        }\n      }\n    }\n  }\n})\n.alright((data) =\u003e {\n  // ...\n})\n.failed((errors) =\u003e {\n  // ...\n})\n```\n\n### Example: Lists, Collections and Entries\n\n```javascript\n/* Array of values (List)*/\n\nValidator.build({\n  values: {\n    list: [\n      1, 2, 3, 4\n    ]\n  },\n  rules: {\n    'list': [\"integer\"]\n  },\n  messages: {\n    'list.array': \"Custom message for 'list.array'\",\n    'list.*': {\n      'integer': \"Custom message for '{n}.integer'\"\n    },\n    // or\n    'list': {\n      'array': \"Custom message for 'list.array'\",\n      'integer': \"Custom message for '{n}.integer'\"\n    }\n  }\n})\n.alright((data) =\u003e {\n  // ...\n})\n.failed((errors) =\u003e {\n  // ...\n})\n```\n\n```javascript\n/* Array of objects (Collection) */\n\nValidator.build({\n  values: {\n    collection: [\n      {\n        text: \"123\",\n        number: 123\n      },\n      {\n        text: \"456\",\n        number: 456\n      }\n    ]\n  },\n  rules: {\n    'collection': [{\n      'text': \"string|min:6|max:256\",\n      'number': \"integer\"\n    }]\n  },\n  messages: {\n    'collection.*': {\n      'text.string': \"Custom message for 'text.string'\",\n      'text.min': \"Custom message for 'text.min'\",\n      'text.max': \"Custom message for 'text.max'\",\n      'number.string': \"Custom message for 'number.string'\"\n      // or\n      'text': {\n        'string': \"Custom message for 'text.string'\",\n        'min': \"Custom message for 'text.min'\",\n        'max': \"Custom message for 'text.max'\"\n      },\n      'number': {\n        'string': \"Custom message for 'number.string'\"\n      }\n    }\n  }\n})\n.alright((data) =\u003e {\n  // ...\n})\n.failed((errors) =\u003e {\n  // ...\n})\n```\n\n```javascript\n/* Array of Arrays (Entries) */\n\nValidator.build({\n  values: {\n    entries: [\n      [ 1, 2, 3, 4 ],\n      [ 'a', 'b', 'c', 'd' ]\n    ]\n  },\n  rules: {\n    'entries': [\n      [\"integer\"],\n      [\"string\"]\n    ]\n  },\n  messages: {\n    'entries'{\n      '0': {\n        '*': {\n          'integer': \"Custom message\"\n        }\n      },\n      '1': {\n        '*': {\n          'string': \"Custom message\"\n        }\n      }\n      // or\n      '0.*': {\n        'integer': \"Custom message\"\n      },\n      '1.*': {\n        'string': \"Custom message\"\n      }\n    }\n  }\n})\n.alright((data) =\u003e {\n  // ...\n})\n.failed((errors) =\u003e {\n  // ...\n})\n```\n\n### Revalidate\n```javascript\nconst values = {\n  variable1: 1,\n  variable2: 2\n}\n\nconst validation = Validator.build({\n  values,\n  rules: {\n    'variable1': \"string\",\n    'variable2': \"string\"\n  }\n})\n\n// First check without errors\nif(validation.alright()){\n  return;\n}\n\n// Change values\nif('variable1.string' in validation.errors)\n  values.variable1 = \"text-value1\"\n\nif('variable2.string' in validation.errors)\n  values.variable2 = \"text-value2\"\n\n// Revalidate\nif(validation.alright()){\n  return;\n}\n```\n\n## Messages\nYou can override the default error message using the a custom `field message`.\n\n### Basic message\n```javascript\n{\n  'field.rule1': \"Custom message\",\n  'field.rule2': \"Custom message\"\n}\n```\n\n### Grouped by field name\n```javascript\n{\n  'field': {\n    'rule1': \"Custom message\",\n    'rule2': \"Custom message\"\n  }\n}\n```\n\n### Message for all items in an array\n```javascript\n/* List of values */\n\n{\n  'field': {\n    '*': {\n      'rule1': \"Custom message\",\n      'rule2': \"Custom message\"\n    }\n  }\n  // or\n  'field.*'{\n    'rule1': \"Custom message\",\n    'rule2': \"Custom message\"\n  }\n}\n```\n\n```javascript\n/* Collection of objects */\n\n{\n  'field': {\n    '*': {\n      'field1': {\n        'rule1': \"Custom message\",\n        'rule2': \"Custom message\"\n      },\n      'field2': {\n        'rule1': \"Custom message\",\n        'rule2': \"Custom message\"\n      }\n    }\n  },\n  // or\n  'field.*': {\n    'field1': {\n      'rule1': \"Custom message\",\n      'rule2': \"Custom message\"\n    },\n    'field2': {\n      'rule1': \"Custom message\",\n      'rule2': \"Custom message\"\n    }\n  }\n}\n```\n\n```javascript\n{\n  'entries'{\n    '*': {\n      '*': {\n        'integer': \"Custom message\"\n      }\n    },\n  }\n  // or\n  'entries.*'{\n    '*': {\n      'integer': \"Custom message\"\n    }\n  }\n}\n```\n\n### Message for some specific items in an array\n```javascript\n/* List of values */\n\n{\n  'field': {\n    '0': {\n      'rule1': \"Custom message\",\n      'rule2': \"Custom message\"\n    },\n    '1': {\n      'rule1': \"Custom message\",\n      'rule2': \"Custom message\"\n    }\n  }\n}\n```\n\n```javascript\n/* Collection of objects */\n\n{\n  'field': {\n    '0': {\n      'field1': {\n        'rule1': \"Custom message\",\n        'rule2': \"Custom message\"\n      },\n      'field2': {\n        'rule1': \"Custom message\",\n        'rule2': \"Custom message\"\n      }\n    },\n    '1': {\n      'field1': {\n        'rule1': \"Custom message\",\n        'rule2': \"Custom message\"\n      },\n      'field2': {\n        'rule1': \"Custom message\",\n        'rule2': \"Custom message\"\n      }\n    }\n  }\n}\n```\n\n```javascript\n/* Entries */\n{\n  'entries'{\n    '0': {\n      '*': {\n        'integer': \"Custom message\"\n      }\n    },\n    '1': {\n      '*': {\n        'string': \"Custom message\"\n      }\n    }\n    // or\n    '0.*': {\n      'integer': \"Custom message\"\n    },\n    '1.*': {\n      'string': \"Custom message\"\n    }\n  }\n}\n```\n\n### Global messages\nGlobal messages replace all messages in the same or lower scope. \nLocal messages have higher priority.\n```javascript\n{\n  'rule1': \"Custom message\"\n  'rule2': \"Custom message (will not appear)\",\n\n  'field': {\n    'rule2': \"Custom message (override the global)\"\n  }\n}\n```\n\n## Default supported validations\n\nRule         |  Parameter  | Description\n-------------|-------------|------------\n**required** | N/A         | Check if the field is defined or is not a empty string.\n**integer**  | N/A         | Check if the field is a valid **integer** value\n**float**    | N/A         | Check if the field is a valid **float** value\n**number**   | N/A         | Check if the field is a valid **number** value\n**string**   | N/A         | Check if the field is a valid **string** value\n**array**    | N/A         | Check if the field is an **array**. Defining rules as `'rule': []` validates as **array** by default.\n**object**   | N/A         | Check if the field is an **object**. Defining rules as `'rule': {}` validates as **object** by default.\n**email**    | N/A         | Check if the field is a valid **email** value\n**min**      | **integer** | This validation have 2 modes. When in a **string** field, check if the length of the text is greater than *@param*. In a **numeric** field, check if the value is greater than *@param*.\n**max**      | **integer** | This validation have 2 modes. When in a **string** field, check if the text length is less than *@param*. In a **numeric** field, check if the value is less than *@param*.\n\n### Extra validations\nRule         |  Parameter  | Description\n-------------|-------------|------------\n**cpf**      | N/A         | Check if the field is a valid **cpf** (Brazilian Natural Persons Register) value. \n\n## Custom validation\nYou can implement your own validations. Validation passes when no error message is returned.\n\n```javascript\n/* Custom validation template */\n\nValidator.custom('custom_rule', (key, value, param) =\u003e {\n  if(/* condition */)\n    return /* Error message */;\n  /* Valid result */\n})\n\nValidator.build({\n  values: {\n    field: 123\n  },\n  rules: {\n    'field': \"custom_rule\"\n  }\n})\n```\n\n## Maintainer\n- [daviinacio](https://github.com/daviinacio) - **Davi Inácio** (author)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaviinacio%2Frest-payload-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaviinacio%2Frest-payload-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaviinacio%2Frest-payload-validator/lists"}