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

table-configuration.mddocs/

Table Configuration

Comprehensive table construction and configuration options for creating tables with headers, custom dimensions, styling, and behavior settings.

Capabilities

Table Constructor

Creates a new table instance with optional configuration.

/**
 * Creates a new table instance extending Array
 * @param options - Optional configuration object
 */
constructor(options?: TableConstructorOptions): Table;

Usage Examples:

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

// Basic table without configuration
const basicTable = new Table();

// Table with headers and column widths
const configuredTable = new Table({
  head: ['Product', 'Price', 'Quantity'],
  colWidths: [20, 10, 10]
});

// Table with full styling configuration
const styledTable = new Table({
  head: ['Name', 'Status'],
  colWidths: [15, 10],
  style: {
    head: ['cyan'],
    border: ['gray'],
    compact: false
  },
  chars: {
    'top': '═',
    'top-mid': '╤',
    'top-left': '╔',
    'top-right': '╗'
  }
});

Configuration Options

Complete configuration interface for table construction.

interface TableConstructorOptions {
  /** Array of header strings */
  head?: string[];
  /** Column widths (null for auto-sizing) */
  colWidths?: Array<number | null>;
  /** Row heights (null for auto-sizing) */
  rowHeights?: Array<number | null>;
  /** Horizontal alignment per column */
  colAligns?: HorizontalAlignment[];
  /** Vertical alignment per row */
  rowAligns?: VerticalAlignment[];
  /** Style configuration object */
  style?: Partial<StyleOptions>;
  /** Border character overrides */
  chars?: Partial<Record<CharName, string>>;
  /** Character used for text truncation */
  truncate?: string;
  /** Enable word wrapping */
  wordWrap?: boolean;
  /** Wrap on word boundaries */
  wrapOnWordBoundary?: boolean;
  /** Enable debug mode (boolean, number, or string) */
  debug?: boolean | number | string;
}

Headers Configuration

Set table headers that appear at the top of the table.

head?: string[];

Usage Examples:

// Simple headers
const table = new Table({
  head: ['Name', 'Age', 'City']
});

// Headers with styling (applied via style.head)
const styledTable = new Table({
  head: ['Product', 'Price', 'Stock'],
  style: { head: ['red', 'bold'] }
});

Dimension Configuration

Control table dimensions with column widths and row heights.

colWidths?: Array<number | null>;
rowHeights?: Array<number | null>;

Usage Examples:

// Fixed column widths
const table = new Table({
  colWidths: [20, 15, 10]  // Exact widths
});

// Mixed fixed and auto widths
const mixedTable = new Table({
  colWidths: [20, null, 10]  // Middle column auto-sized
});

// Row height control
const tallTable = new Table({
  rowHeights: [3, 2, 4]  // Different heights per row
});

Alignment Configuration

Set default horizontal and vertical alignment for columns and rows.

colAligns?: HorizontalAlignment[];
rowAligns?: VerticalAlignment[];

type HorizontalAlignment = 'left' | 'center' | 'right';
type VerticalAlignment = 'top' | 'center' | 'bottom';

Usage Examples:

// Column alignment
const alignedTable = new Table({
  head: ['Product', 'Price', 'Quantity'],
  colAligns: ['left', 'right', 'center']
});

// Row alignment (for multi-line content)
const verticalTable = new Table({
  rowAligns: ['top', 'center', 'bottom']
});

Text Processing Configuration

Control text wrapping and truncation behavior.

truncate?: string;
wordWrap?: boolean;
wrapOnWordBoundary?: boolean;

Usage Examples:

// Custom truncation character
const table = new Table({
  truncate: '...',
  colWidths: [10, 15]
});

// Word wrapping enabled
const wrappingTable = new Table({
  wordWrap: true,
  wrapOnWordBoundary: true,
  colWidths: [20, 25]
});

// Text wrapping without word boundaries
const textTable = new Table({
  wordWrap: true,
  wrapOnWordBoundary: false
});

Debug Configuration

Enable debugging features to get detailed information about table processing.

debug?: boolean | number | string;

Usage Examples:

// Enable basic debugging
const debugTable = new Table({
  debug: true
});

// Set debug level (1=WARN, 2=INFO, 3=DEBUG)
const levelTable = new Table({
  debug: 2
});

// Parse debug level from string
const stringTable = new Table({
  debug: '3'
});

// Access debug messages
if (debugTable.messages) {
  console.log('Debug messages:', debugTable.messages);
}

Default Configuration

The library provides sensible defaults for all configuration options:

const defaultOptions = {
  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': '│'
  },
  truncate: '…',
  colWidths: [],
  rowHeights: [],
  colAligns: [],
  rowAligns: [],
  style: {
    'padding-left': 1,
    'padding-right': 1,
    'head': ['red'],
    'border': ['grey'],
    'compact': false
  },
  head: [],
  wordWrap: false,
  wrapOnWordBoundary: true
};