CLI Table 3: Pretty Unicode Tables

0.6.5 · active · verified Wed Apr 22

cli-table3 is an active utility library for Node.js environments, providing a robust mechanism to render highly customizable unicode-aided tables directly in the command line. As of version 0.6.5, it offers features such as cell spanning (both column and row), individual cell styling (borders, padding), flexible text alignment, word wrapping with configurable boundaries, and enhanced handling of ANSI color characters within cell content. It is the maintained successor and API-compatible evolution of the unmaintained `cli-table` and `cli-table2` packages. Releases are consistent, addressing bug fixes and introducing enhancements like hyperlink support, `bigint` cell content, and improved TypeScript types. It ships with comprehensive TypeScript type definitions, making it suitable for modern JavaScript and TypeScript projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating a horizontal table with headers, custom column widths, and cell styling, including a column span. It also shows a basic vertical table setup.

import Table, { TableOptions, CellOptions } from 'cli-table3';

interface MyRow {
  header1: string | CellOptions;
  header2: string | CellOptions;
}

const tableConfig: TableOptions = {
  head: ['Project', 'Status', 'Progress'],
  colWidths: [30, 15, 20],
  wordWrap: true,
  style: {
    'header': ['cyan', 'bold'],
    'border': ['grey'],
    'compact': true
  }
};

const table = new Table(tableConfig);

// Add rows
table.push(
  ['CLI Table 3', { content: 'Active', style: { fg: 'green' } }, '100%'],
  ['Feature A', 'In Development', { content: '60%', style: { fg: 'yellow' } }],
  ['Feature B', { content: 'On Hold', style: { fg: 'red' } }, '10%'],
  [{ content: 'Total tasks: 3', colSpan: 3, hAlign: 'center' }]
);

console.log(table.toString());

// Example of a vertical table
const verticalTable = new Table();
verticalTable.push(
  { 'Name': 'Alice' },
  { 'Age': '30' },
  { 'City': 'New York' }
);
console.log('\n--- Vertical Table ---\n');
console.log(verticalTable.toString());

view raw JSON →