Skip to content

Instantly share code, notes, and snippets.

@m1sta
Created January 2, 2014 23:45
Show Gist options
  • Save m1sta/8229574 to your computer and use it in GitHub Desktop.
Save m1sta/8229574 to your computer and use it in GitHub Desktop.
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