-
-
Save aplater/c043dc84998c8c7412922def4e1fc246 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