From 8be2c63e88acec0b294bce68aa281dac7a0eb0fa Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Sun, 19 Nov 2017 14:26:48 -0600 Subject: [PATCH] util: add showNone option to util.inspect --- lib/util.js | 5 +++++ test/parallel/test-util-inspect.js | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/util.js b/lib/util.js index 3ea3fa0dc8d2a0..13368bc603e981 100644 --- a/lib/util.js +++ b/lib/util.js @@ -63,6 +63,7 @@ const { const inspectDefaultOptions = Object.seal({ showHidden: false, + tagOnly: false, depth: 2, colors: false, customInspect: true, @@ -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, @@ -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); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 58e06cb0b629c9..f34150ce2ededf 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -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);