Skip to content

Commit

Permalink
util: add showNone option to util.inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Dec 17, 2017
1 parent 97ba69f commit 8be2c63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const {

const inspectDefaultOptions = Object.seal({
showHidden: false,
tagOnly: false,
depth: 2,
colors: false,
customInspect: true,
Expand Down Expand Up @@ -267,6 +268,7 @@ function inspect(obj, opts) {
seen: [],
stylize: stylizeNoColor,
showHidden: inspectDefaultOptions.showHidden,
tagOnly: inspectDefaultOptions.tagOnly,
depth: inspectDefaultOptions.depth,
colors: inspectDefaultOptions.colors,
customInspect: inspectDefaultOptions.customInspect,
Expand Down Expand Up @@ -590,6 +592,9 @@ function formatValue(ctx, value, recurseTimes, ln) {
recurseTimes -= 1;
}

if (ctx.tagOnly)
return braces.join('');

ctx.seen.push(value);
const output = formatter(ctx, value, recurseTimes, keys);

Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ assert(!/Object/.test(
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, null, true)
));

for (const [input, output] of [
[{ a: 1 }, '{}'],
[[1, 2], '[]'],
[new Map([['a', 1], [1, 'a']]), 'Map {}'],
[new Set([1, 2, 3]), 'Set {}'],
])
assert.strictEqual(util.inspect(input, { tagOnly: true }), output);

for (const showHidden of [true, false]) {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab, 1, 2);
Expand Down

0 comments on commit 8be2c63

Please sign in to comment.