Created
February 1, 2017 03:25
-
-
Save roelvan/e4a2d6d983d7aa54ebfc5d11295633bf to your computer and use it in GitHub Desktop.
Extract first name from an array of email addresses.
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 _ = require('lodash') | |
const fs = require('fs') | |
const json2csv = require('json2csv') | |
const emails = [ | |
"[email protected]" | |
] | |
const mappedMails = _.compact(_.map(emails, email => { | |
const firstName = _.capitalize(email.split('.')[0]) | |
if (firstName.indexOf('@') < 0) { | |
return { "firstName": firstName, "email": email } | |
} | |
})) | |
try { | |
const csv = json2csv({ data: mappedMails, fields: [ 'firstName', 'email' ] }) | |
fs.writeFile('./emails.csv', csv, (err) => { | |
if (err) throw err | |
console.log('file saved') | |
}) | |
} catch (err) { | |
console.error(err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment