summaryrefslogtreecommitdiff
path: root/graphs/js/gallery
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/js/gallery
add: graphs et rushs
Diffstat (limited to 'graphs/js/gallery')
-rw-r--r--graphs/js/gallery/gallery.js54
1 files changed, 54 insertions, 0 deletions
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"));