Giter Site home page Giter Site logo

live-text-table's Introduction

We'll do it live

live-text-table

travis cov-coveralls npm-downloads npm-version dm-david

Yet another library for printing tables to the terminal. In this case though, there is no expectation that you will have all the data ahead of time. Instead, you can set up your column definitions ahead of time, and data will be printed to the terminal as it is provided, allowing to provide feedback immediately as you fetch more and more data.

If you do have all you data already, consider using fancy-text-table, which will be able to automatically size the columns for you.

require('live-text-table')({Object} options) โ†’ Table

Initializes a new table. All options are optional, with the defaults resulting in printing directory to console similar to console.log(param1, param2, param3, ...). The following options are available:

  • columns {Array[{Object}]}: definitions for each column, in order. Each column has the following properties:
    • size {Integer}: the number of characters in each cell
    • align {String}: how to align the colums, either left, right, or center
    • char {String}: the character to use when padding the string for alignment
  • separator {String}: the text to use to separate columns
const table = require('live-text-table')({
  columns: [
    { size: 2, align: 'left' },
    { size: 45, align: 'left', char: chalk.gray('.') },
    { size: 10, align: 'right' }
  ],
  separator: ' | '
});

Each instance of a table has the following methods:

Table.title({String} title)

Creates a title. This string will span across cells of a table, and not factor in cell alignment.

table.title('This Is My Table');

Table.row(...args)

Creates a row of items as defined in the table options. Note that if a value is larger than the defined size, it will push the rest of the content and misalign that row in the table.

table.row('1', 'value 1', 1234);
table.row('2', 'value 2', 5678);
table.row('3', 'value 3', 90);

Table.line()

Creates an empty line in teh table. This is useful if you want to break up chunkcs of cells.

table.line();

Example

Full table example. Feel free to use colors anywhere you'd like to make your tables even prettier!

const chalk = require('chalk');
const table = require('live-text-table')({
  columns: [
    { size: 2, align: 'left' },
    { size: 15, align: 'left', char: chalk.gray('.') },
    { size: 6, align: 'right' }
  ],
  separator: ' | '
});

table.title('My Fruits');
table.line();
table.row(chalk.dim('#1'), chalk.cyan('pineapples'), 1234);
table.row(chalk.dim('#2'), chalk.cyan('oranges'), 5678);
table.row(chalk.dim('#3'), chalk.cyan('bananas'), 90);

// My Fruits
//
// #1 | pineapples..... |   1234
// #2 | oranges........ |   5678
// #3 | bananas........ |     90

live-text-table's People

Contributors

catdad avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.