Created
January 2, 2014 23:45
-
-
Save m1sta/8229574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
walk(require(process.argv[2], 1) | |
function getParamNames(func) { | |
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; | |
var fnStr = func.toString().replace(STRIP_COMMENTS, '') | |
var result = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')).match(/([^\s,]+)/g) | |
if(result === null) | |
result = [] | |
return result | |
} | |
function walk(obj, depth, antiLoop){ | |
var lead = new Array(depth*4).join(" ") | |
antiLoop = antiLoop ? antiLoop : [] | |
antiLoop.push(obj) | |
for(key in obj){ | |
if(obj[key] instanceof Function) | |
{ console.log(lead, key + "(" + getParamNames(obj[key]).join(", ") + ")") } | |
else | |
{ if(key != parseInt(key)) console.log(lead, key)} | |
if(antiLoop.indexOf(obj[key]) < 0) walk(obj[key], depth + 1, antiLoop) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment