cli-table vs cli-table3 vs console-table-printer vs table vs text-table
Node.js Table Formatting Libraries
cli-tablecli-table3console-table-printertabletext-tableSimilar Packages:

Node.js Table Formatting Libraries

These libraries are designed to create and format tables in the command-line interface (CLI) for Node.js applications. They allow developers to display data in a structured and visually appealing way, enhancing the readability of output in terminal applications. Each library offers unique features and capabilities, catering to different use cases and preferences in table formatting.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
cli-table02,29317.3 kB185 years ago-
cli-table3063546.2 kB262 years agoMIT
console-table-printer022851.5 kB163 months agoMIT
table0973335 kB332 years agoBSD-3-Clause
text-table0---13 years agoMIT

Feature Comparison: cli-table vs cli-table3 vs console-table-printer vs table vs text-table

Ease of Use

  • cli-table:

    cli-table provides a very straightforward API that allows developers to create tables with minimal setup. It is designed for quick implementations and is easy to learn for beginners.

  • cli-table3:

    cli-table3 builds upon the simplicity of cli-table but adds more features while maintaining ease of use. It is still user-friendly, making it accessible for developers of all skill levels.

  • console-table-printer:

    console-table-printer offers a simple API but includes more options for customization, which may require a slight learning curve. However, it is still relatively easy to use for most developers.

  • table:

    table is designed for quick and efficient table generation, making it very easy to use with a minimalistic approach. It is perfect for developers who want to get tables up and running quickly.

  • text-table:

    text-table is extremely easy to use, focusing on generating plain text tables without any complex configurations. It is ideal for those who want a straightforward solution.

Customization Options

  • cli-table:

    cli-table has limited customization options, focusing mainly on basic table formatting. It allows for some styling but lacks advanced features for customization.

  • cli-table3:

    cli-table3 offers enhanced customization options, including support for Unicode characters and more flexible column definitions, making it suitable for more complex table layouts.

  • console-table-printer:

    console-table-printer excels in customization, allowing developers to define colors, styles, and widths for columns, providing a rich visual output for CLI applications.

  • table:

    table offers basic customization options but is primarily focused on performance and simplicity, making it less flexible than some other libraries.

  • text-table:

    text-table is minimalistic and does not provide extensive customization options, focusing instead on generating simple text tables without additional styling.

Performance

  • cli-table:

    cli-table is lightweight and performs well for basic table generation, making it suitable for applications that require quick output without heavy processing.

  • cli-table3:

    cli-table3 maintains good performance while adding more features. It is optimized for modern usage and handles Unicode characters efficiently.

  • console-table-printer:

    console-table-printer may have slightly more overhead due to its advanced features, but it is still efficient for most use cases and provides a visually appealing output.

  • table:

    table is designed for high performance and is very efficient in generating tables, making it a great choice for applications that need to display large amounts of data quickly.

  • text-table:

    text-table is lightweight and performs well for generating simple text tables, making it suitable for applications that require minimal processing.

Output Formatting

  • cli-table:

    cli-table formats tables in a traditional style, which may be limited in terms of aesthetics but is functional for basic needs.

  • cli-table3:

    cli-table3 enhances output formatting with better support for Unicode, allowing for more visually appealing tables that can include various character sets.

  • console-table-printer:

    console-table-printer provides rich output formatting options, including colors and styles, making it ideal for applications that require a more polished presentation.

  • table:

    table focuses on straightforward output formatting, providing clear and concise tables without extensive styling options.

  • text-table:

    text-table generates plain text tables that are easy to read but lack advanced formatting options, making it suitable for simple use cases.

Community and Maintenance

  • cli-table:

    cli-table has a stable user base and is well-maintained, although it may not receive frequent updates due to its simplicity.

  • cli-table3:

    cli-table3 is actively maintained and has a growing community, providing regular updates and improvements over its predecessor.

  • console-table-printer:

    console-table-printer is actively developed with a focus on adding new features and enhancements, supported by a responsive community.

  • table:

    table is maintained with a focus on performance and simplicity, ensuring that it remains a reliable choice for developers.

  • text-table:

    text-table is a mature library that is stable and well-maintained, but it may not see frequent updates due to its straightforward nature.

How to Choose: cli-table vs cli-table3 vs console-table-printer vs table vs text-table

  • cli-table:

    Choose cli-table if you need a simple and straightforward solution for creating tables in the CLI. It is easy to use and suitable for basic table formatting without advanced features.

  • cli-table3:

    Select cli-table3 if you require a modernized version of cli-table with additional features and better support for Unicode characters. It is ideal for projects that need more flexibility and customization in table styling.

  • console-table-printer:

    Opt for console-table-printer if you want a library that supports advanced features like colorized output and customizable column widths. It is perfect for applications that need enhanced visual representation of data in tables.

  • table:

    Use table if you need a lightweight and efficient solution for generating tables with minimal configuration. It is suitable for quick implementations where performance is a priority.

  • text-table:

    Choose text-table if you prefer a library that focuses on simplicity and ease of use for generating plain text tables. It is ideal for projects that require basic table formatting without additional complexity.

