-
-
Save carymrobbins/720fbf32d84491d2fc36 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
var repr = function (o, depth, max) { | |
var result, i; | |
depth = depth === undefined ? 0 : depth; | |
max = max === undefined ? 2 : max; | |
if (depth > max) { | |
return '<..>'; | |
} | |
switch (typeof o) { | |
case 'string': return '"' + o.replace(/"/g, '\\"') + '"'; | |
case 'function': return o.toString(); | |
case 'object': | |
if (o === null) { | |
return null; | |
} | |
if (Object.prototype.toString.call(o) === '[object Array]') { | |
result = []; | |
for (i in o) { | |
if (o.hasOwnProperty(i)) { | |
result.push(repr(o[i], depth + 1, max)); | |
} | |
} | |
return '[' + result + ']'; | |
} | |
result = []; | |
for (i in o) { | |
if (o.hasOwnProperty(i)) { | |
result.push(i + ': ' + repr(o[i], depth + 1, max)); | |
} | |
} | |
return '{' + result + '}'; | |
case 'undefined': return 'undefined'; | |
default: return o; | |
} | |
}; | |
var type = typeof exports; | |
if (type !== 'undefined') { | |
exports.repr = repr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment