Created
January 23, 2018 13:01
-
-
Save siygle/759ec80f98da6707db08a8ab565028eb to your computer and use it in GitHub Desktop.
Parse CSV, filter and then output to another file (e.g, Email)
This file contains hidden or 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 parse = require('csv-parse') | |
const fs = require('fs') | |
const transform = require('stream-transform') | |
const isEmail = require('is-email') | |
const input = fs.createReadStream('./input.csv') | |
const output = fs.createWriteStream('./output.csv') | |
const parser = parse({ delimiter: ',' }) | |
const transformer = transform((record, callback) => { | |
if (Array.isArray(record) && isEmail(record[4])) { | |
callback(null, `${record[4]}\n`) | |
} else { | |
callback(null) | |
} | |
}, { parallel: 5 }) | |
input.pipe(parser).pipe(transformer).pipe(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment