From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/js/gallery/gallery.js | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 graphs/js/gallery/gallery.js (limited to 'graphs/js/gallery/gallery.js') diff --git a/graphs/js/gallery/gallery.js b/graphs/js/gallery/gallery.js new file mode 100644 index 0000000..8446846 --- /dev/null +++ b/graphs/js/gallery/gallery.js @@ -0,0 +1,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")); -- cgit v1.2.3