or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cell-formatting.mddata-management.mdindex.mdstyling-layout.mdtable-configuration.md
tile.json

tessl/npm-cli-table3

Pretty unicode tables for the command line with advanced features like spanning, alignment, and ANSI color support

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/cli-table3@0.6.x

To install, run

npx @tessl/cli install tessl/npm-cli-table3@0.6.0

index.mddocs/

CLI Table 3

CLI 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.

Package Information

  • Package Name: cli-table3
  • Package Type: npm
  • Language: JavaScript with TypeScript definitions
  • Installation: npm install cli-table3

Core Imports

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

For TypeScript:

import CliTable3 = require('cli-table3');

Basic Usage

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());

Architecture

CLI Table 3 is built around several key components:

  • Table Class: Main constructor extending Array for managing table data and configuration
  • Cell System: Individual cell objects supporting spanning, styling, and content formatting
  • Layout Manager: Handles table layout computation, width calculation, and row/column sizing
  • Style Engine: Manages border characters, colors, padding, and alignment options
  • Text Processing: ANSI-aware text truncation, word wrapping, and color state management

Capabilities

Table Construction

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;
}

Table Configuration

Data Management

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[]; }

Data Management

Cell Formatting

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;

Cell Formatting

Styling and Layout

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';

Styling and Layout

Properties and Methods

Instance Properties

interface Table extends Array<TableRow> {
  readonly options: TableInstanceOptions;
  readonly width: number;
  readonly messages?: string[];
}

Instance Methods

toString(): string;

Static Methods

/**
 * Reset global debugging state and clear all debug messages
 */
static reset(): void;

Type Definitions

Core Types

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;
}