Skip to content

Commit 3b5c6f1

Browse files
makenowjustMylesBorins
authored andcommittedMay 8, 2018
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 9211def commit 3b5c6f1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
 

‎lib/console.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,6 @@ const iterKey = '(iteration index)';
315315

316316

317317
const isArray = (v) => ArrayIsArray(v) || isTypedArray(v) || isBuffer(v);
318-
const inspect = (v) => {
319-
const opt = { depth: 0, maxArrayLength: 3 };
320-
if (v !== null && typeof v === 'object' &&
321-
!isArray(v) && ObjectKeys(v).length > 2)
322-
opt.depth = -1;
323-
return util.inspect(v, opt);
324-
};
325-
326-
const getIndexArray = (length) => ArrayFrom({ length }, (_, i) => inspect(i));
327318

328319
// https://console.spec.whatwg.org/#table
329320
Console.prototype.table = function(tabularData, properties) {
@@ -336,6 +327,16 @@ Console.prototype.table = function(tabularData, properties) {
336327

337328
const final = (k, v) => this.log(cliTable(k, v));
338329

330+
const inspect = (v) => {
331+
const opt = { depth: 0, maxArrayLength: 3 };
332+
if (v !== null && typeof v === 'object' &&
333+
!isArray(v) && ObjectKeys(v).length > 2)
334+
opt.depth = -1;
335+
Object.assign(opt, this[kGetInspectOptions](this._stdout));
336+
return util.inspect(v, opt);
337+
};
338+
const getIndexArray = (length) => ArrayFrom({ length }, (_, i) => inspect(i));
339+
339340
const mapIter = isMapIterator(tabularData);
340341
if (mapIter)
341342
tabularData = previewMapIterator(tabularData);

0 commit comments

Comments
 (0)