Skip to content

Instantly share code, notes, and snippets.

@aplater
Forked from siygle/parse-csv-email.js
Created September 27, 2019 18:01
Show Gist options
  • Select an option

  • Save aplater/c043dc84998c8c7412922def4e1fc246 to your computer and use it in GitHub Desktop.

Select an option

Save aplater/c043dc84998c8c7412922def4e1fc246 to your computer and use it in GitHub Desktop.
Parse CSV, filter and then output to another file (e.g, Email)
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