Skip to content

Commit

Permalink
cleanup #46
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Feb 18, 2016
1 parent b736bdb commit 2e36a5d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ var fs = require('fs')

fs.createReadStream('some-csv-file.csv')
.pipe(csv())
.on('data', function(data) {
console.log("Name: %s Age: %s",
data["NAME"], data["AGE"])
.on('data', function (data) {
console.log('Name: %s Age: %s', data.NAME, data.AGE)
})
```

Expand All @@ -60,7 +59,7 @@ var stream = csv(['index', 'message'])

// Source from somewere with format 12312,Hello World
origin.pipe(stream)
.on('data', function(data) {
.on('data', function (data) {
console.log(data) // Should output { "index": 12312, "message": "Hello World" }
})
```
Expand All @@ -81,19 +80,22 @@ var stream = csv({
If you do not specify the headers, csv-parser will take the first line of the csv and treat it like the headers

## Events

The following events are emitted during parsing.

### data

For each row parsed (except the header), this event is emitted. This is already discussed above.

### headers

After the header row is parsed this event is emitted. An array of header names is supplied as the payload.

```
fs.createReadStream('some-csv-file.csv')
.pipe(csv())
.on('headers', function(headerList) {
console.log("First header: %s", headerList[0])
.on('headers', function (headerList) {
console.log('First header: %s', headerList[0])
})
```

Expand All @@ -103,11 +105,11 @@ The usual [Readable stream](https://nodejs.org/api/stream.html#stream_class_stre
```
fs.createReadStream('some-csv-file.csv')
.pipe(csv())
.on('data', function(data) {
//Process row
.on('data', function (data) {
// Process row
})
.on('end', function() {
//We are done
.on('end', function () {
// We are done
})
```

Expand All @@ -134,7 +136,6 @@ You can specify these CLI flags to control the JSON serialization output format
- `beforeOutput` - default empty, what to put at beginning of output
- `afterOutput` - default `\n`, what to put at end of output


For example, to produce an object with a JSON array of items as output:

```
Expand Down

0 comments on commit 2e36a5d

Please sign in to comment.