{"id":22394182,"url":"https://github.com/atlantis-software/csv.io","last_synced_at":"2025-09-16T16:43:07.470Z","repository":{"id":83024034,"uuid":"119673582","full_name":"Atlantis-Software/csv.io","owner":"Atlantis-Software","description":"csv import / export ","archived":false,"fork":false,"pushed_at":"2020-05-22T13:47:54.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T04:25:39.147Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Atlantis-Software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-01-31T10:39:59.000Z","updated_at":"2020-05-22T13:47:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"41975833-f06a-494e-8deb-7ba47815faf3","html_url":"https://github.com/Atlantis-Software/csv.io","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/Atlantis-Software%2Fcsv.io","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atlantis-Software%2Fcsv.io/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atlantis-Software%2Fcsv.io/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atlantis-Software%2Fcsv.io/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Atlantis-Software","download_url":"https://codeload.github.com/Atlantis-Software/csv.io/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245749796,"owners_count":20666084,"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-05T05:09:19.915Z","updated_at":"2025-09-16T16:43:02.403Z","avatar_url":"https://github.com/Atlantis-Software.png","language":"JavaScript","readme":"# csv.io\n\n[![npm version](https://badge.fury.io/js/csv.io.svg)](https://www.npmjs.com/csv.io)\n[![Build Status](https://travis-ci.org/Atlantis-Software/csv.io.svg?branch=master)](https://travis-ci.org/Atlantis-Software/csv.io)\n[![Coverage Status](https://coveralls.io/repos/github/Atlantis-Software/csv.io/badge.svg?branch=master)](https://coveralls.io/github/Atlantis-Software/csv.io?branch=master)\n[![NSP Status](https://nodesecurity.io/orgs/atlantis/projects/3c799d7b-23a9-4f48-a858-4259fb351d1c/badge)](https://nodesecurity.io/orgs/atlantis/projects/3c799d7b-23a9-4f48-a858-4259fb351d1c)\n[![Dependencies Status](https://david-dm.org/Atlantis-Software/csv.io.svg)](https://david-dm.org/Atlantis-Software/csv.io)\n\ncsv import / export\n\nCsv.io is a node module that provide functions simplifying the import/export of csv. It uses streams and handle backpressure, wich provide good scalability. You can also provide your own formatters, to get exactly the data you want.\n\n## Installation\nJust do an npm install in your project folder :\n```\nnpm install csv.io\n```\n\n## Usage\nCsv.io is composed of two instantiable objects : an importer and an exporter. They don't take the same options, and must be instantiated separately.\n\nThe importer take a csv string/buffer/stream and convert it to json object. The exporter do the opposite.\n\nBut first let's require everything you need :\n```javascript\nvar csvIO = require('csv.io');\n\nvar importer = csvIO.importer;\nvar exporter = csvIO.exporter;\n```\nNow for the specific usage of each object :\n\n### Importer\nThe initialization of the importer require an object containing some options. Let's take an example :\n\n```javascript\nvar options = {\n  columns: [\n    { name: 'column1', type: 'string' },\n    { name: 'column2', type: 'number' },\n    { name: 'column3', type: 'string', nullable: true },\n    { name: 'column4', type: 'boolean' },\n    { name: 'column5', type: 'date' },\n    { name: 'column6', type: 'doNothing' },\n    { name: 'column7', formatter: myCustomFormatter } // this custom formatter is specific to this column\n  ],\n  encoding: 'windows-1252', // can also be 'ascii', and default to utf-8\n  delimiter: '|', // default to ';',\n  rowDelimiter: '\\r\\n', // default to '\\n'\n  formatters: {\n    date: anotherCustomFormatter  // replace the date formatter with a custom one\n  }\n};\n```\nThe only option really required is `columns`, wich is an array of objects with a `name`, and either a `type` (that is basically a standard formatter for `string`, `number`, `boolean`, or `date`. `doNothing` is a special formatter that just return the data without formatting it) or a `formatter` property where you can inject your own formatter.\n\nYou can also define a `nullable` property. If a field is nullable and contain null or 'null', it will be returned as null, if it's not nullable it will be returned as an empty value. Default to false.\n\nA custom fomatter is a function. So if we take the previous example, `myCustomFormatter` could look like this :\n\n```javascript\nvar myCustomFormatter = function(column, value) {\n  if (isNull(val)) \u0026\u0026 column.nullable) {\n    return null;\n  }\n  if (isEmpty(val) || isNull(val)) {\n    return void 0;\n  }\n  return 'this value -\u003e ' + val + ' \u003c- is now modified';\n}\n```\n\n`column` is basically the column you passed in the options (so you can check if it's nullable, or even pass other custom metadata), `value` is the value parsed from the csv.\n\nOnce everything is set, you can initialize the importer :\n```javascript\nvar importCsv = new importer(options);\n```\n\nYou can then get your output stream with the `getOutput` function. If given a function as parameter, it will be called on each line returned.\n\n```javascript\n  var outputStream = importCsv.getOutput(function(line, cb) {\n    insertIntoDb(line); // Or whatever you want to do with your new shiny object\n    return cb(); // Don't forget to call the callback\n  });\n```\n\nYou can then start feeding data to your importer, either by writing into your stream...\n```javascript\nimportCsv.write(someBuffer);\nimportCsv.write(someOtherBuffer);\nimportCsv.write(someString);\n```\n\n... or by piping a stream :\n\n```javascript\nsomeInputStream.pipe(importCsv);\n```\n\nYou can also pipe your output into a stream :\n\n```javascript\noutput.pipe(anotherStream);\n```\n\nYou can listen for `error` and `finish` event on your output stream (the output stream being either the one returned by `getOutput` or the last stream you piped it into). **DO NOT** listen for the `data` event or you will break all backpressure handling and will flood your memory !\n\n```javascript\nanotherStream // since earlier we piped output to anotherStream, we listen to the latter\n.on('error', function(err) {\n  // Handle your errors here\n})\n.on('finish', function() {\n  // you can has cheezburger\n});\n```\n\nIf you didn't pipe a stream as input and only used `write`, once you have written everything you wanted, you must signal\nthat there is no more input with the `end` function :\n\n```javascript\nimportCsv.end();\n```\n\n### Exporter\nThe exporter is really similar in usage to the importer, but its options are slightly differents :\n\n```javascript\nvar options = {\n  columns: [\n    { name: 'column1', type: 'string' },\n    { name: 'column2', type: 'number' },\n    { name: 'column3', type: 'string', nullable: true },\n    { name: 'column4', type: 'boolean' },\n    { name: 'column5', type: 'date' },\n    { name: 'column6', type: 'doNothing' },\n    { name: 'column7', formatter: myCustomFormatter } // this custom formatter is specific to this column\n  ],\n  delimiter: '|', // default to ';',\n  rowDelimiter: '\\r\\n', // default to '\\n'\n  textDelimiter: \"'\", // default to \", you can pass an empty string if you don't want a delimiter\n  showHeaders: true, // First line returned will be the columns names, default to false\n  displayEmptyValue: 'EMPTY', // Value displayed when a field is empty, default to empty string\n  formatters: {\n    date: anotherCustomFormatter  // replace the date formatter with a custom one\n  }\n};\n```\n\nOnce again, only `columns` is required.\nLike the importer, you can now instantiate the exporter :\n\n```javascript\nexportCsv = new exporter(options);\n```\n\nOnce this is done, the exporter behave exactly like the importer : an input stream, an output stream and an optional function called on each line.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatlantis-software%2Fcsv.io","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatlantis-software%2Fcsv.io","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatlantis-software%2Fcsv.io/lists"}