JavaScript library for displaying table in the console
- Customizable border
- Four built-in styles
- Option to create custom style
- Text and background color styling and text decorations
- Text alignment (left, center, right)
- Padding (left, right)
- Horizontal lines customization (disabled, only header, enabled)
- Zero dependency
npm install table-console
var Table = require("table-console");
var t = new Table({
padding: 2,
headerLine: false,
});
t.insertRows([
['First value', 'Second value'],
['First value', 'Second value']
]);
console.log(t.toString());
-
style -
string
ornumber
, default value"unicode"
Build-in style of border-
"unicode"
or1
(default)┌─────────────┬──────────────┐ │ First value │ Second value │ ├─────────────┼──────────────┤ │ Third value │ Fourth value │ └─────────────┴──────────────┘
-
"unicode bold"
or2
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓ ┃ First value ┃ Second value ┃ ┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫ ┃ Third value ┃ Fourth value ┃ ┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
-
"unicode double"
or3
╔═════════════╦══════════════╗ ║ First value ║ Second value ║ ╠═════════════╬══════════════╣ ║ Third value ║ Fourth value ║ ╚═════════════╩══════════════╝
-
"ascii"
or4
+-------------+--------------+ | First value | Second value | |-------------+--------------| | Third value | Fourth value | +-------------+--------------+
-
-
borders -
object
Custom borderE.g.
borders: { topLeft: "┌", top: "─", topMid: "┬", topRight: "┐", midLeft: "├", mid: "─", midMid: "┼", midRight: "┤", botLeft: "└", bot: "─", botMid: "┴", botRight: "┘", sep: "│", }
-
horizontalLines -
boolean
, default valuefalse
Put horizontal lines after each row -
headerLine -
boolean
, default valuetrue
Put horizontal lines after first row -
padding, leftPadding, rightPadding -
number
, default value1
Padding in cells leftPadding and rightPadding is preferred over padding if both are present.
-
insertRow(row)
Inserts one row to bottom of the tableParameters:
- row -
Array
containing row cells
- row -
-
insertRows(rows)
Inserts multiple rows to bottom of the tableParameters:
- rows -
Array
containing rows
- rows -
-
removeRow(row)
Removes one row from the tableParameters:
- row - row id
-
getRows()
Returns all rows in the table -
toString()
Returns string representation of the table -
insertHorizontalLine()
Inserts horizontal line to bottom of the table -
getCell(row, col)
Return cell valueParameters:
- row - row id
- col - column id
-
setCell(row, col, value)
Sets cell valueParameters:
- row - row id
- col - column id
- value - new value
-
setCellAttrs(row, col, attrs)
Sets cell attributesParameters:
- row - row id
- col - column id
- attrs - attributes
- color -
string
-black
,red
,green
,yellow
,blue
,magenta
,cyan
,white
,gray
,brightRed
,brightGreen
,brightYellow
,brightBlue
,brightMagenta
,brightCyan
,brightWhite
- bgColor -
string
-black
,red
,green
,yellow
,blue
,magenta
,cyan
,white
,gray
,brightRed
,brightGreen
,brightYellow
,brightBlue
,brightMagenta
,brightCyan
,brightWhite
- decorations -
Array
-bold
,dim
,italic
,underline
,overline
,inverse
,strikethrough
,slowBlink
,rapidBlink
- align -
string
-left
,center
,right
- color -
-
setRowAttrs(row, attrs)
Sets row attributesParameters:
- row - row id
- attrs - same as
setCellAttrs
-
setColAttrs(col, attrs)
Sets column attributesParameters:
- col - column id
- attrs - same as
setCellAttrs