json-md-table
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Pretty Markdown tables from JSON and CSV data

json-md-table

Lightweight and fast generation of markdown tables from js data sources


npm npm bundle size GitHub Workflow Status GitHub Workflow Status nycrc config on GitHub

Content

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

Package Sidebar

Install

npm i json-md-table

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

95.3 kB

Total Files

17

Last publish

Collaborators

  • 1nvitr0