cli-table3
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@colors/colors | 1.5.0 | 10.89 kB | MIT | prod optional | |
string-width | 4.2.3 | 2.33 kB | MIT | prod |
cli-table3 is a utility that allows for the rendering of unicode-aided tables in the command line from your node.js scripts. It's a refreshed version based on the original cli-table and cli-table2, which are no longer maintained. The added value of cli-table3 over its predecessors is the ability to make cells span multiple columns and/or rows, set custom styles per cell, better align text vertically and horizontally, and handle text color that spans multiple lines more efficiently. It also has various other features like improved truncation for cell text that contains ansi color characters, is API compatible with the original cli-table and comes with a highly comprehensive test suite including the entire original suite for cli-table.
To use cli-table3, start by installing it on your system with the npm package manager, using the command npm install cli-table3
.
The usage breaks down into three primary types of tables you can create: horizontal, vertical, and cross tables. For all types, you start by requiring 'cli-table3' in your node.js scripts.
For a horizontal table, you instantiate a new Table object with desired properties, like header labels and column widths. The table is essentially an array and can be manipulated as such with push
, unshift
, splice
and other array methods to add rows.
Vertical tables follow a similar process, but the table object is declared without properties and rows are added again using the push
method, with key-value pairs representing a single cell.
Cross tables require an empty string as the first header in the head
property. The rows here are structured with a key being the row header and the value being an array of cell values.
You can also customize table styles using the chars
property or create compact tables with no decoration.
For more details and advanced usage examples, refer to the examples provided in the unit test suite.
The official documentation for cli-table3 can be found directly in the readme file of its repository on GitHub. Additionally, cli-table3 provides a basic usage guide and an advanced usage guide, both hosted on GitHub. These guides cover basic usage cases and make good use of the new column and row span features, respectively.