{"name":"csv-string","version":"3.0.1","author":{"name":"Nicolas Thouvenin","email":"nthouvenin@gmail.com"},"contributors":[{"name":"Stéphane Gully","url":"https://github.com/kerphi"},{"name":"J Baumbach","url":"https://github.com/jbaumbach"},{"name":"Sam Hauglustaine","url":"https://github.com/smhg"},{"name":"Rick Huizinga","url":"https://github.com/rickhuizinga"},{"name":"François Parmentier","url":"https://github.com/parmentf"}],"description":"PARSE and STRINGIFY for CSV strings. It's like JSON object but for CSV. It can also work row by row. And, if can parse strings, it can be use to parse files or streams too.","keywords":["csv","parser","string","generator"],"homepage":"http://github.com/touv/node-csv-string","scripts":{"test":"istanbul test ./node_modules/.bin/_mocha -- -R spec"},"main":"./index.js","repository":{"type":"git","url":"git+https://github.com/touv/node-csv-string.git"},"dependencies":{},"devDependencies":{"eslint":"^4.11.0","istanbul":"^0.3.0","mocha":">=1.8.1","should":"^1.2.1"},"license":"MIT","engines":{"node":">=0.10.0"},"gitHead":"ed2ed8f79579f319ececc284cfd47f1e8f1ec969","bugs":{"url":"https://github.com/touv/node-csv-string/issues"},"_id":"csv-string@3.0.1","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"touv","email":"nthouvenin@gmail.com"},"dist":{"integrity":"sha512-RJ7p+0xuyu1enJ1IZwVb51H3YBBKBU5yWm8RelYuyQ6ylJtFtKu86MQ4VoBmS9LcQilqPQIpYvCq8BbmRnM1BA==","shasum":"20551a4a58efc6e8820df82e19a7e9dba8ed8352","tarball":"http://registry-npm.ywwl.com/csv-string/download/csv-string-3.0.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBR62W5/Fj56bVSaYMVTlkKf1Jg3eV1LHBQjk5uDxCNxAiBMw2gOvjJ21gKpeXDsTGOhj9u/xGV3TUGpx6wfd+xbow=="}],"size":8062,"noattachment":false,"key":"/csv-string/-/csv-string-3.0.1.tgz"},"maintainers":[{"name":"touv","email":"nthouvenin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/csv-string-3.0.1.tgz_1511597360909_0.34419446578249335"},"directories":{},"readme":"# Javascript CSV Strings\n\n[![Build Status](https://travis-ci.org/Inist-CNRS/node-csv-string.png?branch=master)](https://travis-ci.org/Inist-CNRS/node-csv-string)\n\nParse and Stringify for CSV strings.\n\n- API similar to the JSON parser (`CSV.parse` and `CSV.stringify`).\n- Can also work row by row.\n- Can also be used to parse strings from readable streams (e.g. file streams).\n- Tolerant with the weird data\n- Written in TypeScript\n\n```js\nimport * as CSV from 'csv-string';\n\n// with String\nconst arr = CSV.parse('a,b,c\\na,b,c');\nconst str = CSV.stringify(arr);\n\n// with Stream\nconst stream = CSV.createStream();\nstream.on('data', rows => {\n  process.stdout.write(CSV.stringify(rows, ','));\n});\nprocess.stdin.pipe(stream);\n```\n\n## Contributors\n\n- [Kael Shipman](https://github.com/kael-shipman)\n- [Mehul Mohan](https://github.com/mehulmpt)\n- [Hossam Magdy](https://github.com/hossam-magdy)\n- [Rich](https://github.com/rich-TIA)\n- [Rick Huizinga](https://github.com/rickhuizinga)\n- [Nicolas Thouvenin](https://github.com/touv)\n- [Stéphane Gully](https://github/kerphi)\n- [J. Baumbach](https://github.com/jbaumbach)\n- [Sam Hauglustaine](https://github.com/smhg)\n- [Rick Huizinga](https://github.com/rickhuizinga)\n- [doleksy1](https://github.com/doleksy1)\n- [François Parmentier](https://github.com/parmentf)\n\n## Installation\n\nusing [npm](http://npmjs.org):\n\n```bash\nnpm install csv-string\n```\n\nor [yarn](https://yarnpkg.com/)\n\n```bash\nyarn add csv-string\n```\n\n## API Documentation\n\n### parse(input: String, [options: Object]): Object\n### parse(input: string, [separator: string], [quote: string]): Object\n\nConverts a CSV string `input` to array output.\n\n\nOptions :\n\n-   `comma` **String** to indicate the CSV separator. (optional, default `,`)\n-   `quote` **String** to indicate the CSV quote if need. (optional, default `\"`)\n-   `output` **String** choose 'objects' or 'tuples' to change output for Array or Object. (optional, default `tuples`)\n\n\nExample 1 :\n\n```js\nconst CSV = require('csv-string');\nconst parsedCsv = CSV.parse('a;b;c\\nd;e;f', ';');\nconsole.log(parsedCsv);\n```\n\nOutput:\n\n```json\n[\n  [\"a\", \"b\", \"c\"],\n  [\"d\", \"e\", \"f\"]\n]\n```\n\nExample 2 :\n\n```js\nconst CSV = require('csv-string');\nconst parsedCsv = CSV.parse('a,b,c\\n1,2,3\\n4,5,6', { output: 'objects' });\nconsole.log(parsedCsv);\n```\n\nOutput:\n\n```json\n[\n  { a: '1', b: '2', c: '3' },\n  { a: '4', b: '5', c: '6' }\n]\n```\n\n\nIf separator parameter is not provided, it is automatically detected.\n\n### stringify(input: Object, [separator: string]): string\n\nConverts object `input` to a CSV string.\n\n```js\nimport * as CSV from 'csv-string';\n\nconsole.log(CSV.stringify(['a', 'b', 'c']));\nconsole.log(\n  CSV.stringify([\n    ['c', 'd', 'e'],\n    ['c', 'd', 'e']\n  ])\n);\nconsole.log(CSV.stringify({ a: 'e', b: 'f', c: 'g' }));\n```\n\nOutput:\n\n```txt\na,b,c\n\nc,d,e\nc,d,e\n\ne,f,g\n```\n\n### detect(input: string): string\n\nDetects the best separator.\n\n```js\nimport * as CSV from 'csv-string';\n\nconsole.log(CSV.detect('a,b,c'));\nconsole.log(CSV.detect('a;b;c'));\nconsole.log(CSV.detect('a|b|c'));\nconsole.log(CSV.detect('a\\tb\\tc'));\n```\n\nOutput:\n\n```txt\n,\n;\n|\n\\t\n```\n\n### forEach(input: string, sep: string, quo: string, callback: function)\n\n### forEach(input: string, sep: string, callback: function)\n\n### forEach(input: string, callback: function)\n\n_callback(row: array, index: number): void_\n\nCalls `callback` for each CSV row/line. The Array passed to callback contains the fields of the current row.\n\n```js\nimport * as CSV from 'csv-string';\n\nconst data = 'a,b,c\\nd,e,f';\n\nCSV.forEach(data, ',', function (row, index) {\n  console.log('#' + index + ' : ', row);\n});\n```\n\nOutput:\n\n```txt\n#0 :  [ 'a', 'b', 'c' ]\n#1 :  [ 'd', 'e', 'f' ]\n```\n\n### read(input: string, sep: string, quo: string, callback: function): number\n\n### read(input: string, sep: string, callback: function): number\n\n### read(input: string, callback: function): number\n\n_callback(row: array): void_\n\nCalls `callback` when a CSV row is read. The Array passed to callback contains the fields of the row.\nReturns the first offset after the row.\n\n```js\nimport * as CSV from 'csv-string';\n\nconst data = 'a,b,c\\nd,e,f';\n\nconst index = CSV.read(data, ',', row => {\n  console.log(row);\n});\n\nconsole.log(data.slice(index));\n```\n\nOutput:\n\n```txt\n[ 'a', 'b', 'c' ]\nd,e,f\n```\n\n### readAll(input: string, sep: string, quo: string, callback: function): number\n\n### readAll(input: string, sep: string, callback: function): number\n\n### readAll(input: string, callback: function): number\n\n_callback(rows: array): void_\n\nCalls `callback` when all CSV rows are read. The Array passed to callback contains the rows of the file.\nReturns the offset of the end of parsing (generally it's the end of the input string).\n\n```js\nimport * as CSV from 'csv-string';\n\nconst data = 'a,b,c\\nd,e,f';\n\nconst index = CSV.readAll(data, row => {\n  console.log(row);\n});\n\nconsole.log('-' + data.slice(index) + '-');\n```\n\nOutput:\n\n```txt\n[ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ] ]\n--\n```\n\n### readChunk(input: string, sep: string, quo: string, callback: function): number\n\n### readChunk(input: string, sep: string, callback: function): number\n\n### readChunk(input: string, callback: function): number\n\n_callback(rows: array): void_\n\nCalls `callback` when all CSV rows are read. The last row could be ignored, because the remainder could be in another chunk.\nThe Array passed to callback contains the rows of the file.\nReturns the offset of the end of parsing. If the last row is ignored, the offset will point to the beginnning of the row.\n\n```js\nimport * as CSV from 'csv-string';\n\nconst data = 'a,b,c\\nd,e';\n\nconst index = CSV.readChunk(data, row => {\n  console.log(row);\n});\n\nconsole.log('-' + data.slice(index) + '-');\n```\n\nOutput:\n\n```txt\n[ [ 'a', 'b', 'c' ] ]\n--\n```\n\n### createStream(options: Object): WritableStream\n\n### createStream(): WritableStream\n\nCreate a writable stream for CSV chunk. Options are :\n\n- **separator** : To indicate the CSV separator. By default is auto (see the detect function)\n- quote\\*\\* : To indicate the CSVquote.\n\nExample : Read CSV file from the standard input.\n\n```js\nconst stream = CSV.createStream();\n\nstream.on('data', row => {\n  console.log(row);\n});\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.pipe(stream);\n```\n\n## Contribution\n\n- `clone`\n- `yarn install`\n- ... do the changes, write tests\n- `yarn test` (ensure all tests pass)\n- `yarn bench` (to check the performance impact)\n\n## Related projects\n\n- <https://npmjs.org/browse/keyword/csv>\n- <http://www.uselesscode.org/js/csv/>\n- <https://github.com/archan937/csonv.js>\n\n## Benchmark\n\nThere is a quite basic benchmark to compare this project to other related ones, using file streams as input. See `./bench` for source code.\n\n### the test\n\n```bash\nyarn bench\n```\n\n### the result\n\nfor a test file with 949,044 rows\n\n| Package        | Time      | Output/Input similarity |\n| -------------- | --------- | ----------------------- |\n| a-csv          | 6.01s     | ~99%                    |\n| csv-stream     | 6.64s     | ~73%                    |\n| csv-streamer   | 7.03s     | ~79%                    |\n| **csv-string** | **6.53s** | **100%**                |\n| fast-csv       | 12.33s    | 99.99%                  |\n| nodecsv        | 7.10s     | 100%                    |\n\n## License\n\n[MIT/X11](https://github.com/Inist-CNRS/node-csv-string/blob/master/LICENSE)\n","publish_time":1511597361981,"_cnpm_publish_time":1511597361981,"dist-tags":{"latest":"4.1.1"}}