Pretty unicode tables for the command line with advanced features like spanning, alignment, and ANSI color support
npx @tessl/cli install tessl/npm-cli-table3@0.6.0CLI Table 3 is a comprehensive Node.js library for creating visually appealing and highly customizable unicode tables for terminal output. Built as an enhanced successor to the original cli-table, it provides advanced features including cell spanning, custom styling, alignment options, word wrapping, and robust text truncation with ANSI color sequence support.
npm install cli-table3const Table = require('cli-table3');For TypeScript:
import CliTable3 = require('cli-table3');const Table = require('cli-table3');
// Create a basic table with headers
const table = new Table({
head: ['Name', 'Age', 'City'],
colWidths: [15, 10, 20]
});
// Add rows using array notation
table.push(
['Alice Johnson', 28, 'New York'],
['Bob Smith', 35, 'Los Angeles'],
['Carol Davis', 42, 'Chicago']
);
console.log(table.toString());CLI Table 3 is built around several key components:
Core table creation with comprehensive configuration options including headers, dimensions, styling, and behavior settings.
constructor(options?: TableConstructorOptions): Table;
interface TableConstructorOptions {
head?: string[];
colWidths?: Array<number | null>;
rowHeights?: Array<number | null>;
colAligns?: HorizontalAlignment[];
rowAligns?: VerticalAlignment[];
style?: Partial<StyleOptions>;
chars?: Partial<Record<CharName, string>>;
truncate?: string;
wordWrap?: boolean;
wrapOnWordBoundary?: boolean;
debug?: boolean | number | string;
}Array-based interface for adding, removing, and modifying table data with support for horizontal, vertical, and cross table layouts.
push(...rows: TableRow[]): number;
unshift(...rows: TableRow[]): number;
splice(start: number, deleteCount?: number, ...items: TableRow[]): TableRow[];
type TableRow = HorizontalTableRow | VerticalTableRow | CrossTableRow;
type HorizontalTableRow = Cell[];
interface VerticalTableRow { [name: string]: Cell; }
interface CrossTableRow { [name: string]: Cell[]; }Advanced cell configuration with content, styling, spanning, alignment, and hyperlink support.
interface CellOptions {
content: CellValue;
colSpan?: number;
rowSpan?: number;
hAlign?: HorizontalAlignment;
vAlign?: VerticalAlignment;
style?: Partial<{
'padding-left': number;
'padding-right': number;
head: string[];
border: string[];
}>;
chars?: Partial<Record<CharName, string>>;
truncate?: string;
wordWrap?: boolean;
wrapOnWordBoundary?: boolean;
href?: string;
}
type CellValue = boolean | number | bigint | string | null | undefined;
type Cell = CellValue | CellOptions;Comprehensive styling system with customizable border characters, colors, padding, alignment, and layout options.
interface StyleOptions {
'padding-left': number;
'padding-right': number;
head: string[];
border: string[];
compact: boolean;
}
type HorizontalAlignment = 'left' | 'center' | 'right';
type VerticalAlignment = 'top' | 'center' | 'bottom';interface Table extends Array<TableRow> {
readonly options: TableInstanceOptions;
readonly width: number;
readonly messages?: string[];
}toString(): string;/**
* Reset global debugging state and clear all debug messages
*/
static reset(): void;type CharName =
| 'top' | 'top-mid' | 'top-left' | 'top-right'
| 'bottom' | 'bottom-mid' | 'bottom-left' | 'bottom-right'
| 'left' | 'left-mid' | 'mid' | 'mid-mid'
| 'right' | 'right-mid' | 'middle';
interface TableInstanceOptions extends TableConstructorOptions {
chars: Record<CharName, string>;
style: StyleOptions;
truncate: string;
colWidths: Array<number | null>;
rowHeights: Array<number | null>;
colAligns: HorizontalAlignment[];
rowAligns: VerticalAlignment[];
head: string[];
wordWrap: boolean;
wrapOnWordBoundary: boolean;
}