UNPKG

js-code-audit

Version:

Js Code audit helps programmers to write better Javascript code

33 lines (25 loc) 1.01 kB
const fs = require("fs"); function extractFunctionNamesFromFile(filePath) { const fileContent = fs.readFileSync(filePath, "utf-8"); const functionRegex = /(function\s+(\w+)\s*\([\w\s,]*\)\s*\{[\s\S]*?\})|((\w+)\s*=\s*(?:function\s*)?\([\w\s,]*\)\s*\{[\s\S]*?\})|((\w+)\s*=\s*\([\w\s,]*\)\s*=>)|(\([\w\s,]*\)\s*=>\s*\{[\s\S]*?\})/g; const matches = fileContent.matchAll(functionRegex); const functionNames = []; for (const match of matches) { const functionName = match[2] || match[4] || match[6] || match[8]; functionNames.push(functionName); } return functionNames; } // Extract functions and arrow functions from the file const crawlFile = (filePath) => { const functions = extractFunctionNamesFromFile(filePath); // Print the extracted functions functions.forEach((name) => { console.log(""); console.log("Functions Name: " + name); console.log("Path: " + filePath); console.log(""); }); }; module.exports = { crawlFile };