{"id":22202148,"url":"https://github.com/rumkin/validation-report","last_synced_at":"2025-03-25T00:59:19.792Z","repository":{"id":57390363,"uuid":"75561548","full_name":"rumkin/validation-report","owner":"rumkin","description":"Unified validation report interface","archived":false,"fork":false,"pushed_at":"2017-07-12T01:11:07.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-07T09:04:57.278Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rumkin.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","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":"2016-12-04T20:10:33.000Z","updated_at":"2016-12-04T21:09:28.000Z","dependencies_parsed_at":"2022-09-19T04:12:28.626Z","dependency_job_id":null,"html_url":"https://github.com/rumkin/validation-report","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fvalidation-report","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fvalidation-report/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fvalidation-report/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fvalidation-report/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rumkin","download_url":"https://codeload.github.com/rumkin/validation-report/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245377988,"owners_count":20605377,"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":[],"created_at":"2024-12-02T16:12:34.489Z","updated_at":"2025-03-25T00:59:19.766Z","avatar_url":"https://github.com/rumkin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Validation Report\n\nUnified validation report interface. It specifies interface for the validation\nissues reporting and issues interface. This \"low level\" library is for\ncreating validators also it could be used with manual validation.\n\n![Build](https://img.shields.io/travis/rumkin/validation-report.svg)\n\n---\n\n## Installation\n\nInstall via npm:\n```bash\nnpm i validation-report\n```\n\n## Usage\n\nValidation report is a collection of objects which contains validation result\ndata (issues). Each issue has `path`, `rule` and `details` properties.\n\nExample of issues:\n\n```javascript\n{\n    path: ['images', 0, 'title'],\n    rule: 'required',\n    details: {},\n}\n\n{\n    path: ['user', 'age'],\n    rule: 'min',\n    details: {should: 18, is: 16},\n}\n\n{\n    path: ['file.js'],\n    rule: 'syntax',\n    details: {line: 0, pos: 0, lang: 'javascript', is: '%'},\n}\n```\n\nSuch objects are very simple to send, process or stringify.\n\n### Path: string[]\n\nPath is array to allow any characters (including dots, slashes or other separators) as property name.\n\n### Rule: string\n\nValidation rule code unique across your application.\n\n### Details: object\n\nCustom data object representing error data.\n\n## Example\n\nLet create simple one function number validator:\n\n```javascript\nconst Report = require('validation-report');\n\nfunction checkNumber(value) {\n    const report = new Report();\n\n    if (typeof value !== 'number') {\n        report.addIssue({\n            rule: 'type',\n            details: {\n                should: 'number',\n                is: typeof value,\n            },\n        });\n    }\n\n    return report;\n}\n\nconst report = checkNumber(null);\n\nif (report.hasIssues()) {\n    console.log('Looks like it is not a Number');\n    const issue = report.findIssue(); // =\u003e {path: [], issue: 'type', details: {should: 'number', is: 'object'}}\n}\n\n```\n\n## Example for Express\n\nCreate and use report without validator in express:\n\n```javascript\nconst Report = require('validation-report');\nconst express = require('express');\n\nexpress()\n    .use((req, res, next) =\u003e {\n        let report = new Report({\n            value: req.query,\n        });\n\n        if ('id' in req.query === false) {\n            report.addIssue('id', 'exists');\n        }\n        else if (req.query.id.length != 24) {\n            report.addIssue('id', 'length', {\n                accept: 32,\n                result: req.query.id.length,\n            });\n        }\n\n        if (! report.isValid()) {\n            res.status(400)\n            .json({\n                code: 'validation',\n                error: 'Request validation error',\n                details: {issues: report},\n            });\n        }\n        else {\n            // do something...\n            res.end();\n        }\n    })\n```\n\n## API\n\n### constructor({issues:ReportIssue[], value: * }) -\u003e Report\n\nConstructor accepts an object as an only argument. This object could\nprovides validating `value` and array of `issues`.\n\n### setIssues(issues:ReportIssue[]) -\u003e Report\n\nAdd a list of issues.\n\n### getIssues() -\u003e ReportIssue[]\n\nReturn an array of issues.\n\n### addIssue(issue:ReportIssue) -\u003e Report\n\nAdd an issue.\n\n### hasIssue(path:string|string[]) -\u003e Boolean\n\nCheck is issue exists by it's path. If path is a string separate it with '.'.\n\n### findIssue(path:function(reportIssue) -\u003e Bool|string|string[], [rule]) -\u003e ReportIssue\n\nSearch issue with function or by path or by path and rule. Returns\nReportIssue or undefined if issue not found.\n\n### isValid() -\u003e Boolean\n\n**DEPRECATED** since version 1.5.0 use Report.hasIssues.\n\nCheck if report contains no issues.\n\n### hasIssues() -\u003e Boolean\n\nCheck if report contains has issues.\n\n### toJSON() -\u003e ReportIssue[]\n\nReturn array of report issues.\n\n### License\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumkin%2Fvalidation-report","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frumkin%2Fvalidation-report","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumkin%2Fvalidation-report/lists"}