1
- <h1 id =" table " >Table</h1 >
1
+ <a name =" table " ></a >
2
+ # Table
2
3
3
4
[ ![ Travis build status] ( http://img.shields.io/travis/gajus/table/master.svg?style=flat )] ( https://travis-ci.org/gajus/table )
4
5
[ ![ NPM version] ( http://img.shields.io/npm/v/table.svg?style=flat )] ( https://www.npmjs.com/package/table )
@@ -22,7 +23,8 @@ Produces a string that represents array data in a text table.
22
23
23
24
![ Demo of table displaying a list of missions to the Moon.] ( ./.README/demo.png )
24
25
25
- <h2 id =" table-features " >Features</h2 >
26
+ <a name =" table-features " ></a >
27
+ ## Features
26
28
27
29
* Works with strings containing [ fullwidth] ( https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms ) characters.
28
30
* Works with strings containing [ ANSI escape codes] ( https://en.wikipedia.org/wiki/ANSI_escape_code ) .
@@ -32,12 +34,18 @@ Produces a string that represents array data in a text table.
32
34
* Configurable column width.
33
35
* Text wrapping.
34
36
35
- <h2 id =" table-usage " >Usage</h2 >
37
+ <a name =" table-usage " ></a >
38
+ ## Usage
36
39
37
40
Table data is described using an array (rows) of array (cells).
38
41
39
42
``` js
40
- import table from ' table' ;
43
+ import {
44
+ table
45
+ } from ' table' ;
46
+
47
+ // Using commonjs?
48
+ // const {table} = require('table');
41
49
42
50
let data,
43
51
output;
@@ -125,7 +133,8 @@ console.log(output);
125
133
```
126
134
127
135
128
- <h3 id =" table-usage-cell-content-alignment " >Cell Content Alignment</h3 >
136
+ <a name =" table-usage-cell-content-alignment " ></a >
137
+ ### Cell Content Alignment
129
138
130
139
` {string} config.columns[{number}].alignment ` property controls content horizontal alignment within a cell.
131
140
@@ -174,7 +183,8 @@ console.log(output);
174
183
╚════════════╧════════════╧════════════╝
175
184
```
176
185
177
- <h3 id =" table-usage-column-width " >Column Width</h3 >
186
+ <a name =" table-usage-column-width " ></a >
187
+ ### Column Width
178
188
179
189
` {number} config.columns[{number}].width ` property restricts column width to a fixed width.
180
190
@@ -212,7 +222,8 @@ console.log(output);
212
222
╚════╧════════════╧════╝
213
223
```
214
224
215
- <h3 id =" table-usage-custom-border " >Custom Border</h3 >
225
+ <a name =" table-usage-custom-border " ></a >
226
+ ### Custom Border
216
227
217
228
` {object} config.border ` property describes characters used to draw the table border.
218
229
@@ -265,7 +276,8 @@ console.log(output);
265
276
└────┴────┴────┘
266
277
```
267
278
268
- <h3 id =" table-usage-draw-horizontal-line " >Draw Horizontal Line</h3 >
279
+ <a name =" table-usage-draw-horizontal-line " ></a >
280
+ ### Draw Horizontal Line
269
281
270
282
` {function} config.drawHorizontalLine ` property is a function that is called for every non-content row in the table. The result of the function ` {boolean} ` determines whether a row is drawn.
271
283
@@ -311,7 +323,8 @@ console.log(output);
311
323
╚════╧════╧════╝
312
324
```
313
325
314
- <h3 id =" table-usage-padding-cell-content " >Padding Cell Content</h3 >
326
+ <a name =" table-usage-padding-cell-content " ></a >
327
+ ### Padding Cell Content
315
328
316
329
` {number} config.columns[{number}].paddingLeft ` and ` {number} config.columns[{number}].paddingRight ` properties control content padding within a cell. Property value represents a number of whitespaces used to pad the content.
317
330
@@ -355,12 +368,14 @@ console.log(output);
355
368
╚══════╧══════╧════╝
356
369
```
357
370
358
- <h3 id =" table-usage-predefined-border-templates " >Predefined Border Templates</h3 >
371
+ <a name =" table-usage-predefined-border-templates " ></a >
372
+ ### Predefined Border Templates
359
373
360
374
You can load one of the predefined border templates using ` getBorderCharacters ` function.
361
375
362
376
``` js
363
- import table, {
377
+ import {
378
+ table ,
364
379
getBorderCharacters
365
380
} from ' table' ;
366
381
@@ -423,7 +438,8 @@ table(data, config);
423
438
424
439
Raise [ an issue] ( https://github.com/gajus/table/issues ) if you'd like to contribute a new border template.
425
440
426
- <h4 id =" table-usage-predefined-border-templates-borderless-table " >Borderless Table</h4 >
441
+ <a name =" table-usage-predefined-border-templates-borderless-table " ></a >
442
+ #### Borderless Table
427
443
428
444
Simply using "void" border character template creates a table with a lot of unnecessary spacing.
429
445
@@ -452,7 +468,8 @@ console.log(output);
452
468
2A 2B 2C
453
469
```
454
470
455
- <h3 id =" table-usage-streaming " >Streaming</h3 >
471
+ <a name =" table-usage-streaming " ></a >
472
+ ### Streaming
456
473
457
474
` table ` package exports ` createStream ` function used to draw a table and append rows.
458
475
@@ -532,7 +549,8 @@ setInterval(() => {
532
549
```
533
550
534
551
![ Streaming random data.] ( ./.README/streaming-random.gif )
535
- <h3 id =" table-usage-text-truncation " >Text Truncation</h3 >
552
+ <a name =" table-usage-text-truncation " ></a >
553
+ ### Text Truncation
536
554
537
555
To handle a content that overflows the container width, ` table ` package implements [ text wrapping] ( #table-usage-text-wrapping ) . However, sometimes you may want to truncate content that is too long to be displayed in the table.
538
556
@@ -571,7 +589,8 @@ console.log(output);
571
589
╚══════════════════════╝
572
590
```
573
591
574
- <h3 id =" table-usage-text-wrapping " >Text Wrapping</h3 >
592
+ <a name =" table-usage-text-wrapping " ></a >
593
+ ### Text Wrapping
575
594
576
595
` table ` package implements auto text wrapping, i.e. text that has width greater than the container width will be separated into multiple lines, e.g.
577
596
0 commit comments