From 1cd48c7ae5f592307741865f2ba650515a0c4f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavi=20Magrinya=CC=80?= Date: Sun, 8 Jun 2014 13:02:54 +0300 Subject: [PATCH] console: console.dir() accepts options object This features comes from the need of adding extra options when displaying the object using console.dir(). console.dir() accepts now a second parameter that is passed to util.inspect() in order to provide extra options to the output. These options are: depth, color and showHidden. More information about these options in util.inspect() documentation. Signed-off-by: Fedor Indutny --- doc/api/console.markdown | 4 ++-- lib/console.js | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/doc/api/console.markdown b/doc/api/console.markdown index 62bccf4323..154b4bf697 100644 --- a/doc/api/console.markdown +++ b/doc/api/console.markdown @@ -47,10 +47,10 @@ Same as `console.error`. ## console.dir(obj, [options]) Uses `util.inspect` on `obj` and prints resulting string to stdout. This function -bypasses any custom `inspect()` function on `obj`. An optional *options* object +bypasses any custom `inspect()` function on `obj`. An optional *options* object may be passed that alters certain aspects of the formatted string: -- `showHidden` - if `true` then the object's non-enumerable properties will be +- `showHidden` - if `true` then the object's non-enumerable properties will be shown too. Defaults to `false`. - `depth` - tells `inspect` how many times to recurse while formatting the diff --git a/lib/console.js b/lib/console.js index 63dcbe17b1..75ca0adeaa 100644 --- a/lib/console.js +++ b/lib/console.js @@ -66,12 +66,9 @@ Console.prototype.error = Console.prototype.warn; Console.prototype.dir = function(object, options) { - if (typeof options === 'object' && options !== null) { - options.customInspect = false; - } else { - options = { customInspect: false }; - } - this._stdout.write(util.inspect(object, options) + '\n'); + this._stdout.write(util.inspect(object, util._extend({ + customInspect: false + }, options)) + '\n'); };