CLI Table 2

0.2.0 · abandoned · verified Wed Apr 22

cli-table2 is a Node.js utility designed for rendering highly customizable, unicode-aided tables directly within command-line interfaces. Released as version 0.2.0, it presents itself as an API-compatible, drop-in replacement for the original `cli-table` package, offering enhanced features such as column and row spanning, per-cell styling (including borders and padding), vertical text alignment, and automatic word wrapping. The package also provides more robust handling of ANSI color characters within cell text, ensuring correct rendering across multiple lines. Due to its very low version number and apparent lack of recent updates since its initial releases, it appears to be an unmaintained package, which may pose compatibility challenges with newer Node.js versions or introduce unpatched security vulnerabilities. It primarily targets CommonJS environments and has no stated release cadence, reflecting its abandoned status.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the creation of horizontal, vertical, and cross-tabulated CLI tables, including basic data insertion, column width specification, and custom character styling.

const Table = require('cli-table2');

// --- Horizontal Table ---
const horizontalTable = new Table({
    head: ['TH 1 label', 'TH 2 label', 'TH 3 Label'],
    colWidths: [20, 30, 15] // Example widths
});

horizontalTable.push(
    ['First value A', 'Second value B', 'Third value C'],
    ['More data 1', 'More data 2', 'More data 3']
);
console.log('--- Horizontal Table ---');
console.log(horizontalTable.toString());
console.log('\n'); // Add a newline for separation

// --- Vertical Table ---
const verticalTable = new Table();
verticalTable.push(
    { 'Some key': 'Some value' },
    { 'Another key': 'Another value with a longer string to demonstrate wrapping' }
);
console.log('--- Vertical Table ---');
console.log(verticalTable.toString());
console.log('\n');

// --- Cross Table ---
const crossTable = new Table({ head: ["", "Top Header 1", "Top Header 2"] });
crossTable.push(
    { 'Left Header 1': ['Value Row 1 Col 1', 'Value Row 1 Col 2'] },
    { 'Left Header 2 with a long name': ['Value Row 2 Col 1', 'Value Row 2 Col 2'] }
);
console.log('--- Cross Table ---');
console.log(crossTable.toString());
console.log('\n');

// --- Custom Styles Example ---
const customTable = new Table({
  head: ['Styled Header 1', 'Styled Header 2'],
  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: { 'header': [], 'border': ['cyan'], 'compact': false } // Example style
});
customTable.push(
    ['Custom Data 1', 'Custom Data 2']
);
console.log('--- Custom Styled Table ---');
console.log(customTable.toString());

view raw JSON →