]> git.ipfire.org Git - thirdparty/blocklistproject/lists.git/commitdiff
Update update-number-of-domains.js
authorgap579137 <30596626+gap579137@users.noreply.github.com>
Fri, 20 Sep 2024 15:07:25 +0000 (10:07 -0500)
committerGitHub <noreply@github.com>
Fri, 20 Sep 2024 15:07:25 +0000 (10:07 -0500)
scripts/update-number-of-domains.js

index 439c4fa3579e3be4e94813b8a2f55abe3b2abed8..fcb3e31767ecd7bd2664861593a696d72dcc7022 100644 (file)
@@ -1,31 +1,33 @@
-const fs = require("fs").promises;
-const path = require("path");
+const fs = require("node:fs").promises;
+const path = require("node:path");
 
 (async () => {
        try {
                const directoryPath = path.join(__dirname, "..");
-               const files = (await fs.readdir(directoryPath)).filter(file => file.endsWith(".txt"));
+               const files = (await fs.readdir(directoryPath)).filter((file) =>
+                       file.endsWith(".txt"),
+               );
 
-               await Promise.all(files.map(async file => {
-                       const filePath = path.join(directoryPath, file);
-                       const fileContents = await fs.readFile(filePath, "utf8");
+               await Promise.all(
+                       files.map(async (file) => {
+                               const filePath = path.join(directoryPath, file);
+                               const fileContents = await fs.readFile(filePath, "utf8");
 
-                       // Extract unique domains
-                       const existingDomains = new Set(
-                               fileContents
-                                       .split("\n")
-                                       .filter(line => line.startsWith("0.0.0.0 "))
-                                       .map(line => line.replace("0.0.0.0 ", ""))
-                       );
+                               const existingDomains = new Set(
+                                       fileContents
+                                               .split("\n")
+                                               .filter((line) => line.startsWith("0.0.0.0 "))
+                                               .map((line) => line.replace("0.0.0.0 ", "")),
+                               );
 
-                       // Update the total number of network filters
-                       const updatedContents = fileContents.replace(
-                               /^# Total number of network filters: ?(\d*)$/gm,
-                               `# Total number of network filters: ${existingDomains.size}`
-                       );
+                               const updatedContents = fileContents.replace(
+                                       /^# Total number of network filters: ?(\d*)$/gm,
+                                       `# Total number of network filters: ${existingDomains.size}`,
+                               );
 
-                       await fs.writeFile(filePath, updatedContents, "utf8");
-               }));
+                               await fs.writeFile(filePath, updatedContents, "utf8");
+                       }),
+               );
        } catch (error) {
                console.error("Error processing files:", error);
        }