{"id":22491772,"url":"https://github.com/travishorn/csval","last_synced_at":"2025-04-09T20:04:33.763Z","repository":{"id":41512138,"uuid":"208143964","full_name":"travishorn/csval","owner":"travishorn","description":"Check CSV files against a set of validation rules.","archived":false,"fork":false,"pushed_at":"2025-02-21T09:48:59.000Z","size":815,"stargazers_count":34,"open_issues_count":2,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T20:04:28.503Z","etag":null,"topics":["cli","csv","data","json-schema","parser","validation"],"latest_commit_sha":null,"homepage":"","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/travishorn.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-12T20:49:28.000Z","updated_at":"2025-02-21T09:49:02.000Z","dependencies_parsed_at":"2024-06-20T22:09:42.403Z","dependency_job_id":null,"html_url":"https://github.com/travishorn/csval","commit_stats":{"total_commits":97,"total_committers":3,"mean_commits":"32.333333333333336","dds":"0.22680412371134018","last_synced_commit":"3599940052976c759f86240b2e670a59eed8f155"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travishorn%2Fcsval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travishorn%2Fcsval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travishorn%2Fcsval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travishorn%2Fcsval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/travishorn","download_url":"https://codeload.github.com/travishorn/csval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103865,"owners_count":21048245,"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":["cli","csv","data","json-schema","parser","validation"],"created_at":"2024-12-06T18:10:14.661Z","updated_at":"2025-04-09T20:04:33.732Z","avatar_url":"https://github.com/travishorn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# csval\n\nCheck CSV files against a set of validation rules.\n\n## Validation Checks\n\n- CSV file is actually valid itself and can be parsed\n- Presence of required fields\n- Mismatching types. For example, number vs string\n- Minimum and maxiumum lengths\n- Number ranges\n- Values from a fixed set of options\n- Regex pattern matching\n- Much more. Check the [JSON Schema\n  reference](https://ajv.js.org/json-schema.html) for more information\n\n## CLI Installation\n\n```\nnpm install --global csval\n```\n\n## Usage\n\nRun `csval` and give a CSV file as the first argument\n\n```\ncsval mydata.csv\n```\n\nSince no rules were specified above, the file is only checked to make sure it\ncan be parsed correctly. As long as it's a valid CSV file, it will pass\nvalidation. The CLI will show errors if they exist. Otherwise, it will display\na success message.\n\nPass in a rules file to validate against the rules\n\n```\ncsval mydata.csv myrules.json\n```\n\nAgain, the CLI will show parsing errors if they exist. When a rules file is\nspecified as it is above, the CLI will also display any validation errors.\nOtherwise, it will display a success message.\n\n### Rules file\n\nRules files should follow the [JSON Schema](https://ajv.js.org/json-schema.html)\nformat. It describes what you should expect in each row. Here's an example.\n\n```json\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"salary\": {\n      \"type\": \"number\"\n    }\n  }\n}\n```\n\nNote: The `\"type\": \"object\"` line above is implied and can be left out if\ndesired.\n\nThe rules above say that the \"salary\" field on each row must be a number. This\nCSV file would pass.\n\n```\nname,salary\nJohn,100000\nJane,150000\n```\n\n```\nThe CSV file meets all validation checks.\n```\n\nThis CSV file would fail.\n\n```\nname,salary\nJohn,100000\nJane,idk\n```\n\n```\nRow 3: 'salary' must be number\n```\n\nHere's another example rules file.\n\n```json\n{\n  \"properties\": {\n    \"age\": {\n      \"type\": \"number\",\n      \"minimum\": 0\n    }\n  }\n}\n```\n\nThis CSV file would pass.\n\n```\nname,age\nJohn,30\nJane,50\n```\n\nBut this one would fail.\n\n```\nname,age\nJohn,30\nJane,-10\n```\n\nYou can require certain fields, as well. Consider this rules file.\n\n```json\n{\n  \"properties\": {\n    \"age\": {\n      \"type\": \"number\"\n    }\n  },\n  \"required\": [\"age\"]\n}\n```\n\nThis CSV file would pass.\n\n```\nname,age,salary\nJohn,30,100000\nJane,50,150000\n```\n\nThis one would fail.\n\n```\nname,salary\nJohn,100000\nJane,150000\n```\n\nThere are many other possible rules. See the [JSON\nSchema](https://ajv.js.org/json-schema.html) for more information.\n\n## Programmatic API\n\nInstall the library\n\n```\nnpm install csval\n```\n\nUse it in your project like so\n\n```javascript\nimport { parseCsv, validate } from \"csval\";\n\nconst main = async () =\u003e {\n  const csvString= \"name,age\\nJohn,30\";\n\n  const rules = {\n    properties: {\n      name: {\n        type: \"string\"\n      }\n    }\n  };\n\n  const parsed = await parseCsv(csvString);\n  const valid = await validate(parsed, rules);\n\n  // validate will either throw an error or valid will be true\n};\n\nmain();\n```\n\nYou can also read CSV data and rules from files.\n\n```javascript\nimport { readCsv, readRules, parseCsv, validate } from \"csval\";\n\nconst csvString = await readCsv(\"path/to/file.csv\");\nconst rules = await readRules(\"path/to/rules.json\");\nconst parsed = await parseCsv(csvString);\nconst valid = await validate(parsed, rules);\n\n// validate will either throw an error or valid will be true\n```\n\n## Develop\n\nClone the repository\n\n```\ngit clone https://github.com/travishorn/csval.git\n```\n\nChange into the directory\n\n```\ncd csval\n```\n\nInstall dependencies\n\n```\nnpm install\n```\n\n## Tests\n\nRun tests via Mocha\n\n```\nnpm run test\n```\n\n## Lint\n\nLint all JavaScript files via ESLint and Prettier\n\n```\nnpm run lint\n```\n\nAutomatically fix linting problems if possible\n\n```\nnpm run lint:fix\n```\n\n## License\n\nThe MIT License\n\nCopyright 2023 Travis Horn\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftravishorn%2Fcsval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftravishorn%2Fcsval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftravishorn%2Fcsval/lists"}