|
|
@ -29,9 +29,9 @@ exports.error = function (x) { |
|
|
|
* @param {Object} value The object to print out |
|
|
|
* @param {Boolean} showHidden Flag that shows hidden (not enumerable) properties of objects. |
|
|
|
*/ |
|
|
|
exports.inspect = function (obj, showHidden) { |
|
|
|
exports.inspect = function (obj, showHidden, depth) { |
|
|
|
var seen = []; |
|
|
|
function format(value) { |
|
|
|
function format(value, recurseTimes) { |
|
|
|
// Primitive types cannot have properties
|
|
|
|
switch (typeof value) { |
|
|
|
case 'undefined': return 'undefined'; |
|
|
@ -45,9 +45,12 @@ exports.inspect = function (obj, showHidden) { |
|
|
|
} |
|
|
|
|
|
|
|
// Look up the keys of the object.
|
|
|
|
var keys = showHidden ? Object.getOwnPropertyNames(value).map(function (key) { |
|
|
|
return '' + key; |
|
|
|
}) : Object.keys(value); |
|
|
|
if (showHidden) { |
|
|
|
var keys = Object.getOwnPropertyNames(value).map(function (key) { return '' + key; }); |
|
|
|
} else { |
|
|
|
var keys = Object.keys(value); |
|
|
|
} |
|
|
|
|
|
|
|
var visible_keys = Object.keys(value); |
|
|
|
|
|
|
|
// Functions without properties can be shortcutted.
|
|
|
@ -112,7 +115,15 @@ exports.inspect = function (obj, showHidden) { |
|
|
|
} |
|
|
|
if (!str) { |
|
|
|
if (seen.indexOf(value[key]) < 0) { |
|
|
|
str = format(value[key]); |
|
|
|
if (typeof recurseTimes === 'undefined' || recurseTimes === null) { |
|
|
|
str = format(value[key]); |
|
|
|
} |
|
|
|
else if (recurseTimes > 0) { |
|
|
|
str = format(value[key], recurseTimes - 1); |
|
|
|
} |
|
|
|
else { |
|
|
|
str = value[key]; |
|
|
|
} |
|
|
|
} else { |
|
|
|
str = '[Circular]'; |
|
|
|
} |
|
|
@ -129,7 +140,7 @@ exports.inspect = function (obj, showHidden) { |
|
|
|
return ' ' + line; |
|
|
|
}).join('\n') + "\n" + braces[1]; |
|
|
|
} |
|
|
|
return format(obj); |
|
|
|
return format(obj, depth); |
|
|
|
}; |
|
|
|
|
|
|
|
exports.p = function () { |
|
|
|