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