3 [![Build][build-badge]][build]
4 [![Coverage][coverage-badge]][coverage]
5 [![Downloads][downloads-badge]][downloads]
6 [![Size][size-badge]][size]
8 Generate fancy [Markdown][fancy]/ASCII tables.
15 npm install markdown-table
20 Normal usage (defaults to left-alignment):
23 var table = require('markdown-table')
27 ['master', '0123456789abcdef'],
28 ['staging', 'fedcba9876543210']
36 | ------- | ---------------- |
37 | master | 0123456789abcdef |
38 | staging | fedcba9876543210 |
46 ['Beep', 'No.', 'Boop'],
47 ['beep', '1024', 'xyz'],
48 ['boop', '3388450', 'tuv'],
49 ['foo', '10106', 'qrstuv'],
53 align: ['l', 'c', 'r']
62 | :--- | :-----: | -----: |
64 | boop | 3388450 | tuv |
65 | foo | 10106 | qrstuv |
72 table([['No.'], ['0.1.2'], ['11.22.33'], ['5.6.'], ['1.22222']], {
90 ### `markdownTable(table[, options])`
92 Turns a given matrix of strings (an array of arrays of strings) into a table.
96 ###### `options.align`
98 One style for all columns, or styles for their respective columns (`string` or
99 `Array.<string>`). Each style is either `'l'` (left), `'r'` (right), `'c'`
100 (centre), or `'.'` (dot). Other values are treated as `''`, which doesn’t place
101 the colon but does left align. _Only the lowercased first character is used,
104 ###### `options.delimiter`
106 Value to insert between cells (`string`, default: `' | '`). Careful, setting
107 this to a non-pipe breaks GitHub Flavoured Markdown.
109 ###### `options.start`
111 Value to insert at the beginning of every row (`string`, default: `'| '`).
115 Value to insert at the end of every row (`string`, default: `' |'`).
117 ###### `options.rule`
119 Whether to display a rule between the header and the body of the table
120 (`boolean`, default: `true`). Careful, will break GitHub Flavoured Markdown
123 ###### `options.stringLength`
125 Method to detect the length of a cell (`Function`, default: `s => s.length`).
127 ANSI-sequences mess up tables on terminals. To fix this, you have to
128 pass in a `stringLength` option to detect the “visible” length of a
132 var strip = require('strip-ansi')
134 function stringLength(cell) {
135 return strip(cell).length
141 Whether to pad the markdown for table cells to make them the same width
142 (`boolean`, default: `true`). Setting this to false will cause the table
143 rows to remain staggered.
147 The original idea and basic implementation was inspired by James
148 Halliday’s [text-table][] library.
152 [MIT][license] © [Titus Wormer][author]
156 [build-badge]: https://img.shields.io/travis/wooorm/markdown-table.svg
158 [build]: https://travis-ci.org/wooorm/markdown-table
160 [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/markdown-table.svg
162 [coverage]: https://codecov.io/github/wooorm/markdown-table
164 [downloads-badge]: https://img.shields.io/npm/dm/markdown-table.svg
166 [downloads]: https://www.npmjs.com/package/markdown-table
168 [size-badge]: https://img.shields.io/bundlephobia/minzip/markdown-table.svg
170 [size]: https://bundlephobia.com/result?p=markdown-table
172 [npm]: https://docs.npmjs.com/cli/install
176 [author]: https://wooorm.com
178 [fancy]: https://help.github.com/articles/github-flavored-markdown/#tables
180 [text-table]: https://github.com/substack/text-table