From: gap579137 <30596626+gap579137@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:07:07 +0000 (-0500) Subject: Update remove-duplicates.js X-Git-Tag: aggregated-20250518~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e424b4996dc594f3baa35363d4fc0519b72ae470;p=thirdparty%2Fblocklistproject%2Flists.git Update remove-duplicates.js --- diff --git a/scripts/remove-duplicates.js b/scripts/remove-duplicates.js index 5392aca..02586f1 100644 --- a/scripts/remove-duplicates.js +++ b/scripts/remove-duplicates.js @@ -1,36 +1,35 @@ -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); - let 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"); - const lines = fileContents.split("\n"); - const existingDomains = new Set(); - const filteredLines = []; - - lines.forEach(line => { - if (line.startsWith("0.0.0.0 ")) { - const domain = line.replace("0.0.0.0 ", ""); - if (!existingDomains.has(domain)) { - existingDomains.add(domain); - filteredLines.push(line); + const lines = fileContents.split("\n"); + const existingDomains = new Set(); + const filteredLines = lines.filter((line) => { + if (line.startsWith("0.0.0.0 ")) { + const domain = line.replace("0.0.0.0 ", ""); + if (!existingDomains.has(domain)) { + existingDomains.add(domain); + return true; + } + return false; } - } else { - filteredLines.push(line); - } - }); - - // Combine the filtered lines back into a single string - const updatedContents = filteredLines.join("\n"); + return true; + }); - await fs.writeFile(filePath, updatedContents, "utf8"); - })); + await fs.writeFile(filePath, filteredLines.join("\n"), "utf8"); + }), + ); } catch (error) { console.error("Error processing files:", error); }