Skip to content

Commit 4433ecb

Browse files
BridgeARtargos
authored andcommittedJul 14, 2018
lib: refactor cli table
The cli table used multi line template strings which are normally not used in our code base and it also upper cased a regular function name. This is changed by this patch. PR-URL: #20960 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent f1b18ba commit 4433ecb

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed
 

‎lib/internal/cli_table.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,28 @@ const table = (head, columns) => {
5151
for (var i = 0; i < head.length; i++) {
5252
const column = columns[i];
5353
for (var j = 0; j < longestColumn; j++) {
54-
if (!rows[j])
54+
if (rows[j] === undefined)
5555
rows[j] = [];
56-
const v = rows[j][i] = HasOwnProperty(column, j) ? column[j] : '';
56+
const value = rows[j][i] = HasOwnProperty(column, j) ? column[j] : '';
5757
const width = columnWidths[i] || 0;
58-
const counted = countSymbols(v);
58+
const counted = countSymbols(value);
5959
columnWidths[i] = Math.max(width, counted);
6060
}
6161
}
6262

6363
const divider = columnWidths.map((i) =>
6464
tableChars.middleMiddle.repeat(i + 2));
6565

66-
const tl = tableChars.topLeft;
67-
const tr = tableChars.topRight;
68-
const lm = tableChars.leftMiddle;
69-
let result = `${tl}${divider.join(tableChars.topMiddle)}${tr}
70-
${renderRow(head, columnWidths)}
71-
${lm}${divider.join(tableChars.rowMiddle)}${tableChars.rightMiddle}
72-
`;
66+
let result = `${tableChars.topLeft}${divider.join(tableChars.topMiddle)}` +
67+
`${tableChars.topRight}\n${renderRow(head, columnWidths)}\n` +
68+
`${tableChars.leftMiddle}${divider.join(tableChars.rowMiddle)}` +
69+
`${tableChars.rightMiddle}\n`;
7370

7471
for (const row of rows)
7572
result += `${renderRow(row, columnWidths)}\n`;
7673

77-
result += `${tableChars.bottomLeft}${
78-
divider.join(tableChars.bottomMiddle)}${tableChars.bottomRight}`;
74+
result += `${tableChars.bottomLeft}${divider.join(tableChars.bottomMiddle)}` +
75+
tableChars.bottomRight;
7976

8077
return result;
8178
};

0 commit comments

Comments
 (0)
Please sign in to comment.