diff --git a/lib/internal/cli_table.js b/lib/internal/cli_table.js index 4c07d92eebdaa7..f6c711ece8e0ad 100644 --- a/lib/internal/cli_table.js +++ b/lib/internal/cli_table.js @@ -51,11 +51,11 @@ const table = (head, columns) => { for (var i = 0; i < head.length; i++) { const column = columns[i]; for (var j = 0; j < longestColumn; j++) { - if (!rows[j]) + if (rows[j] === undefined) rows[j] = []; - const v = rows[j][i] = HasOwnProperty(column, j) ? column[j] : ''; + const value = rows[j][i] = HasOwnProperty(column, j) ? column[j] : ''; const width = columnWidths[i] || 0; - const counted = countSymbols(v); + const counted = countSymbols(value); columnWidths[i] = Math.max(width, counted); } } @@ -63,19 +63,16 @@ const table = (head, columns) => { const divider = columnWidths.map((i) => tableChars.middleMiddle.repeat(i + 2)); - const tl = tableChars.topLeft; - const tr = tableChars.topRight; - const lm = tableChars.leftMiddle; - let result = `${tl}${divider.join(tableChars.topMiddle)}${tr} -${renderRow(head, columnWidths)} -${lm}${divider.join(tableChars.rowMiddle)}${tableChars.rightMiddle} -`; + let result = `${tableChars.topLeft}${divider.join(tableChars.topMiddle)}` + + `${tableChars.topRight}\n${renderRow(head, columnWidths)}\n` + + `${tableChars.leftMiddle}${divider.join(tableChars.rowMiddle)}` + + `${tableChars.rightMiddle}\n`; for (const row of rows) result += `${renderRow(row, columnWidths)}\n`; - result += `${tableChars.bottomLeft}${ - divider.join(tableChars.bottomMiddle)}${tableChars.bottomRight}`; + result += `${tableChars.bottomLeft}${divider.join(tableChars.bottomMiddle)}` + + tableChars.bottomRight; return result; };