1.2.0 • Published 3 years ago

json-md-table v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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

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

1.2.0

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago