Options
All
  • Public
  • Public/Protected
  • All
Menu

@thi.ng/markdown-table

Index

Interfaces

Type aliases

Functions

Type aliases

Align

Align: "c" | "l" | "r"

Column

Column: Nullable<NumOrString>

Row

Row: Column[]

Functions

Const table

  • table(header: string[], rows: Iterable<Row>, opts?: Partial<TableOpts>): string
  • Takes an array of column titles, an iterable of rows and (optional) table options (e.g. column alignments). Returns string of formatted Markdown table.

    remarks

    Each row is a string array. Nullish cells/columns are allowed. Rows can also be empty. By default all columns are left-aligned.

    example
    markdownTable(
    ["ID", "Actor", "Comment"],
    [
    [1, "Alice"],
    [201, "Bob", "(foe)"],
    [3003, "Charlie", null],
    [44, "Dora", "(recipient)"],
    ],
    { bold: true, align: ["r", "c", "l"] }
    );

    // | **ID** | **Actor** | **Comment** |
    // |-------:|:---------:|:------------|
    // | 1 | Alice | |
    // | 201 | Bob | (foe) |
    // | 3003 | Charlie | |
    // | 44 | Dora | (recipient) |

    Parameters

    • header: string[]
    • rows: Iterable<Row>
    • opts: Partial<TableOpts> = {}

    Returns string

Const tableKeys

  • tableKeys<T>(headers: string[], keys: (keyof T | Fn<T, Column>)[], items: Iterable<T>, opts?: Partial<TableOpts>): string
  • Similar to table, however accepts rows as objects and looks up column values using given keys array.

    example
    tableKeys(
    ["ID", "Actor", "Comment"],
    ["id", "name", (x) => x.hint],
    [
    { id: 1, name: "Alice" },
    { id: 201, name: "Bob", hint: "(foe)" },
    { id: 3003, name: "Charlie" },
    { id: 44, name: "Dora", hint: "(recipient)" },
    ],
    { bold: true, align: ["r", "c", "l"] }
    )

    // | **ID** | **Actor** | **Comment** |
    // |-------:|:---------:|:------------|
    // | 1 | Alice | |
    // | 201 | Bob | (foe) |
    // | 3003 | Charlie | |
    // | 44 | Dora | (recipient) |

    Type parameters

    • T

    Parameters

    • headers: string[]
    • keys: (keyof T | Fn<T, Column>)[]
    • items: Iterable<T>
    • Optional opts: Partial<TableOpts>

    Returns string

Generated using TypeDoc