# flagstaff/table

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

Source: https://flagstaff.interlace.tools/docs/api/table

<!-- Generated by scripts/api-reference.ts from the built dist/*.d.ts. Do not edit; run `npx tsx scripts/api-reference.ts`. -->

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

## Functions

### table

Draw `rows` as a table, as a string.

```ts
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).

```ts
function tableComponent(options?: TableOptions): Component<TableState>;
```

| Parameter | Type |
| :-- | :-- |
| `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.

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

### TableOptions

```ts
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

```ts
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.

```ts
type Cell = string | Linked;
```

### Row

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

```ts
type Row = Cell[];
```
