forked from nightcore420/learn-for-hack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailFilterWithValidator.js
32 lines (30 loc) · 1.23 KB
/
emailFilterWithValidator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const inquirer = require('inquirer');
const emailCheck = require('email-validator');
const fs = require('fs');
const questions = [{
type: 'input',
name: 'name',
message: 'Add email Path:'
}]
inquirer.prompt(questions)
.then((result) => {
const datas = fs.readFileSync(result['name'], 'utf-8');
const removeDuplicatedLines = text => [...new Set(text.split(/\r\n|\n\r|\n|\r/g))].join('\n');
const dataRemove = removeDuplicatedLines(datas);
for (let i = 0; i <= dataRemove.split('\n').length; i++) {
var cek = emailCheck.validate(dataRemove.split('\n')[i]) === true
if (cek) {
var date = new Date().toJSON().slice(0, 10).replace(/-/g, '-');
fs.appendFile(`./output/emailValidAt ${date}.txt`, dataRemove.split('\n').sort()[i] + '\n', function(err) {
if (err) throw err
return
})
// console.log(dataRemove.split('\n')[i] + ' ok')
} else {
console.log(`${dataRemove.split('\n')[i]} => tidak valid`)
}
// console.log(emailCheck.validate(dataRemove.split('\n')[i]))
}
}).catch((err) => {
console.log(err)
});