Skip to content

Repository files navigation

Tests

CLI Table output for objects and arrays

Why? The existing console.table output is actually really great, but it could use some more formatting options.

Install from npm

npm i tablecli

Usage

Create a new table

    const { TableCli } = require('tablecli');

    const mockArray = [
	  ['items', 'prices', 'animal', 'cars', 'flabbergasters'],
	  [3, '$2343.00', 'giraffe', 'Audi', 'Justin Flabber'],
	  [13, '$12.50', 'Rhinoceros', 'Lamborghini', 'John']
    ];

    const table = new TableCli();
    table.setData(mockArray);

    table.showTable();
];

basic_table

Create a new table and add rows

    const { TableCli } = require('tablecli');

    const mockObject = {
	  items: [3, 13, 34],
	  prices: ['$2343.00', '$12.50', '$234'],
	  animal: ['giraffe', 'Rhinoceros', 'ape'],
	  cars: ['Audi', 'Lamborghini'],
	  flabbergasters: ['Justin Flabber', 'John', 'Henry'] 
    }

    const table = new TableCli();
    table.setData(mockObject);

    Table.addRow([55, '$23432', 'Siverback', 'Ford', 'Oscar',
      'too many!']);
    Table.addRow([1, '$.22', 'Hedgehog', 'Buick']);

    table.showTable();
];

basic_added_rows

Customize headers, columns

    const mockObject = {
	  items: [3, 13, 34],
	  prices: ['$2343.00', '$12.50', '$234'],
	  animal: ['giraffe', 'Rhinoceros', 'ape'],
	  cars: ['Audi', 'Lamborghini'],
	  flabbergasters: ['Justin Flabber', 'John', 'Henry'] 
    }

    const options = {
	  align: 'center',
      padding: 10,
      borderType: 'double',
      headers: ['one', 'too'],
	  columnInformation: [
          { color: 'yellow', align: 'right'},
          {},
          {color: 'magenta', align: 'left'}
        ]
    }
    const table = new TableCli(options);
    table.setData(mockObject);
    table.showTable();

table custom

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages