5
5
[ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
6
[ ![ Size] [ size-badge ]] [ size ]
7
7
8
- Generate fancy [ Markdown ] [ fancy ] tables .
8
+ Generate a markdown ( [ GFM ] [ ] ) table .
9
9
10
- ## Install
10
+ ## Contents
11
+
12
+ * [ What is this?] ( #what-is-this )
13
+ * [ When should I use this?] ( #when-should-i-use-this )
14
+ * [ Install] ( #install )
15
+ * [ Use] ( #use )
16
+ * [ API] ( #api )
17
+ * [ ` markdownTable(table[, options]) ` ] ( #markdowntabletable-options )
18
+ * [ Types] ( #types )
19
+ * [ Compatibility] ( #compatibility )
20
+ * [ Security] ( #security )
21
+ * [ Inspiration] ( #inspiration )
22
+ * [ Contribute] ( #contribute )
23
+ * [ License] ( #license )
24
+
25
+ ## What is this?
26
+
27
+ This is a simple package that takes table data and generates a [ GitHub flavored
28
+ markdown (GFM)] [ gfm ] table.
11
29
12
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
13
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
30
+ ## When should I use this?
31
+
32
+ You can use this package when you want to generate the source code of a GFM
33
+ table from some data.
34
+
35
+ This is a simple solution in that it doesn’t handle escapes or HTML or any of
36
+ that.
37
+ For a complete but heavier solution, build an AST and serialize it with
38
+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] (with
39
+ [ ` mdast-util-gfm ` ] [ mdast-util-gfm ] ).
40
+
41
+ ## Install
14
42
15
- [ npm] [ ] :
43
+ This package is [ ESM only] [ esm ] .
44
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
16
45
17
46
``` sh
18
47
npm install markdown-table
19
48
```
20
49
50
+ In Deno with [ Skypack] [ ] :
51
+
52
+ ``` js
53
+ import {markdownTable } from ' https://cdn.skypack.dev/markdown-table@3?dts'
54
+ ```
55
+
56
+ In browsers with [ Skypack] [ ] :
57
+
58
+ ``` html
59
+ <script type =" module" >
60
+ import {markdownTable } from ' https://cdn.skypack.dev/markdown-table@3?min'
61
+ </script >
62
+ ```
63
+
21
64
## Use
22
65
23
66
Typical usage (defaults to align left):
@@ -74,14 +117,16 @@ There is no default export.
74
117
75
118
### ` markdownTable(table[, options]) `
76
119
77
- Turns a given matrix of strings (an array of arrays of strings) into a table .
120
+ Generate a markdown table from table data (matrix of strings).
78
121
79
122
##### ` options `
80
123
124
+ Configuration (optional).
125
+
81
126
###### ` options.align `
82
127
83
128
One style for all columns, or styles for their respective columns (` string ` or
84
- ` string[] ` ).
129
+ ` Array< string> ` ).
85
130
Each style is either ` 'l' ` (left), ` 'r' ` (right), or ` 'c' ` (center).
86
131
Other values are treated as ` '' ` , which doesn’t place the colon in the alignment
87
132
row but does align left.
@@ -112,8 +157,8 @@ When `false`, there is no padding:
112
157
113
158
Whether to begin each row with the delimiter (` boolean ` , default: ` true ` ).
114
159
115
- Note: please don’t use this: it could create fragile structures that aren’t
116
- understandable to some Markdown parsers.
160
+ > 👉 ** Note** : please don’t use this: it could create fragile structures that
161
+ > aren’t understandable to some markdown parsers.
117
162
118
163
When ` true ` , there are starting delimiters:
119
164
@@ -135,8 +180,8 @@ C | Delta |
135
180
136
181
Whether to end each row with the delimiter (` boolean ` , default: ` true ` ).
137
182
138
- Note: please don’t use this: it could create fragile structures that aren’t
139
- understandable to some Markdown parsers.
183
+ > 👉 ** Note** : please don’t use this: it could create fragile structures that
184
+ > aren’t understandable to some markdown parsers.
140
185
141
186
When ` true ` , there are ending delimiters:
142
187
@@ -175,12 +220,14 @@ Pass `false` to make them staggered:
175
220
176
221
###### ` options.stringLength `
177
222
178
- Method to detect the length of a cell (` Function ` , default: ` s => s.length ` ).
179
-
180
- Full-width characters and ANSI-sequences all mess up delimiter alignment
181
- when viewing the Markdown source.
182
- To fix this, you have to pass in a ` stringLength ` option to detect the “visible”
183
- length of a cell (note that what is and isn’t visible depends on your editor).
223
+ Function to detect the length of table cell content (` Function ` , default:
224
+ ` s => s.length ` ).
225
+ This is used when aligning the delimiters (` | ` ) between table cells.
226
+ Full-width characters and emoji mess up delimiter alignment when viewing the
227
+ markdown source.
228
+ To fix this, you can pass this function, which receives the cell content and
229
+ returns its “visible” size.
230
+ Note that what is and isn’t visible depends on where the text is displayed.
184
231
185
232
Without such a function, the following:
186
233
@@ -225,11 +272,31 @@ Yields:
225
272
| 👩❤️👩 | Delta |
226
273
```
227
274
275
+ ## Types
276
+
277
+ This package is fully typed with [ TypeScript] [ ] .
278
+ It exports additional ` Options ` type that models its respective interface.
279
+
280
+ ## Compatibility
281
+
282
+ This package is at least compatible with all maintained versions of Node.js.
283
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
284
+ It also works in Deno and modern browsers.
285
+
286
+ ## Security
287
+
288
+ This package is safe.
289
+
228
290
## Inspiration
229
291
230
292
The original idea and basic implementation was inspired by James Halliday’s
231
293
[ ` text-table ` ] [ text-table ] library.
232
294
295
+ ## Contribute
296
+
297
+ Yes please!
298
+ See [ How to Contribute to Open Source] [ contribute ] .
299
+
233
300
## License
234
301
235
302
[ MIT] [ license ] © [ Titus Wormer] [ author ]
@@ -254,12 +321,24 @@ The original idea and basic implementation was inspired by James Halliday’s
254
321
255
322
[ npm ] : https://docs.npmjs.com/cli/install
256
323
324
+ [ skypack ] : https://www.skypack.dev
325
+
257
326
[ license ] : license
258
327
259
328
[ author ] : https://wooorm.com
260
329
261
- [ fancy ] : https://help.github.com/articles/github-flavored-markdown/#tables
330
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
331
+
332
+ [ typescript ] : https://www.typescriptlang.org
333
+
334
+ [ contribute ] : https://opensource.guide/how-to-contribute/
335
+
336
+ [ gfm ] : https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/organizing-information-with-tables
262
337
263
338
[ text-table ] : https://github.com/substack/text-table
264
339
265
340
[ string-width ] : https://github.com/sindresorhus/string-width
341
+
342
+ [ mdast-util-to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
343
+
344
+ [ mdast-util-gfm ] : https://github.com/syntax-tree/mdast-util-gfm
0 commit comments