README for cli-table

CLI Table NPM Version Build Status

This utility allows you to render unicode-aided tables on the command line from your node.js scripts.

Screenshot

Features

  • Customizable characters that constitute the table.
  • Color/background styling in the header through colors.js
  • Column width customization
  • Text truncation based on predefined widths
  • Text alignment (left, right, center)
  • Padding (left, right)
  • Easy-to-use API

Installation

npm install cli-table

How to use

Horizontal Tables

var Table = require('cli-table');

// instantiate
var table = new Table({
    head: ['TH 1 label', 'TH 2 label']
  , colWidths: [100, 200]
});

// table is an Array, so you can `push`, `unshift`, `splice` and friends
table.push(
    ['First value', 'Second value']
  , ['First value', 'Second value']
);

console.log(table.toString());

Initializing rows in the constructore

Optionally you can initialize rows in the constructors directly - comes in handy for smaller tables:

new Table({
  rows: [
      ['foo', '7 minutes ago']
    , ['bar', '8 minutes ago']
  ]
})

Vertical Tables

var Table = require('cli-table');
var table = new Table();

table.push(
    { 'Some key': 'Some value' }
  , { 'Another key': 'Another value' }
);

console.log(table.toString());

Cross Tables

Cross tables are very similar to vertical tables, with two key differences:

  1. They require a head setting when instantiated that has an empty string as the first header
  2. The individual rows take the general form of { "Header": ["Row", "Values"] }
var Table = require('cli-table');
var table = new Table({ head: ["", "Top Header 1", "Top Header 2"] });

table.push(
    { 'Left Header 1': ['Value Row 1 Col 1', 'Value Row 1 Col 2'] }
  , { 'Left Header 2': ['Value Row 2 Col 1', 'Value Row 2 Col 2'] }
);

console.log(table.toString());

Custom styles

The chars property controls how the table is drawn:

var table = new Table({
  chars: { 'top': '═' , 'top-mid': '╤' , 'top-left': '╔' , 'top-right': '╗'
         , 'bottom': '═' , 'bottom-mid': '╧' , 'bottom-left': '╚' , 'bottom-right': '╝'
         , 'left': '║' , 'left-mid': '╟' , 'mid': '─' , 'mid-mid': '┼'
         , 'right': '║' , 'right-mid': '╢' , 'middle': '│' }
});

table.push(
    ['foo', 'bar', 'baz']
  , ['frob', 'bar', 'quuz']
);

console.log(table.toString());
// Outputs:
//
//╔══════╤═════╤══════╗
//║ foo  │ bar │ baz  ║
//╟──────┼─────┼──────╢
//║ frob │ bar │ quuz ║
//╚══════╧═════╧══════╝

Empty decoration lines will be skipped, to avoid vertical separator rows just set the 'mid', 'left-mid', 'mid-mid', 'right-mid' to the empty string:

var table = new Table({ chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''} });
table.push(
    ['foo', 'bar', 'baz']
  , ['frobnicate', 'bar', 'quuz']
);

console.log(table.toString());
// Outputs: (note the lack of the horizontal line between rows)
//┌────────────┬─────┬──────┐
//│ foo        │ bar │ baz  │
//│ frobnicate │ bar │ quuz │
//└────────────┴─────┴──────┘

By setting all chars to empty with the exception of 'middle' being set to a single space and by setting padding to zero, it's possible to get the most compact layout with no decorations:

var table = new Table({
  chars: { 'top': '' , 'top-mid': '' , 'top-left': '' , 'top-right': ''
         , 'bottom': '' , 'bottom-mid': '' , 'bottom-left': '' , 'bottom-right': ''
         , 'left': '' , 'left-mid': '' , 'mid': '' , 'mid-mid': ''
         , 'right': '' , 'right-mid': '' , 'middle': ' ' },
  style: { 'padding-left': 0, 'padding-right': 0 }
});

table.push(
    ['foo', 'bar', 'baz']
  , ['frobnicate', 'bar', 'quuz']
);

console.log(table.toString());
// Outputs:
//foo        bar baz
//frobnicate bar quuz

Running tests

Clone the repository with all its submodules and run:

$ make test

Credits

huntr

License

(The MIT License)

Copyright (c) 2010 LearnBoost <dev@learnboost.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.