table-console
v1.0.0
Published
JavaScript library for displaying table in the console
Downloads
7
Maintainers
Readme
table-console
JavaScript library for displaying table in the console
Features
- 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
Installation
npm install table-console
Usage
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());
API
Constructor options
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 rowheaderLine -
boolean
, default valuetrue
Put horizontal lines after first rowpadding, leftPadding, rightPadding -
number
, default value1
Padding in cells leftPadding and rightPadding is preferred over padding if both are present.
Methods
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 tabletoString()
Returns string representation of the tableinsertHorizontalLine()
Inserts horizontal line to bottom of the tablegetCell(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