tools-在每行末尾加上//符号
be aware of the fucking "\r"
// Node.js program to demonstrate
// the fsPromises.readFile() method
// Include fs module
const fs = require("fs");
const fsPromises = require("fs").promises;
async function readFile() {
const file = await fsPromises.readFile("./file.txt", "utf-8");
return file;
}
readFile().then((file) => {
const manyRows = file.split("\n");
let longestRow = manyRows.length;
const removePrefix = manyRows
.map((row) => {
if (row.length < 10) {
if (row.includes("{") || row.includes("}")) {
return row.replace(/\r/, " ") + "//" + "\r";
}
return row.replace(/\r/, " ") + "//" + "\r";
}
return row.replace(/\r/, "") + "//" + "\r";
})
.join("\n");
fsPromises.writeFile("./resultWithCommentSign.txt", removePrefix);
});