md_table_prettyprint

1.0.3 • Public • Published

Markdown Table Pretty Printer

A 0 dependency tool to pretty print Markdown tables.

I get it, this will be parsed and displayed properly by any Markdown parser, but it's just so ugly.

Col1 | Col2 | Col3
--- | :-: | --: |
1 |2 | 3
super unreadable| data point| who needs formatting anyway?

Why not format that, so it reads a bit easier?

|Col1             |Col2       |Col3                         |
| --------------- |:---------:| ---------------------------:|
|1                |2          |3                            |
|super unreadable |data point |who needs formatting anyway? |

Oh my goodness, a million times better.

Usage

Two methods are available, prettyPrint and prettyPrintAsync they do the same thing but the response is a promise in the async version.

The methods take 2 arguments, the first is the Markdown table as a string, the second is an options object that is optional.

The options object can have the following properties:

  • padding: The number of spaces to pad the columns with, defaults to 1
  • minimumColumnWidth: The minimum width of a column, defaults to 5

Examples

const { prettyPrint } = require('markdown-table-pretty-printer');
const table = 'Col1 | Col2 | Col3\n' +
              '1 |2 | 3';

const prettyTable = prettyPrint(table);
console.log(prettyTable);
const { prettyPrintAsync } = require('markdown-table-pretty-printer');
const table = 'Col1 | Col2 | Col3\n' +
              '--- | --- | --- |\n' +
              '1 |2 | 3';

const options = {
    padding = 2
}

prettyPrintAsync(table, options).then(prettyTable => {
    console.log(prettyTable);
});

Readme

Keywords

none

Package Sidebar

Install

npm i md_table_prettyprint

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

11.7 kB

Total Files

11

Last publish

Collaborators

  • ianmcnaugh