Skip to content

Instantly share code, notes, and snippets.

@bjoerge
Created March 26, 2015 19:14
Show Gist options
  • Save bjoerge/9e88a877a0633705b728 to your computer and use it in GitHub Desktop.
Save bjoerge/9e88a877a0633705b728 to your computer and use it in GitHub Desktop.
Parse CSV into objects with RxJS
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));
});
@tokland
Copy link

tokland commented Feb 18, 2018

@QuentinRow: That's very cool and it probably deserves its own gist. Where is getLogSubscriber used? Typo: csv('file.csv'), { columns: true })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment