Skip to content

Commit 6af26b1

Browse files
makenowjustvsemozhetbyt
authored andcommitted
console: make console.table() use colored inspect
This makes `console.table()` inspect objects with color if available like `console.log()`. PR-URL: #20510 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Jackson Tian <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 852c459 commit 6af26b1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/console.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,6 @@ const iterKey = '(iteration index)';
319319

320320

321321
const isArray = (v) => ArrayIsArray(v) || isTypedArray(v) || isBuffer(v);
322-
const inspect = (v) => {
323-
const opt = { depth: 0, maxArrayLength: 3 };
324-
if (v !== null && typeof v === 'object' &&
325-
!isArray(v) && ObjectKeys(v).length > 2)
326-
opt.depth = -1;
327-
return util.inspect(v, opt);
328-
};
329-
330-
const getIndexArray = (length) => ArrayFrom({ length }, (_, i) => inspect(i));
331322

332323
// https://console.spec.whatwg.org/#table
333324
Console.prototype.table = function(tabularData, properties) {
@@ -340,6 +331,16 @@ Console.prototype.table = function(tabularData, properties) {
340331

341332
const final = (k, v) => this.log(cliTable(k, v));
342333

334+
const inspect = (v) => {
335+
const opt = { depth: 0, maxArrayLength: 3 };
336+
if (v !== null && typeof v === 'object' &&
337+
!isArray(v) && ObjectKeys(v).length > 2)
338+
opt.depth = -1;
339+
Object.assign(opt, this[kGetInspectOptions](this._stdout));
340+
return util.inspect(v, opt);
341+
};
342+
const getIndexArray = (length) => ArrayFrom({ length }, (_, i) => inspect(i));
343+
343344
const mapIter = isMapIterator(tabularData);
344345
if (mapIter)
345346
tabularData = previewMapIterator(tabularData);

0 commit comments

Comments
 (0)