{"id":20526333,"url":"https://github.com/logicspark/csv-import-validation","last_synced_at":"2025-06-19T02:38:50.455Z","repository":{"id":179118463,"uuid":"645617284","full_name":"logicspark/csv-import-validation","owner":"logicspark","description":"CSV Validation library against user defined schema","archived":false,"fork":false,"pushed_at":"2023-10-01T14:29:10.000Z","size":565,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-17T05:44:12.072Z","etag":null,"topics":["csv","csv-files","csv-import","csv-par","csv-read","csv-validator","data-validation","data-validator","exceljs","javascript","nodejs","typescript","validation","validator"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/logicspark.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":"2023-05-26T04:00:15.000Z","updated_at":"2024-04-18T19:59:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"db4bba09-5cf6-48c0-b608-c9d3aa9fdf21","html_url":"https://github.com/logicspark/csv-import-validation","commit_stats":null,"previous_names":["logicspark/csv-import-validation"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/logicspark/csv-import-validation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicspark%2Fcsv-import-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicspark%2Fcsv-import-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicspark%2Fcsv-import-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicspark%2Fcsv-import-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/logicspark","download_url":"https://codeload.github.com/logicspark/csv-import-validation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicspark%2Fcsv-import-validation/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260674292,"owners_count":23045052,"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-import","csv-par","csv-read","csv-validator","data-validation","data-validator","exceljs","javascript","nodejs","typescript","validation","validator"],"created_at":"2024-11-15T23:13:42.584Z","updated_at":"2025-06-19T02:38:45.439Z","avatar_url":"https://github.com/logicspark.png","language":"TypeScript","readme":"\u003ca id=\"readme-top\"\u003e\u003c/a\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003eCSV Import Validation\u003c/h1\u003e\n  \n\u003c/div\u003e\n\n\u003cp align=center\u003e Validation library for CSV files against defined schema. Easy to use and customize. Developed by \u003ca href=\"https://www.logicspark.com\"\u003eLogic Spark\u003c/a\u003e team. \u003c/p\u003e\n\n\u003cp align=center\u003e CSV import validation is a Typescript library that is utilize the function to read CSV data from \u003ca href=\"https://github.com/exceljs/exceljs\"\u003eExcelJS\u003ca/\u003e.\u003c/p\u003e\n\u003cbr\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"#building_construction-built-with\"\u003eBuilt With\u003c/a\u003e - \n  \u003ca href=\"#rocket-getting-started\"\u003eGetting Started\u003c/a\u003e - \n  \u003ca href=\"#fire-usage\"\u003eUsage\u003c/a\u003e -\n  \u003ca href=\"#books-license\"\u003eLicense\u003c/a\u003e -\n  \u003ca href=\"#pray-acknowledgement\"\u003eAcknowledgement\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n## :building_construction: Built With\n\nHere is a list of frameworks/libraries used to develop CSV Import Validation\n\n- [![Typescript][typescript]][typescript-url]\n- ![javascript][javascript]\n- [![Node][node.js]][node-url]\n- [![exceljs][exceljs.js]][exceljs-url]\n- [![Jest][Jest]][jest-url]\n\n## :rocket: Getting Started\n\nCSV Import Validation library checks data validation for CSV files against defined schema and returns data and validation messages as an object. In this guide, you will learn what is required before using the library and how to install it quickly. Let's get started!\n\n### Prerequisite\n\nBefore installing the CSV Import Validation library, please install the most recent `Node.js` version\n\n- npm\n\n```sh\n  npm install npm@latest -g\n```\n\n_Support Node.js 14.21.0 and above_\n\n### Installation\n\nSince the example is based on npm, you can use npm to install CSV Import Validation. You can also install via yarn or pnpm.\n\nnpm install\n\n```sh\nnpm install csv-import-validation\n```\n\n#### Other options\n\nOr yarn\n\n```sh\nyarn add csv-import-validation\n```\n\nOr pnpm\n\n```sh\npnpm install csv-import-validation\n```\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\n\n## :fire: Usage\n\nThere are 2 main features in the library. One reads CSV and returns an array while another reads CSV and returns as objects with validation messages. For each feature, it can be read via a file path or buffer. The functions are independent and do not need to be called in sequence.\n\nTo use the library, you will need to `import` to your targeted file\n\n```js\nimport { CsvUtilities } from \"csv-import-validation\";\n```\n\n### Functions that read CSV and return an array\n\nThere are two functions, namely:\n\n- function readFileMapArray: read CSV by specifying a file path to the CSV file\n- function readBufferMapArray: read CSV from Buffer\n\n```js\nconst filePath = \"files/your-csv-file-name.csv\";\nconst reading = readCsvFileMapArray(filePath);\n```\n\n```js\n  const reading = readBufferMapArray(ฺbuffer);\n```\n\nEach function has the same output as below:\n\n```js\n[\n  [\n    \"Order ID\",\n    \"Product Name\",\n    \"Customer Name\",\n    \"Quantity\",\n    \"Price\",\n    \"Discount\",\n    \"Total\",\n    \"Region\",\n    \"Category\",\n    \"Discount Rate\",\n  ],\n  [\n    \"1\",\n    \"Eldon Base for stackable storage shelf, platinum\",\n    \"Muhammed MacIntyre\",\n    \"3\",\n    \"-213.25\",\n    \"38.94\",\n    \"35\",\n    \"Nunavut\",\n    \"Storage \u0026 Organization\",\n    \"0.8\",\n  ],\n];\n```\n\n### Functions that read CSV and return objects and validations\n\nThere are two functions, namely:\n\n- readFileValidator: read CSV by specifying a file path to the CSV file and validate data\n- readBufferValidator: read CSV from Buffer and validate data.\n  The validation can be applied to the header name and data type of each column.\n\n_If you import with validation, data will only be imported if there is no validation message._\n\n```js\nconst csvConfig: ValidationConfig = [\n  {\n    headerName: \"Order ID\",\n    keyName: \"orderID\",\n    type: \"number\",\n    required: true,\n    unique: true,\n  },\n  { headerName: \"Product Name\", keyName: \"productName\", type: \"string\" },\n  { headerName: \"Customer Name\", keyName: \"customerName\", type: \"string\" },\n  { headerName: \"Quantity\", keyName: \"quantity\", type: \"number\" },\n  { headerName: \"Price\", keyName: \"price\", type: \"number\" },\n  { headerName: \"Discount\", keyName: \"discount\", type: \"number\" },\n  { headerName: \"Total\", keyName: \"total\", type: \"string\" },\n  { headerName: \"Region\", keyName: \"region\", type: \"string\" },\n  { headerName: \"Category\", keyName: \"category\", type: \"string\" },\n  { headerName: \"Discount Rate\", keyName: \"discountRate\", type: \"number\" },\n];\n\nconst filePath = \"files/your-csv-file-name.csv\";\nconst data = await csvUtilities.readFileValidator(filePath, csvConfig);\n```\n\n```js\nconst csvConfig: ValidationConfig = [\n  {\n    headerName: \"Order ID\",\n    keyName: \"orderID\",\n    type: \"number\",\n    required: true,\n    unique: true,\n  },\n  { headerName: \"Product Name\", keyName: \"productName\", type: \"string\" },\n  { headerName: \"Customer Name\", keyName: \"customerName\", type: \"string\" },\n  { headerName: \"Quantity\", keyName: \"quantity\", type: \"number\" },\n  { headerName: \"Price\", keyName: \"price\", type: \"number\" },\n  { headerName: \"Discount\", keyName: \"discount\", type: \"number\" },\n  { headerName: \"Total\", keyName: \"total\", type: \"string\" },\n  { headerName: \"Region\", keyName: \"region\", type: \"string\" },\n  { headerName: \"Category\", keyName: \"category\", type: \"string\" },\n  { headerName: \"Discount Rate\", keyName: \"discountRate\", type: \"number\" },\n];\nconst data = await csvUtilities.readBufferValidator(buffer, csvConfig);\n```\n\n#### Configuration Parameters\n\n| Parameter    | Description                                                                                    |\n| ------------ | ---------------------------------------------------------------------------------------------- |\n| `headerName` | Specify header name of each column to validate with a message                                  |\n| `keyName`    | Specify key to map data of the corresponding column                                            |\n| `type`       | Specify data type of each column (`number`, `string`,`boolean`)                                |\n| `required`   | Specify if a column value is needed (`boolean`)                                                |\n| `unique`     | Specify that a column header title cannot duplicate with another column header (`boolean`)     |\n\nEach function has the same output. If there is no validation message, the output will return objects of data imported.\n\n```js\n{\n  \"data\": [\n   {\n      orderID: 1,\n      productName: 'Eldon Base for stackable storage shelf, platinum',\n      customerName: 'Muhammed MacIntyre',\n      quantity: 3,\n      price: -213.25,\n      discount: 38.94,\n      total: '35',\n      region: 'Nunavut',\n      category: 'Storage \u0026 Organization',\n      discountRate: 0.8\n    },\n    {\n      orderID: 2,\n      productName: '1.7 Cubic Foot Compact \"Cube\" Office Refrigerators',\n      customerName: 'Barry French',\n      quantity: 293,\n      price: 457.81,\n      discount: 208.16,\n      total: '68.02',\n      region: 'Nunavut',\n      category: 'Appliances',\n      discountRate: 0.58\n    },\n  ]\n}\n```\n\nIf there is validation, the data will not be imported and the output will return locations that need to be fixed before importing again.\n\n```js\n{\n  \"invalidData\": [\n    {\n      \"rowIndex\": 1,\n      \"columnIndex\": \"A\",\n      \"message\": \"Order ID's type is number.\"\n    },\n    {\n      \"rowIndex\": 1,\n      \"columnIndex\": \"D\",\n      \"message\": \"Quantity's type is number.\"\n    },\n    {\n      rowIndex: 6,\n      columnIndex: 'A',\n      message: \"Order ID's is required.\"\n    },\n    {\n      \"rowIndex\": 7,\n      \"columnIndex\": \"A\",\n      \"message\": \"Order ID's type is number.\"\n    },\n    {\n      rowIndex: 9,\n      columnIndex: 'A',\n      message: 'Order ID must be unique.'\n    }\n  ]\n}\n```\n\nFor more details, please see our [demo](https://github.com/logicspark/csv-import-validation/tree/main/demo) folder. There are demos for both JavaScript and TypeScript. In the [example-files](https://github.com/logicspark/csv-import-validation/tree/main/example-files) folder, we provide csv files with and without header for your ease of use.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\n\n## :books: License\n\nDistributed under the MIT license. See `LICENSE.txt` for more information.\n\n[ExcelJS](https://github.com/exceljs/exceljs) is licensed under the MIT license.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\n\n## :pray: Acknowledgement\n\n- [ExcelJS](https://github.com/exceljs/exceljs)\n- [Img Shields](https://shields.io)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\n\n[javascript]: https://img.shields.io/badge/javascript-F0DB4F?style=for-the-badge\u0026logo=javascript\u0026logoColor=323330\n[TypeScript]: https://img.shields.io/badge/typescript-007ACC?style=for-the-badge\u0026logo=typescript\u0026logoColor=white\n[typescript-url]: https://www.typescriptlang.org/\n[node.js]: https://img.shields.io/badge/Node.js-43853D?style=for-the-badge\u0026logo=node.js\u0026logoColor=white\n[node-url]: https://nodejs.org/en\n[exceljs.js]: https://img.shields.io/badge/exceljs-red\n[exceljs-url]: https://github.com/exceljs/exceljs\n[Jest]: https://img.shields.io/badge/jest-C32C28?style=for-the-badge\u0026logo=jest\u0026logoColor=white\n[jest-url]: https://jestjs.io/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogicspark%2Fcsv-import-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flogicspark%2Fcsv-import-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogicspark%2Fcsv-import-validation/lists"}