diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-25 13:11:37 +0300 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2018-07-14 15:04:38 +0300 |
commit | 8b0c6d83220fc4be0f2a6f412cd7849af7f54c72 (patch) | |
tree | af3c3f47be98fc896e121b00e5b416fa28dd4673 /lib/internal/cli_table.js | |
parent | 7c2925e60956019fa4ca7bbcafcb98ea79022710 (diff) |
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: https://github.com/nodejs/node/pull/20960
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Diffstat (limited to 'lib/internal/cli_table.js')
-rw-r--r-- | lib/internal/cli_table.js | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/internal/cli_table.js b/lib/internal/cli_table.js index 4c07d92eebd..f6c711ece8e 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; }; |