fancy-text-table
v1.0.0
Published
like text-table, but fancier
Downloads
60
Readme
Fancy Text Table
You know, it's like text-table, but kinda fancier. It features mostly the same functionality, but conveniently handles titles spanning all table cells, table breaks, and colors in all cells.
require('fancy-text-table')
→ Table
To manage rows and titles and stuff, you have to initialize an instance of a table whenever you want to create a new table. This table instance will expose an API:
Table.row({Array} items)
Creates a row of items. Each item in the array will the converted to a string and become a cell in the table.
Table.title({String} title)
Creates a title. This string will span across all cells of the table, and not factor into cell alignment.
Table.line()
Creates an empty line in the table. This is useful if you want to break up chunks of cells.
Table.render()
→ {String}
Returns the laid-out table as a string, ready to be printed to standard output.
Example
var table = require('fancy-text-table');
var tbl = table();
tbl.title('numbers');
tbl.row([1, 2, 3, 4]);
tbl.line();
tbl.title('letters');
tbl.row(['a', 'b', 'c', 'd']);
var str = tbl.render();
console.log(str);
// numbers
// 1 2 3 4
//
// letters
// a b c d