diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2020-05-28 05:30:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-28 08:30:32 -0400 |
commit | 3cbcdd4250cda17cbafa8efdfc296b79d0f6d5c0 (patch) | |
tree | bb8cf1be2a3a57aff8ddfd6c1e70ab5f53bd3227 /cli/js | |
parent | f6e58b076ca430c29f164b65678bbf6bc64a39b7 (diff) |
console: Hide `values` for console.table if display not necessary (#5914)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/web/console.ts | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/cli/js/web/console.ts b/cli/js/web/console.ts index 69c9d3137..622181030 100644 --- a/cli/js/web/console.ts +++ b/cli/js/web/console.ts @@ -842,27 +842,33 @@ export class Console { resultData = data!; } + let hasPrimitives = false; Object.keys(resultData).forEach((k, idx): void => { const value: unknown = resultData[k]!; - - if (value !== null && typeof value === "object") { - Object.entries(value as { [key: string]: unknown }).forEach( - ([k, v]): void => { - if (properties && !properties.includes(k)) { - return; + const primitive = + value === null || + (typeof value !== "function" && typeof value !== "object"); + if (properties === undefined && primitive) { + hasPrimitives = true; + values.push(stringifyValue(value)); + } else { + const valueObj = (value as { [key: string]: unknown }) || {}; + const keys = properties || Object.keys(valueObj); + for (const k of keys) { + if (primitive || !valueObj.hasOwnProperty(k)) { + if (objectValues[k]) { + // fill with blanks for idx to avoid misplacing from later values + objectValues[k].push(""); } - + } else { if (objectValues[k]) { - objectValues[k].push(stringifyValue(v)); + objectValues[k].push(stringifyValue(valueObj[k])); } else { - objectValues[k] = createColumn(v, idx); + objectValues[k] = createColumn(valueObj[k], idx); } } - ); - + } values.push(""); - } else { - values.push(stringifyValue(value)); } indexKeys.push(k); @@ -872,10 +878,7 @@ export class Console { const bodyValues = Object.values(objectValues); const header = [ indexKey, - ...(properties || [ - ...headerKeys, - !isMap && values.length > 0 && valuesKey, - ]), + ...(properties || [...headerKeys, !isMap && hasPrimitives && valuesKey]), ].filter(Boolean) as string[]; const body = [indexKeys, ...bodyValues, values]; |