JSPM

console-table-printer

1.1.70
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1320322
  • Score
    100M100P100Q195738F
  • License MIT

Printing pretty tables on console log

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

Build Status codecov npm version install size

dependencies Status devDependencies Status

code style: prettier

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:

Screenshot

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.0 });
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:

Screenshot

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.0 }, { color: 'green' });
p.addRow({ index: 3, text: 'gelb bananen', value: 100 }, { color: 'yellow' });
p.printTable();

Output:

Screenshot

Documentation

Table instance creation

3 ways to Table Instance creation:

  1. Simplest way new Table()

  2. Only with column names: new Table(['column1', 'column2', 'column3'])

  3. 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 row
  • addColumn(columnObject) adding single column
  • addColumns(columnObjects) adding multiple columns
  • printTable() 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

Screenshot

  • fatBorder:

Screenshot

Example for creating fat border Table new Table({style: 'fatBorder'});

License

MIT