[ { "id": 0, "text": "const fs = require(\"fs\");", "meta": { "functionName": null } }, { "id": 1, "text": "", "meta": { "functionName": null } }, { "id": 2, "text": "const inputFile = \"input.txt\";", "meta": { "functionName": null } }, { "id": 3, "text": "const outputFile = \"output.json\";", "meta": { "functionName": null } }, { "id": 4, "text": "", "meta": { "functionName": null } }, { "id": 5, "text": "async function processLines(lines) {", "meta": { "functionName": "processLines" } }, { "id": 6, "text": " let currentFunctionName = null;", "meta": { "functionName": "processLines" } }, { "id": 7, "text": " let braceCounter = 0;", "meta": { "functionName": "processLines" } }, { "id": 8, "text": "", "meta": { "functionName": "processLines" } }, { "id": 9, "text": " return lines.map((line, index) => {", "meta": { "functionName": "processLines" } }, { "id": 10, "text": " const text = line.replace(/[\\r\\n]+$/, \"\");", "meta": { "functionName": "processLines" } }, { "id": 11, "text": "", "meta": { "functionName": "processLines" } }, { "id": 12, "text": " const matchFunction = text.match(/(?:function|async)\\s+([A-Za-z_$][A-Za-z0-9_$]*)\\s*\\(/);", "meta": { "functionName": "processLines" } }, { "id": 13, "text": "", "meta": { "functionName": "processLines" } }, { "id": 14, "text": " if (matchFunction) {", "meta": { "functionName": "processLines" } }, { "id": 15, "text": " currentFunctionName = matchFunction[1];", "meta": { "functionName": "processLines" } }, { "id": 16, "text": " braceCounter++;", "meta": { "functionName": "processLines" } }, { "id": 17, "text": " }", "meta": { "functionName": "processLines" } }, { "id": 18, "text": "", "meta": { "functionName": "processLines" } }, { "id": 19, "text": " // Increment the braceCounter when it encounters new opening brace", "meta": { "functionName": "processLines" } }, { "id": 20, "text": " if (text.includes(\"{\")) {", "meta": { "functionName": "processLines" } }, { "id": 21, "text": " braceCounter++;", "meta": { "functionName": "processLines" } }, { "id": 22, "text": " }", "meta": { "functionName": "processLines" } }, { "id": 23, "text": "", "meta": { "functionName": "processLines" } }, { "id": 24, "text": " // Decrement the braceCounter when it encounters closing brace", "meta": { "functionName": "processLines" } }, { "id": 25, "text": " if (text.includes(\"}\")) {", "meta": { "functionName": "processLines" } }, { "id": 26, "text": " braceCounter--;", "meta": { "functionName": "processLines" } }, { "id": 27, "text": " }", "meta": { "functionName": "processLines" } }, { "id": 28, "text": "", "meta": { "functionName": "processLines" } }, { "id": 29, "text": " // Update current function name to null if closing brace found and braceCounter is 0", "meta": { "functionName": "processLines" } }, { "id": 30, "text": " if (braceCounter === 0) {", "meta": { "functionName": "processLines" } }, { "id": 31, "text": " currentFunctionName = null;", "meta": { "functionName": "processLines" } }, { "id": 32, "text": " }", "meta": { "functionName": "processLines" } }, { "id": 33, "text": "", "meta": { "functionName": "processLines" } }, { "id": 34, "text": " return {", "meta": { "functionName": "processLines" } }, { "id": 35, "text": " id: index,", "meta": { "functionName": "processLines" } }, { "id": 36, "text": " text: text,", "meta": { "functionName": "processLines" } }, { "id": 37, "text": " meta: { functionName: currentFunctionName },", "meta": { "functionName": "processLines" } }, { "id": 38, "text": " };", "meta": { "functionName": "processLines" } }, { "id": 39, "text": " });", "meta": { "functionName": "processLines" } }, { "id": 40, "text": "}", "meta": { "functionName": null } }, { "id": 41, "text": "", "meta": { "functionName": null } }, { "id": 42, "text": "async function readFileAndProcess(inputFile, outputFile) {", "meta": { "functionName": "readFileAndProcess" } }, { "id": 43, "text": " fs.readFile(inputFile, \"utf8\", async (err, contents) => {", "meta": { "functionName": "readFileAndProcess" } }, { "id": 44, "text": " if (err) throw err;", "meta": { "functionName": "readFileAndProcess" } }, { "id": 45, "text": "", "meta": { "functionName": "readFileAndProcess" } }, { "id": 46, "text": " const lines = contents.trim().split(\"\\n\");", "meta": { "functionName": "readFileAndProcess" } }, { "id": 47, "text": "", "meta": { "functionName": "readFileAndProcess" } }, { "id": 48, "text": " const jsonArray = await processLines(lines);", "meta": { "functionName": "readFileAndProcess" } }, { "id": 49, "text": "", "meta": { "functionName": "readFileAndProcess" } }, { "id": 50, "text": " const jsonString = JSON.stringify(jsonArray, null, 2);", "meta": { "functionName": "readFileAndProcess" } }, { "id": 51, "text": "", "meta": { "functionName": "readFileAndProcess" } }, { "id": 52, "text": " fs.writeFile(outputFile, jsonString, (err) => {", "meta": { "functionName": "readFileAndProcess" } }, { "id": 53, "text": " if (err) throw err;", "meta": { "functionName": "readFileAndProcess" } }, { "id": 54, "text": "", "meta": { "functionName": "readFileAndProcess" } }, { "id": 55, "text": " console.log(\"JSON output file created:\", outputFile);", "meta": { "functionName": "readFileAndProcess" } }, { "id": 56, "text": " });", "meta": { "functionName": "readFileAndProcess" } }, { "id": 57, "text": " });", "meta": { "functionName": "readFileAndProcess" } }, { "id": 58, "text": "}", "meta": { "functionName": "readFileAndProcess" } }, { "id": 59, "text": "", "meta": { "functionName": "readFileAndProcess" } }, { "id": 60, "text": "readFileAndProcess(inputFile, outputFile);", "meta": { "functionName": "readFileAndProcess" } } ]