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