blob: 8446846a04cef412228069c25d9acef7809d0f6e (
plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
const fs = require("fs");
const path = require("path");
function extract(directoryPath) {
const mail = new RegExp(
"([a-z0-9_.+-]+)@([a-z0-9.-]+)\\.(([a-zA-Z0-9]|\\.){2,})",
"g",
);
try {
let emails = [];
const dirs = fs.readdirSync(directoryPath, { withFileTypes: true });
for (const dir of dirs) {
if (dir.isFile()) {
const data = fs.readFileSync(
path.join(directoryPath, dir.name),
"utf8",
);
const matches = data.match(mail);
if (matches) {
emails = [...emails, ...matches];
}
} else if (dir.isDirectory()) {
emails = [
...emails,
...extract(path.join(directoryPath, dir.name)),
];
}
}
return emails;
} catch {
throw new Error("The directory does not exist");
}
}
/*
fzhfeklzjfh@dakljhlzekj.f
fkzjefh@aaa0.fr
dejkzd@djkelh.fr
djhezklf0587dzedez@gmail................
xavier.login@epita.fr
xavier.login@epita.fR
*/
module.exports = {
extract,
};
console.log(extract("gallery"));
|