Last active
February 4, 2019 15:30
-
-
Save conmute/17c4f1c6c455a674ce10df0d0a41be02 to your computer and use it in GitHub Desktop.
JavaScript Multiple/single line emails into validated and formatted data value… better name?
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
let str = ` | |
email1@me | |
email2@me | |
email3@me;email4@me | |
` | |
const parsed = str | |
.split(';') | |
.map(line => { | |
return line | |
.replace(/[^\S\r\n]+/g, '') // trim | |
.split(/[\r\n]+/g) // split new lines | |
.filter(x => !!x) // filter invalid elements, here you can put validation is it email or not | |
}) | |
.reduce((acc, list) => acc = acc.concat(list), []) | |
console.log(parsed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment