Created
February 10, 2011 00:11
-
-
Save wvl/819640 to your computer and use it in GitHub Desktop.
Get a repeatable, readable version of the source of an object
This file contains 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
{inspect} = require 'util' | |
source_for = (obj, level=[]) -> | |
source = "" | |
Object.keys(obj).sort().forEach (k) -> | |
indent = level.join('') | |
if typeof obj[k] == 'function' | |
source += indent + k + ": " +Object.getOwnPropertyDescriptor(obj, k).value.toString() + "\n" | |
else if typeof obj[k] == 'object' | |
source += indent + k + ":\n" + source_for(obj[k], level.concat(' ')) | |
else | |
source += indent + k + ": " + inspect(obj[k]) + "\n" | |
return source |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment