Created
March 26, 2015 19:14
-
-
Save bjoerge/9e88a877a0633705b728 to your computer and use it in GitHub Desktop.
Parse CSV into objects with RxJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Rx = require('rx'); | |
const csv = require('csv-parse'); | |
const fs = require('fs'); | |
Rx.Node.fromReadableStream(fs.createReadStream('file.csv').pipe(csv())) | |
.skip(1) | |
.withLatestFrom(rows.take(1), (row, header) => { | |
// Map header[i] => row[i] | |
return row.reduce((rowObj, cell, i) => { | |
rowObj[header[i]] = cell; | |
return rowObj; | |
}, {}); | |
}) | |
.subscribe((row) => { | |
console.log("Row: %s", JSON.stringify(row, null, 2)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@QuentinRow: That's very cool and it probably deserves its own gist. Where is
getLogSubscriber
used? Typo:csv('file.csv'), { columns: true })