Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
console: console.table() uses colored inspect
This makes console.table() inspect objects with color if available like
`console.log`.
  • Loading branch information
makenowjust committed May 4, 2018
commit f383ab075c48843c6b99a7df7aa6af8e0c3d3063
19 changes: 10 additions & 9 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down