@thi.ng/markdown-table
    TypeScript icon, indicating that this package has built-in type declarations

    0.3.21 • Public • Published

    markdown-table

    npm version npm downloads Twitter Follow

    This project is part of the @thi.ng/umbrella monorepo.

    About

    Markdown table formatter/generator with support for column alignments.

    See related packages below for alternative solutions / approaches...

    Status

    STABLE - used in production

    Search or submit any issues for this package

    Related packages

    Installation

    yarn add @thi.ng/markdown-table

    ES module import:

    <script type="module" src="https://cdn.skypack.dev/@thi.ng/markdown-table"></script>

    Skypack documentation

    For Node.js REPL:

    # with flag only for < v16
    node --experimental-repl-await
    
    > const markdownTable = await import("@thi.ng/markdown-table");
    

    Package sizes (gzipped, pre-treeshake): ESM: 645 bytes

    Dependencies

    API

    Generated API docs

    import { table, tableKeys } from "@thi.ng/markdown-table";
    
    table(
      ["ID", "Actor", "Comment"],
      [
        [1, "Alice"],
        [201, "Bob", "(foe)"],
        [3003, "Charlie", null],
        [44, "Dora", "(recipient)"],
      ],
      { align: ["r", "c", "l"] }
    );
    
    // | **ID** | **Actor** | **Comment** |
    // |-------:|:---------:|:------------|
    // |      1 |   Alice   |             |
    // |    201 |    Bob    | (foe)       |
    // |   3003 |  Charlie  |             |
    // |     44 |   Dora    | (recipient) |
    
    // ...alternatively, this produces the same:
    
    tableKeys(
        // column headers
        ["ID", "Actor", "Comment"],
        // lookup keys
        ["id", "name", "hint"],
        // rows as objects
        [
            { id: 1, name: "Alice" },
            { id: 201, name: "Bob", hint: "(foe)" },
            { id: 3003, name: "Charlie" },
            { id: 44, name: "Dora", hint: "(recipient)" },
        ],
        // table options
        { bold: true, align: ["r", "c", "l"] }
    )

    Result as Markdown:

    ID Actor Comment
    1 Alice
    201 Bob (foe)
    3003 Charlie
    44 Dora (recipient)

    Authors

    Karsten Schmidt

    If this project contributes to an academic publication, please cite it as:

    @misc{thing-markdown-table,
      title = "@thi.ng/markdown-table",
      author = "Karsten Schmidt",
      note = "https://thi.ng/markdown-table",
      year = 2021
    }

    License

    © 2021 - 2022 Karsten Schmidt // Apache Software License 2.0

    Install

    npm i @thi.ng/markdown-table

    DownloadsWeekly Downloads

    77

    Version

    0.3.21

    License

    Apache-2.0

    Unpacked Size

    27.8 kB

    Total Files

    10

    Last publish

    Collaborators

    • thi.ng