API reference
flagstaff/table
Every export of flagstaff/table, with its signature and doc comment: table, tableComponent, plus 6 types.
import { table, tableComponent } from 'flagstaff/table';Functions
table
Draw rows as a table, as a string.
function table(rows: Row[], options?: TableOptions): string;| Parameter | Type |
|---|---|
rows | Row[] |
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>;| Parameter | Type |
|---|---|
options (optional) | TableOptions |
Returns Component<TableState>
Interfaces
ColumnOptions
One column's bounds (table-column-widths R1).
interface ColumnOptions {
/**
* How far the fit may narrow the column while another can still give way. A whole number
* from 0. It bounds the shrink and is not a width: a column narrower than it stays so.
*/
min?: number;
/** A cap no content pushes the column past. A whole number from 1, and at least `min`. */
max?: number;
/**
* What a cell wider than its column does (R3): `'wrap'` onto more physical rows, the
* default and the only behaviour before this option, or `'truncate'` to one row ending in
* `…`. A person's view only: the static projection carries the full cell either way (R4).
*/
overflow?: 'wrap' | 'truncate';
}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')[];
/**
* Bounds per column, positional like `align`; a hole or a missing entry is unbounded. Both
* are content widths, as `width()` measures them, padding not counted.
*/
columns?: (ColumnOptions | undefined)[];
/**
* 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[];