Package Exports
- console-table-printer
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (console-table-printer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
console-table-printer
🖥️🍭Printing Pretty Tables on your console
Synopsis
Printing Simple Table with Coloring rows on your console. Its useful when you want to present some tables on console.
Installation
npm install console-table-printer --save
Basic Example
const {printTable} = require('console-table-printer');
//Create a table
const testCases = [
{ index: 3, text: 'I would like some gelb bananen bitte', value: 100 },
{ index: 4, text: 'I hope batch update is working', value: 300 }
];
//print
printTable(testCases);
Output:
You can also create a Table instance and print it:
const {Table} = require('console-table-printer');
//Create a table
const p = new Table();
//add rows with color
p.addRow({ index: 1, text: 'red wine please', value: 10.212 });
p.addRow({ index: 2, text: 'green gemuse please', value: 20.00 });
p.addRows([ //adding multiple rows are possible
{ index: 3, text: 'gelb bananen bitte', value: 100 },
{ index: 4, text: 'update is working', value: 300}
]);
//print
p.printTable();
Output:
You can also put some color to your table like this:
const p = new Table();
p.addRow({ index: 1, text: 'red wine', value: 10.212 }, {color: 'red'});
p.addRow({ index: 2, text: 'green gemuse', value: 20.00 }, {color: 'green'});
p.addRow({ index: 3, text: 'gelb bananen', value: 100 }, {color: 'yellow'});
p.printTable();
Output:
Documentation
Table instance creation
3 ways to Table Instance creation:
Simplest way
new Table()
Only with column names:
new Table(['column1', 'column2', 'column3'])
Detailed way of creating table instance
new Table({
style: 'fatBorder', //style of border of the table
columns: [
{name: 'column1', alignment: 'left'}, //with alignment
{name: 'column2', alignment: 'right'},
{name: 'column3'}
]
});
Functions
addRow(rowObjet, options)
adding single row.addRows(rowObjets)
adding multiple rows. array of row object. This case options will be applied to all the objects in rowaddColumn(columnObject)
adding single columnaddColumns(columnObjects)
adding multiple columnsprintTable()
Prints the table on your console
possible color
values for rows
- red
- green
- yellow
- white
- blue
- magenta
- cyan
- crimson
- white_bold
Example usage: To Create a row of color blue
table.addRow(rowObject, {color: 'blue'});
possible border Style of table
- thinBorder
- fatBorder:
Example for creating fat border Table new Table({style: 'fatBorder'});