json-md-table
v1.2.0
Published
<h1 align="center">Pretty Markdown tables from JSON and CSV data</h1>
Downloads
5
Readme
Features
- Generate markdown tables from
- CSV strings
- CSV-like arrays
- JSON array
- Pretty print tables with
- alignment support
- column whitelist + additional columns
- column blacklist
Download & Installation
npm i --save json-md-table
Examples
import generateMarkdownTable from 'json-md-table';
generateMarkdownTable([{ a: 1, b: 2, c: 3 }, { a: 4, b: 5, c: 6 }]);
generateMarkdownTable([['a', 'b', 'c'], [1, 2, 3], [4, 5, 6]]);
generateMarkdownTable('a,b,c\n1,2,3\n4,5,6');
| a | b | c | | :---: | :---: | :---: | | 1 | 2 | 3 | | 4 | 5 | 6 |
Custom headers
generateMarkdownTable(['d', 'e', 'f'], [[1, 2, 3], [4, 5, 6]]);
generateMarkdownTable(['d', 'e', 'f'], '1,2,3\n4,5,6');
Options
generateMarkdownTable(
'a,b,c\n1,2,3\n4,5,6',
{ exclude: 'b', alignment: ['left', 'right'], pretty: true }
);
// Shorthand for `{ pretty: true }`
generateMarkdownTable('a,b,c\n1,2,3\n4,5,6', true);
| a | c | | :--- | ---: | | 1 | 3 | | 4 | 6 |
// Complete option list
interface MarkdownTableOptions {
columns?: string[];
exclude?: string[];
pretty?: true;
alignment?:
| ('left' | 'center' | 'right')[]
| ('left' | 'center' | 'right');
minWidth?: number | number[];
margin?:
| ({ left: number; right: number } | number)[]
| ({ left: number; right: number } | number);
}
Authors or Acknowledgments
- Aram Becker
License
This project is licensed under the MIT License