flagstaff
API reference

flagstaff/table

Every export of flagstaff/table, with its signature and doc comment: table, tableComponent, plus 5 types.

import { table, tableComponent } from 'flagstaff/table';

Functions

table

Draw rows as a table, as a string.

function table(rows: Row[], options?: TableOptions): string;
ParameterType
rowsRow[]
options (optional)TableOptions

Returns string

tableComponent

A table as a component: header: value pairs off a terminal, the grid on one (R1).

function tableComponent(options?: TableOptions): Component<TableState>;
ParameterType
options (optional)TableOptions

Returns Component<TableState>

Interfaces

Linked

A cell or a body with a destination attached. href is a url or a path — file:// for a path a terminal should be able to open, which is the case R12 is named after.

interface Linked {
    readonly text: string;
    readonly href: string;
}

TableOptions

interface TableOptions {
    /** Column headers. Omitted, the table is drawn without a header row. */
    head?: string[];
    /** Columns the whole table may occupy. Default 80. */
    width?: number;
    /** Alignment per column; `left` for any column not named. */
    align?: ('left' | 'right')[];
    /**
     * The terminal a linked cell is rendered for. Omitted, the real process is read through
     * this package's seam. Supply one and the whole path is pure — which is how `link.test.ts`
     * grades both branches without a terminal in sight.
     */
    terminal?: Terminal;
}

TableState

interface TableState {
    head?: string[];
    rows: Row[];
}

Types

Cell

A table cell: text, or text with somewhere to go. A plain string stays a plain string.

type Cell = string | Linked;

Row

A row of cells. A plain string[] is still a row — a destination is opt-in per cell.

type Row = Cell[];

On this page