Skip to content

Latest commit

 

History

History

markdown-table

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@thi.ng/markdown-table

npm version npm downloads Mastodon Follow

Note

This is one of 199 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

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

ESM import:

import * as mt from "@thi.ng/markdown-table";

Browser ESM import:

<script type="module" src="https://esm.run/@thi.ng/markdown-table"></script>

JSDelivr documentation

For Node.js REPL:

const mt = await import("@thi.ng/markdown-table");

Package sizes (brotli'd, pre-treeshake): ESM: 617 bytes

Dependencies

Note: @thi.ng/api is in most cases a type-only import (not used at runtime)

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

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 - 2024 Karsten Schmidt // Apache License 2.0