{"id":26243996,"url":"https://github.com/shystruk/csv-file-validator","last_synced_at":"2025-05-15T23:03:28.651Z","repository":{"id":37818749,"uuid":"124094486","full_name":"shystruk/csv-file-validator","owner":"shystruk","description":"🔧🔦 Validation of CSV file against user defined schema (returns back object with data and invalid messages)","archived":false,"fork":false,"pushed_at":"2025-02-17T08:51:21.000Z","size":1320,"stargazers_count":94,"open_issues_count":9,"forks_count":42,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-19T02:35:32.556Z","etag":null,"topics":["csv","csv-files","csv-parser","csv-reader","javascript","validator"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/csv-file-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/shystruk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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,"zenodo":null}},"created_at":"2018-03-06T14:59:38.000Z","updated_at":"2025-04-01T03:13:03.000Z","dependencies_parsed_at":"2024-06-18T18:14:41.395Z","dependency_job_id":"d16cdd2c-2895-4db6-8744-4a6f1d5f7350","html_url":"https://github.com/shystruk/csv-file-validator","commit_stats":{"total_commits":114,"total_committers":12,"mean_commits":9.5,"dds":0.6491228070175439,"last_synced_commit":"0f6c355e3617c486687dc2429baf4f3c5d31309e"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shystruk%2Fcsv-file-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shystruk%2Fcsv-file-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shystruk%2Fcsv-file-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shystruk%2Fcsv-file-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shystruk","download_url":"https://codeload.github.com/shystruk/csv-file-validator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254315012,"owners_count":22050356,"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":["csv","csv-files","csv-parser","csv-reader","javascript","validator"],"created_at":"2025-03-13T10:38:39.476Z","updated_at":"2025-05-15T23:03:28.632Z","avatar_url":"https://github.com/shystruk.png","language":"JavaScript","readme":"# CSV File Validator [![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?hashtags=javascript\u0026original_referer=https%3A%2F%2Fpublish.twitter.com%2F\u0026ref_src=twsrc%5Etfw\u0026text=Validation%20of%20CSV%20file%20against%20user%20defined%20schema%20(returns%20back%20object%20with%20data%20and%20invalid%20messages)\u0026tw_p=tweetbutton\u0026url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fcsv-file-validator\u0026via=shystrukk) #\n[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)\n[![codecov](https://codecov.io/gh/shystruk/csv-file-validator/branch/master/graph/badge.svg)](https://codecov.io/gh/shystruk/csv-file-validator)\n[![Build Status](https://travis-ci.org/shystruk/csv-file-validator.svg?branch=master)](https://travis-ci.org/shystruk/csv-file-validator)\n[![Known Vulnerabilities](https://snyk.io/test/github/shystruk/csv-file-validator/badge.svg?targetFile=package.json)](https://snyk.io/test/github/shystruk/csv-file-validator?targetFile=package.json)\n[![npm version](https://badge.fury.io/js/csv-file-validator.svg)](https://badge.fury.io/js/csv-file-validator)\n\nValidation of CSV file against user defined schema (returns back object with data and invalid messages)\n\n## Getting csv-file-validator ##\n\n#### npm\n`npm install --save csv-file-validator`\n\n#### yarn\n`yarn add csv-file-validator --save`\n\n## Example ##\n```javascript\nimport CSVFileValidator from 'csv-file-validator'\n\nCSVFileValidator(file, config)\n    .then(csvData =\u003e {\n        csvData.data // Array of objects from file\n        csvData.inValidData // Array of error messages\n    })\n    .catch(err =\u003e {})\n```\n\nPlease see **Demo** for more details **/demo/index.html**\n\n![](demo/demo.png)\n\n## API ##\n### CSVFileValidator(file, config) ###\nreturns the Promise\n\n## file ##\nType: `File` \u003cbr\u003e\n\n.csv file\n\n## config ##\nType: `Object` \u003cbr\u003e\n\nConfig object should contain:\u003cbr\u003e\n**headers** - Type: `Array`, row header (title) objects\u003cbr\u003e\n**isHeaderNameOptional** - Type: `Boolean`, skip headers name if it is empty\u003cbr\u003e\n**isColumnIndexAlphabetic** - Type: `Boolean`, convert numeric column index to alphabetic letter\u003cbr\u003e\n**parserConfig** - Type: `Object`, optional, [papaparse](https://www.papaparse.com/docs#config) options.\nDefault options, which can't be overridden: **skipEmptyLines**, **complete** and **error**\n\n```javascript\nconst config = {\n    headers: [], // required\n    isHeaderNameOptional: false, // default (optional)\n    isColumnIndexAlphabetic: false // default (optional)\n}\n```\n\n### name\nType: `String` \u003cbr\u003e\nname of the row header (title)\n\n### inputName\nType: `String` \u003cbr\u003e\nkey name which will be return with value in a column\n\n### optional\nType: `Boolean` \u003cbr\u003e\n\nMakes column optional. If true column value will be return\n\n### headerError\nType: `Function` \u003cbr\u003e\n\nIf a header name is omitted or is not the same as in config *name* headerError function will be called with arguments\n**headerValue, headerName, rowNumber, columnNumber**\n\n### required\nType: `Boolean` \u003cbr\u003e\n\nIf required is true then a column value will be checked if it is not empty\n\n### requiredError\nType: `Function` \u003cbr\u003e\n\nIf value is empty requiredError function will be called with arguments\n**headerName, rowNumber, columnNumber**\n\n### unique\nType: `Boolean` \u003cbr\u003e\n\nIf it is true all header (title) column values will be checked for uniqueness\n\n### uniqueError\nType: `Function` \u003cbr\u003e\n\nIf one of the header value is not unique uniqueError function will be called with argument **headerName, rowNumber**\n\n### validate\nType: `Function` \u003cbr\u003e\n\nValidate column value. As an argument column value will be passed\nFor e.g.\n```javascript\n/**\n * @param {String} email\n * @return {Boolean}\n */\nfunction(email) {\n    return isEmailValid(email);\n}\n```\n\n### validateError\nType: `Function` \u003cbr\u003e\n\nIf validate returns false validateError function will be called with arguments **headerName, rowNumber, columnNumber**\n\n\n### dependentValidate\nType: `Function` \u003cbr\u003e\n\nValidate column value that depends on other values in other columns.\nAs an argument column value and row will be passed.\nFor e.g.\n```javascript\n/**\n * @param {String} email\n * @param {Array\u003cstring\u003e} row\n * @return {Boolean}\n */\nfunction(email, row) {\n    return isEmailDependsOnSomeDataInRow(email, row);\n}\n```\n\n### dependentValidateError\nType: `Function` \u003cbr\u003e\n\nIf dependentValidate returns false dependentValidateError function will be called with arguments **headerName, rowNumber, columnNumber**\n\n### isArray\nType: `Boolean` \u003cbr\u003e\n\nIf column contains list of values separated by comma in return object it will be as an array\n\n#### Config example ####\n```javascript\nconst config = {\n    headers: [\n        {\n            name: 'First Name',\n            inputName: 'firstName',\n            required: true,\n            requiredError: function (headerName, rowNumber, columnNumber) {\n                return `${headerName} is required in the ${rowNumber} row / ${columnNumber} column`\n            }\n        },\n        {\n            name: 'Last Name',\n            inputName: 'lastName',\n            required: false\n        },\n        {\n            name: 'Email',\n            inputName: 'email',\n            unique: true,\n            uniqueError: function (headerName) {\n                return `${headerName} is not unique`\n            },\n            validate: function(email) {\n                return isEmailValid(email)\n            },\n            validateError: function (headerName, rowNumber, columnNumber) {\n                return `${headerName} is not valid in the ${rowNumber} row / ${columnNumber} column`\n            }\n        },\n        {\n            name: 'Roles',\n            inputName: 'roles',\n            isArray: true\n        },\n        {\n            name: 'Country',\n            inputName: 'country',\n            optional: true,\n            dependentValidate: function(email, row) {\n                return isEmailDependsOnSomeDataInRow(email, row);\n            }\n        }\n    ]\n}\n```\n\n## Contributing\n\nAny contributions you make **are greatly appreciated**.\n\nPlease read the [Contributions Guidelines](CONTRIBUTING.md) before submitting a PR.\n\n## License\n\nMIT © [Vasyl Stokolosa](https://about.me/shystruk)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshystruk%2Fcsv-file-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshystruk%2Fcsv-file-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshystruk%2Fcsv-file-validator/lists"}