{"id":15673178,"url":"https://github.com/jonschlinkert/parse-csv","last_synced_at":"2025-05-06T22:13:28.280Z","repository":{"id":57319284,"uuid":"26972738","full_name":"jonschlinkert/parse-csv","owner":"jonschlinkert","description":"CSV parser for node.js","archived":false,"fork":false,"pushed_at":"2019-03-11T18:23:48.000Z","size":21,"stargazers_count":15,"open_issues_count":8,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-06T22:13:17.064Z","etag":null,"topics":["csv","parse","parser"],"latest_commit_sha":null,"homepage":null,"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/jonschlinkert.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}},"created_at":"2014-11-21T18:35:28.000Z","updated_at":"2021-05-15T15:46:20.000Z","dependencies_parsed_at":"2022-08-25T22:41:16.416Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/parse-csv","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/jonschlinkert%2Fparse-csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fparse-csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fparse-csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fparse-csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/parse-csv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776600,"owners_count":21802469,"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","parse","parser"],"created_at":"2024-10-03T15:38:08.377Z","updated_at":"2025-05-06T22:13:27.716Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parse-csv [![NPM version](https://img.shields.io/npm/v/parse-csv.svg?style=flat)](https://www.npmjs.com/package/parse-csv) [![NPM downloads](https://img.shields.io/npm/dm/parse-csv.svg?style=flat)](https://npmjs.org/package/parse-csv) [![Build Status](https://img.shields.io/travis/jonschlinkert/parse-csv.svg?style=flat)](https://travis-ci.org/jonschlinkert/parse-csv)\n\nCSV parser for node.js.\n\n## TOC\n\n- [Install](#install)\n- [Usage](#usage)\n- [API](#api)\n  * [Available renderers](#available-renderers)\n- [Options](#options)\n  * [Parser options](#parser-options)\n  * [Renderer options](#renderer-options)\n- [Related projects](#related-projects)\n- [Contributing](#contributing)\n- [Building docs](#building-docs)\n- [Running tests](#running-tests)\n- [Author](#author)\n- [License](#license)\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install parse-csv --save\n```\n\nBased on [mr-data-converter](https://github.com/shancarter/mr-data-converter) by [@shancarter](https://github.com/shancarter). Copyright (c) 2011 Shan Carter.\n\n## Usage\n\n```js\nvar csv = require('parse-csv');\n\nvar str = [\n  'id,fruit,vegetable',\n  '1,apple,carrot',\n  '2,orange,corn',\n  '3,banana,potato'\n].join('\\n');\n\nvar obj = csv.toJSON(str, {headers: {included: true}});\nconsole.log(obj);\n```\n\n## API\n\n### [csv](index.js#L45)\n\nParse a string of CSV to a datagrid and render it using the specified [renderer](#renderer). The `.json` renderer is used by default.\n\n**Params**\n\n* `method` **{String}**: The name of the renderer method to use, or a string of CSV. If CSV, the `.json` method will be used.\n* `str` **{String|Object}**: String of CSV or options.\n* `options` **{Object}**\n* `returns` **{String}**\n\n**Example**\n\n```js\nvar str = `\nid,fruit,vegetable\n1,apple,carrot\n2,orange,corn\n3,banana,potato`;\n\nvar res = csv(str, {headers: {included: true}});\nconsole.log(res);\n// results in:\n// [{\"id\":\"1\",\"fruit\":\"apple\",\"vegetable\":\"carrot\"},\n// {\"id\":\"2\",\"fruit\":\"orange\",\"vegetable\":\"corn\"},\n// {\"id\":\"3\",\"fruit\":\"banana\",\"vegetable\":\"potato\"}]\n```\n\n### [.toJSON](index.js#L90)\n\nParse a string of CSV to a datagrid, format it using one of the `.json*` [renderer](#renderer) methods, then parse it back to JSON.\n\n**Params**\n\n* `method` **{String}**: The name of the renderer method to use, or a string of CSV. If CSV, the `.json` method will be used.\n* `str` **{String|Object}**: String of CSV or options.\n* `options` **{Object}**\n* `returns` **{String}**\n\n**Example**\n\n```js\nvar str = `\nid,fruit,vegetable\n1,apple,carrot\n2,orange,corn\n3,banana,potato`;\n\nvar res = csv.toJSON('jsonDict', str, {headers: {included: true}});\nconsole.log(res);\n// results in:\n// { '1': { fruit: 'apple', vegetable: 'carrot' },\n//   '2': { fruit: 'orange', vegetable: 'corn' },\n//   '3': { fruit: 'banana', vegetable: 'potato' } }\n```\n\n### [Parser](lib/parser.js#L30)\n\nCreate a new `Parser` with the given `options`.\n\n**Params**\n\n* `options` **{Options}**\n\n**Example**\n\n```js\nvar csv = require('parse-csv');\nvar parser = new csv.Parser();\n```\n\n### [.parse](lib/parser.js#L72)\n\nParse CSV or tab-delimited string into a data-grid formatted JavaScript object.\n\n**Params**\n\n* `str` **{String}**\n* `options` **{Object}**\n* `returns` **{Object}**\n\n**Example**\n\n```js\nvar parser = new Parser();\n\nvar str = `\nid,fruit,vegetable\n1,apple,carrot\n2,orange,corn\n3,banana,potato`;\n\nvar datagrid = parser.parse(str);\n\n// results in:\n// { data:\n//    [ [ '1', 'apple', 'carrot' ],\n//      [ '2', 'orange', 'corn' ],\n//      [ '3', 'banana', 'potato' ] ],\n//   header:\n//    { names: [ 'id', 'fruit', 'vegetable' ],\n//      types: [ '-1': 'string' ] } }\n```\n\n### [Renderer](lib/renderer.js#L22)\n\nCreate a new `Renderer` with the given `options`.\n\n**Params**\n\n* `options` **{Object}**\n\n**Example**\n\n```js\nvar csv = require('parse-csv');\nvar renderer = new csv.Renderer();\n```\n\n### Available renderers\n\nThe following render methods are available when the renderer is used directly. Or specify the renderer on `options.renderer` when using the main export function.\n\n* `.as`: Actionscript\n* `.asp`: ASP/VBScript\n* `.html`: HTML\n* `.json`: JSON - Properties\n* `.jsonArrayCols`: JSON - Column Arrays\n* `.jsonArrayRows`: JSON - Row Arrays\n* `.jsonDict`: JSON - Dictionary\n* `.mysql`: MySQL\n* `.php`: PHP\n* `.python`: Python - Dict\n* `.ruby`: Ruby\n* `.xmlProperties`: XML - Properties\n* `.xml`: XML - Nodes\n* `.xmlIllustrator`: XML - Illustrator\n\n**Example**\n\nTo render CSV as HTML:\n\n```js\nvar csv = require('parse-csv');\nvar renderer = new csv.Renderer();\n\nvar str = `\nid,fruit,vegetable\n1,apple,carrot\n2,orange,corn\n3,banana,potato`;\n\nvar html = renderer.html(str, {headers: {included: true}});\nconsole.log(html);\n```\n\nResults in:\n\n```html\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth class=\"id-cell\"\u003eid\u003c/th\u003e\n      \u003cth class=\"fruit-cell\"\u003efruit\u003c/th\u003e\n      \u003cth class=\"vegetable-cell\"\u003evegetable\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr class=\"firstRow\"\u003e\n      \u003ctd class=\"id-cell\"\u003e1\u003c/td\u003e\n      \u003ctd class=\"fruit-cell\"\u003eapple\u003c/td\u003e\n      \u003ctd class=\"vegetable-cell\"\u003ecarrot\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd class=\"id-cell\"\u003e2\u003c/td\u003e\n      \u003ctd class=\"fruit-cell\"\u003eorange\u003c/td\u003e\n      \u003ctd class=\"vegetable-cell\"\u003ecorn\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr class=\"lastRow\"\u003e\n      \u003ctd class=\"id-cell\"\u003e3\u003c/td\u003e\n      \u003ctd class=\"fruit-cell\"\u003ebanana\u003c/td\u003e\n      \u003ctd class=\"vegetable-cell\"\u003epotato\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n```\n\n## Options\n\n### Parser options\n\nAvailable parser options and the actual defaults used.\n\n```js\n{\n  headers: {\n    included: false,\n    downcase: true,\n    upcase: true\n  },\n  delimiter: 'tab',\n  decimalSign: 'comma'\n}\n```\n\n### Renderer options\n\nAvailable renderer options and the actual defaults used.\n\n```js\n{\n  headers: {\n    included: true,\n    downcase: true,\n    upcase: true\n  },\n\n  delimiter: 'tab',\n  decimalSign: 'comma',\n  outputDataType: 'json',\n  columnDelimiter: \"\\t\",\n  rowDelimiter: '\\n',\n\n  inputHeader: {},\n  outputHeader: {},\n  dataSelect: {},\n\n  outputText: '',\n\n  newline: '\\n',\n  indent: '  ',\n\n  commentLine: '//',\n  commentLineEnd: '',\n  tableName: 'converter',\n\n  useUnderscores: true,\n  includeWhiteSpace: true,\n  useTabsForIndent: false\n}\n```\n\n## Related projects\n\nYou might also be interested in these projects:\n\n* [gulp-convert](https://www.npmjs.com/package/gulp-convert): Gulp plugin to convert to or from JSON, YAML, XML, PLIST or CSV. | [homepage](https://github.com/assemble/gulp-convert)\n* [parser-csv](https://www.npmjs.com/package/parser-csv): CSV parser, compatible with [parser-cache]. | [homepage](https://github.com/jonschlinkert/parser-csv)\n\n## Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/parse-csv/issues/new).\n\n## Building docs\n\nGenerate readme and API documentation with [verb](https://github.com/verbose/verb):\n\n```sh\n$ npm install verb \u0026\u0026 npm run docs\n```\n\nOr, if [verb](https://github.com/verbose/verb) is installed globally:\n\n```sh\n$ verb\n```\n\n## Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm install -d \u0026\u0026 npm test\n```\n\n## Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)\n\n## License\n\nCopyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT license](https://github.com/jonschlinkert/parse-csv/blob/master/LICENSE).\n\n***\n\n_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on May 09, 2016._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fparse-csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fparse-csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fparse-csv/lists"}