Permalink
Browse files

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 <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
MakeNowJust authored and vsemozhetbyt committed May 4, 2018
1 parent 852c459 commit 6af26b11b79efab37b547ce5a85807291c26845c
Showing with 10 additions and 9 deletions.
  1. +10 −9 lib/console.js
View
@@ -319,15 +319,6 @@ const iterKey = '(iteration index)';
const isArray = (v) => ArrayIsArray(v) || isTypedArray(v) || isBuffer(v);
const inspect = (v) => {
const opt = { depth: 0, maxArrayLength: 3 };
if (v !== null && typeof v === 'object' &&
!isArray(v) && ObjectKeys(v).length > 2)
opt.depth = -1;
return util.inspect(v, opt);
};
const getIndexArray = (length) => ArrayFrom({ length }, (_, i) => inspect(i));
// https://console.spec.whatwg.org/#table
Console.prototype.table = function(tabularData, properties) {
@@ -340,6 +331,16 @@ Console.prototype.table = function(tabularData, properties) {
const final = (k, v) => this.log(cliTable(k, v));
const inspect = (v) => {
const opt = { depth: 0, maxArrayLength: 3 };
if (v !== null && typeof v === 'object' &&
!isArray(v) && ObjectKeys(v).length > 2)
opt.depth = -1;
Object.assign(opt, this[kGetInspectOptions](this._stdout));
return util.inspect(v, opt);
};
const getIndexArray = (length) => ArrayFrom({ length }, (_, i) => inspect(i));
const mapIter = isMapIterator(tabularData);
if (mapIter)
tabularData = previewMapIterator(tabularData);

0 comments on commit 6af26b1

Please sign in to comment.