Skip to content

Commit 8be2c63

Browse files
committed
util: add showNone option to util.inspect
1 parent 97ba69f commit 8be2c63

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/util.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const {
6363

6464
const inspectDefaultOptions = Object.seal({
6565
showHidden: false,
66+
tagOnly: false,
6667
depth: 2,
6768
colors: false,
6869
customInspect: true,
@@ -267,6 +268,7 @@ function inspect(obj, opts) {
267268
seen: [],
268269
stylize: stylizeNoColor,
269270
showHidden: inspectDefaultOptions.showHidden,
271+
tagOnly: inspectDefaultOptions.tagOnly,
270272
depth: inspectDefaultOptions.depth,
271273
colors: inspectDefaultOptions.colors,
272274
customInspect: inspectDefaultOptions.customInspect,
@@ -590,6 +592,9 @@ function formatValue(ctx, value, recurseTimes, ln) {
590592
recurseTimes -= 1;
591593
}
592594

595+
if (ctx.tagOnly)
596+
return braces.join('');
597+
593598
ctx.seen.push(value);
594599
const output = formatter(ctx, value, recurseTimes, keys);
595600

test/parallel/test-util-inspect.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ assert(!/Object/.test(
111111
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, null, true)
112112
));
113113

114+
for (const [input, output] of [
115+
[{ a: 1 }, '{}'],
116+
[[1, 2], '[]'],
117+
[new Map([['a', 1], [1, 'a']]), 'Map {}'],
118+
[new Set([1, 2, 3]), 'Set {}'],
119+
])
120+
assert.strictEqual(util.inspect(input, { tagOnly: true }), output);
121+
114122
for (const showHidden of [true, false]) {
115123
const ab = new ArrayBuffer(4);
116124
const dv = new DataView(ab, 1, 2);

0 commit comments

Comments
 (0)