1.0.3 • Published 1 year ago

md_table_prettyprint v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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);
});
1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago