csv-string / 2.3.0 last updated 10 months ago created on Jan 21st 2013
Install
npm install --save csv-string
Clone
git clone git@github.com:touv/node-csv-string.git
dependencies
No dependencies listed.
maintainers
versions
23 total
| 2.3.0 | 10 months ago | touv |
| 2.2.5 | a year ago | touv |
| 2.2.4 | a year ago | touv |
| 2.2.3 | a year ago | touv |
| 2.2.2 | 2 years ago | touv |
| 2.2.1 | 2 years ago | touv |
| 2.1.1 | 2 years ago | touv |
| 2.1.0 | 2 years ago | touv |
| 2.0.4 | 2 years ago | touv |
| 2.0.3 | 3 years ago | touv |
| 2.0.2 | 3 years ago | touv |
| 2.0.1 | 3 years ago | touv |
| 2.0.0 | 3 years ago | touv |
| 1.2.2 | 3 years ago | touv |
| 1.2.1 | 3 years ago | touv |
| 1.2.0 | 3 years ago | touv |
| 1.1.0 | 3 years ago | touv |
| 1.0.5 | 3 years ago | touv |
| 1.0.4 | 3 years ago | touv |
| 1.0.3 | 3 years ago | touv |
| 1.0.2 | 3 years ago | touv |
| 1.0.1 | 3 years ago | touv |
| 1.0.0 | 3 years ago | touv |
readme
Javascript CSV Strings
Parse and Stringify for CSV strings.
- API similar to the JSON parser (
CSV.parseandCSV.stringify). - Can also work row by row.
- Can also be used to parse strings from readable streams (e.g. file streams).
Contributors
Installation
With npm:
Tests
Use mocha to run the tests.
API Documentation
parse(input : String, [separator : String]) : Object
Converts a CSV string input to array output.
Output:
If separator parameter is not provided, it is automatically detected.
stringify(input : Object, [separator : String]) : String
Converts object input to a CSV string.
Output:
detect(input : String) : String
Detects the best separator.
Output:
forEach(input : String, sep : String, callback : Function)
forEach(input : String, callback : Function)
callback(row : Array, index : Number) : undefined
Calls callback for each CSV row/line. The Array passed to callback contains the fields of the current row.
Output:
read(input : String, sep : String, callback : Function) : Number
read(input : String, callback : Function) : Number
callback(row : Array) : undefined
Calls callback when a CSV row is read. The Array passed to callback contains the fields of the row.
Returns the first offset after the row.
Output:
readAll(input : String, sep : String, callback : Function) : Number
readAll(input : String, callback : Function) : Number
callback(rows : Array) : undefined
Calls callback when all CSV rows are read. The Array passed to callback contains the rows of the file.
Returns the offset of the end of parsing (generaly it's the end of the input string).
Output:
readChunk(input : String, sep : String, callback : Function) : Number
readChunk(input : String, callback : Function) : Number
callback(rows : Array) : undefined
Calls callback when all CSV rows are read. The last row could be ignored, because the remainder could be in another chunk.
The Array passed to callback contains the rows of the file.
Returns the offset of the end of parsing. If the last row is ignored, the offset will point to the beginnning of the row.
Output:
createStream(options : Object) : WritableStream
createStream() : WritableStream
Create a writable stream for CSV chunk. Options are :
- separator : To indicate the CSV separator. By default is auto (see the detect function)
Example : Read CSV file from the standard input.
Related projects
- https://npmjs.org/browse/keyword/csv
- http://www.uselesscode.org/javascript/csv/
- https://github.com/archan937/csonv.js
Benchmark
I made a very basic benchmark to compare this project to other related projects, using file streams as input. See ./bench for source code.
the test
the result
| Package | Input equal Output | Time for ~1 200 000 rows |
|---|---|---|
| a-csv | almost | 0m13.903s |
| csv-streamer | yes | 0m15.599s |
| csv-stream | yes | 0m17.265s |
| csv-string | yes | 0m15.432s |
| fast-csv | no | - |
| nodecsv | yes | 0m22.129s |

