Last active
November 3, 2015 07:35
-
-
Save bitifet/5087dc1ced686c426858 to your computer and use it in GitHub Desktop.
Circular-references aware inspect() function.
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
| // util.inspect() alternative returning always valid JSON even having circular refernces. | |
| // Only for debugging and inspection purposes. | |
| // Intended to be used in conjunction with underscore. Ex: "underscore print --color" | |
| // Also useful with my lovely javascript inspection vim mappings: | |
| // https://github.com/bitifet/dotfiles/blob/master/.vim/after/syntax/javascript/SyntaxInclude.vim | |
| var inspect = (function(){ | |
| var utilInspect = require("util").inspect; | |
| return function inspect (obj) { | |
| var result; | |
| var str = "var Circular = \"(->CIRCULAR<-)\";\n"; | |
| str += "result = JSON.stringify("; | |
| str += utilInspect (obj, {showHidden: false, depth: null}) | |
| str += ");" | |
| eval(str); | |
| return result; | |
| }; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment