table 6.5.0 → 6.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +407 -434
- package/dist/alignString.d.ts +2 -3
- package/dist/alignString.js +23 -11
- package/dist/alignTableData.d.ts +1 -2
- package/dist/alignTableData.js +7 -14
- package/dist/calculateCellHeight.d.ts +4 -2
- package/dist/calculateCellHeight.js +8 -9
- package/dist/calculateCellWidths.d.ts +5 -0
- package/dist/{calculateCellWidthIndex.js → calculateCellWidths.js} +6 -6
- package/dist/{calculateMaximumColumnWidthIndex.d.ts → calculateColumnWidths.d.ts} +0 -0
- package/dist/calculateColumnWidths.js +16 -0
- package/dist/calculateRowHeights.d.ts +5 -0
- package/dist/calculateRowHeights.js +18 -0
- package/dist/createStream.d.ts +1 -2
- package/dist/createStream.js +29 -30
- package/dist/drawBorder.d.ts +6 -5
- package/dist/drawBorder.js +60 -14
- package/dist/drawContent.d.ts +9 -0
- package/dist/drawContent.js +26 -0
- package/dist/drawHeader.d.ts +2 -0
- package/dist/drawHeader.js +29 -0
- package/dist/drawRow.d.ts +1 -2
- package/dist/drawRow.js +16 -12
- package/dist/drawTable.d.ts +1 -2
- package/dist/drawTable.js +28 -27
- package/dist/generated/validators.d.ts +2 -2
- package/dist/generated/validators.js +653 -303
- package/dist/getBorderCharacters.d.ts +1 -2
- package/dist/getBorderCharacters.js +7 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -9
- package/dist/makeStreamConfig.d.ts +1 -2
- package/dist/makeStreamConfig.js +14 -26
- package/dist/{makeConfig.d.ts → makeTableConfig.d.ts} +1 -2
- package/dist/{makeConfig.js → makeTableConfig.js} +29 -21
- package/dist/mapDataUsingRowHeights.d.ts +2 -0
- package/dist/mapDataUsingRowHeights.js +44 -0
- package/dist/padTableData.d.ts +2 -2
- package/dist/padTableData.js +10 -4
- package/dist/stringifyTableData.d.ts +1 -2
- package/dist/stringifyTableData.js +7 -2
- package/dist/table.d.ts +1 -2
- package/dist/table.js +23 -24
- package/dist/truncateTableData.d.ts +2 -2
- package/dist/truncateTableData.js +10 -6
- package/dist/types/api.d.ts +18 -4
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +92 -0
- package/dist/validateConfig.d.ts +1 -2
- package/dist/validateConfig.js +3 -1
- package/dist/validateTableData.d.ts +1 -2
- package/dist/validateTableData.js +5 -2
- package/dist/wrapCell.d.ts +1 -2
- package/dist/wrapCell.js +9 -24
- package/dist/wrapString.d.ts +1 -2
- package/dist/wrapString.js +3 -1
- package/dist/wrapWord.d.ts +1 -2
- package/dist/wrapWord.js +3 -1
- package/package.json +4 -5
- package/dist/calculateCellWidthIndex.d.ts +0 -6
- package/dist/calculateMaximumColumnWidthIndex.js +0 -24
- package/dist/calculateRowHeightIndex.d.ts +0 -6
- package/dist/calculateRowHeightIndex.js +0 -21
- package/dist/drawHorizontalContent.d.ts +0 -11
- package/dist/drawHorizontalContent.js +0 -18
- package/dist/mapDataUsingRowHeightIndex.d.ts +0 -3
- package/dist/mapDataUsingRowHeightIndex.js +0 -26
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<a name="table"></a>
|
|
2
2
|
# Table
|
|
3
3
|
|
|
4
|
+
> Produces a string that represents array data in a text table.
|
|
5
|
+
|
|
4
6
|
[](https://travis-ci.org/gajus/table)
|
|
5
7
|
[](https://coveralls.io/github/gajus/table)
|
|
6
8
|
[](https://www.npmjs.org/package/table)
|
|
@@ -11,20 +13,11 @@
|
|
|
11
13
|
* [Features](#table-features)
|
|
12
14
|
* [Install](#table-install)
|
|
13
15
|
* [Usage](#table-usage)
|
|
14
|
-
|
|
15
|
-
* [
|
|
16
|
-
* [
|
|
17
|
-
* [
|
|
18
|
-
* [Draw Horizontal Line](#table-usage-draw-horizontal-line)
|
|
19
|
-
* [Single Line Mode](#table-usage-single-line-mode)
|
|
20
|
-
* [Padding Cell Content](#table-usage-padding-cell-content)
|
|
21
|
-
* [Predefined Border Templates](#table-usage-predefined-border-templates)
|
|
22
|
-
* [Streaming](#table-usage-streaming)
|
|
23
|
-
* [Text Truncation](#table-usage-text-truncation)
|
|
24
|
-
* [Text Wrapping](#table-usage-text-wrapping)
|
|
25
|
-
|
|
16
|
+
* [API](#table-api)
|
|
17
|
+
* [table](#table-api-table-1)
|
|
18
|
+
* [createStream](#table-api-createstream)
|
|
19
|
+
* [getBorderCharacters](#table-api-getbordercharacters)
|
|
26
20
|
|
|
27
|
-
Produces a string that represents array data in a text table.
|
|
28
21
|
|
|
29
22
|

|
|
30
23
|
|
|
@@ -44,98 +37,28 @@ Produces a string that represents array data in a text table.
|
|
|
44
37
|
|
|
45
38
|
```bash
|
|
46
39
|
npm install table
|
|
47
|
-
|
|
48
40
|
```
|
|
49
41
|
|
|
50
42
|
[](https://www.buymeacoffee.com/gajus)
|
|
51
43
|
[](https://www.patreon.com/gajus)
|
|
52
44
|
|
|
45
|
+
|
|
53
46
|
<a name="table-usage"></a>
|
|
54
47
|
## Usage
|
|
55
48
|
|
|
56
|
-
Table data is described using an array (rows) of array (cells).
|
|
57
|
-
|
|
58
49
|
```js
|
|
59
|
-
import {
|
|
60
|
-
table
|
|
61
|
-
} from 'table';
|
|
50
|
+
import { table } from 'table';
|
|
62
51
|
|
|
63
52
|
// Using commonjs?
|
|
64
|
-
// const {table} = require('table');
|
|
65
|
-
|
|
66
|
-
let data,
|
|
67
|
-
output;
|
|
53
|
+
// const { table } = require('table');
|
|
68
54
|
|
|
69
|
-
data = [
|
|
55
|
+
const data = [
|
|
70
56
|
['0A', '0B', '0C'],
|
|
71
57
|
['1A', '1B', '1C'],
|
|
72
58
|
['2A', '2B', '2C']
|
|
73
59
|
];
|
|
74
60
|
|
|
75
|
-
|
|
76
|
-
* @typedef {string} table~cell
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @typedef {table~cell[]} table~row
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @typedef {Object} table~columns
|
|
85
|
-
* @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
|
|
86
|
-
* @property {number} width Column width (default: auto).
|
|
87
|
-
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
|
|
88
|
-
* @property {number} paddingLeft Cell content padding width left (default: 1).
|
|
89
|
-
* @property {number} paddingRight Cell content padding width right (default: 1).
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @typedef {Object} table~border
|
|
94
|
-
* @property {string} topBody
|
|
95
|
-
* @property {string} topJoin
|
|
96
|
-
* @property {string} topLeft
|
|
97
|
-
* @property {string} topRight
|
|
98
|
-
* @property {string} bottomBody
|
|
99
|
-
* @property {string} bottomJoin
|
|
100
|
-
* @property {string} bottomLeft
|
|
101
|
-
* @property {string} bottomRight
|
|
102
|
-
* @property {string} bodyLeft
|
|
103
|
-
* @property {string} bodyRight
|
|
104
|
-
* @property {string} bodyJoin
|
|
105
|
-
* @property {string} joinBody
|
|
106
|
-
* @property {string} joinLeft
|
|
107
|
-
* @property {string} joinRight
|
|
108
|
-
* @property {string} joinJoin
|
|
109
|
-
*/
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Used to dynamically tell table whether to draw a line separating rows or not.
|
|
113
|
-
* The default behavior is to always return true.
|
|
114
|
-
*
|
|
115
|
-
* @typedef {function} drawHorizontalLine
|
|
116
|
-
* @param {number} index
|
|
117
|
-
* @param {number} size
|
|
118
|
-
* @return {boolean}
|
|
119
|
-
*/
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @typedef {Object} table~config
|
|
123
|
-
* @property {table~border} border
|
|
124
|
-
* @property {table~columns[]} columns Column specific configuration.
|
|
125
|
-
* @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
|
|
126
|
-
* @property {table~drawHorizontalLine} drawHorizontalLine
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Generates a text table.
|
|
131
|
-
*
|
|
132
|
-
* @param {table~row[]} rows
|
|
133
|
-
* @param {table~config} config
|
|
134
|
-
* @return {String}
|
|
135
|
-
*/
|
|
136
|
-
output = table(data);
|
|
137
|
-
|
|
138
|
-
console.log(output);
|
|
61
|
+
console.log(table(data));
|
|
139
62
|
```
|
|
140
63
|
|
|
141
64
|
```
|
|
@@ -150,112 +73,44 @@ console.log(output);
|
|
|
150
73
|
```
|
|
151
74
|
|
|
152
75
|
|
|
153
|
-
<a name="table-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
`{string} config.columns[{number}].alignment` property controls content horizontal alignment within a cell.
|
|
157
|
-
|
|
158
|
-
Valid values are: "left", "right" and "center".
|
|
159
|
-
|
|
160
|
-
```js
|
|
161
|
-
let config,
|
|
162
|
-
data,
|
|
163
|
-
output;
|
|
76
|
+
<a name="table-api"></a>
|
|
77
|
+
## API
|
|
164
78
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
['1A', '1B', '1C'],
|
|
168
|
-
['2A', '2B', '2C']
|
|
169
|
-
];
|
|
79
|
+
<a name="table-api-table-1"></a>
|
|
80
|
+
### table
|
|
170
81
|
|
|
171
|
-
|
|
172
|
-
columns: {
|
|
173
|
-
0: {
|
|
174
|
-
alignment: 'left',
|
|
175
|
-
width: 10
|
|
176
|
-
},
|
|
177
|
-
1: {
|
|
178
|
-
alignment: 'center',
|
|
179
|
-
width: 10
|
|
180
|
-
},
|
|
181
|
-
2: {
|
|
182
|
-
alignment: 'right',
|
|
183
|
-
width: 10
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
82
|
+
Returns the string in the table format
|
|
187
83
|
|
|
188
|
-
|
|
84
|
+
**Parameters:**
|
|
85
|
+
- **_data_:** The data to display
|
|
86
|
+
- Type: `any[][]`
|
|
87
|
+
- Required: `true`
|
|
189
88
|
|
|
190
|
-
|
|
191
|
-
|
|
89
|
+
- **_config_:** Table configuration
|
|
90
|
+
- Type: `object`
|
|
91
|
+
- Required: `false`
|
|
192
92
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
║ 0A │ 0B │ 0C ║
|
|
196
|
-
╟────────────┼────────────┼────────────╢
|
|
197
|
-
║ 1A │ 1B │ 1C ║
|
|
198
|
-
╟────────────┼────────────┼────────────╢
|
|
199
|
-
║ 2A │ 2B │ 2C ║
|
|
200
|
-
╚════════════╧════════════╧════════════╝
|
|
201
|
-
```
|
|
93
|
+
<a name="table-api-table-1-config-border"></a>
|
|
94
|
+
##### config.border
|
|
202
95
|
|
|
203
|
-
|
|
204
|
-
|
|
96
|
+
Type: `{ [type: string]: string }`\
|
|
97
|
+
Default: `honeywell` [template](#getbordercharacters)
|
|
205
98
|
|
|
206
|
-
|
|
99
|
+
Custom borders. The keys are any of:
|
|
100
|
+
- `topLeft`, `topRight`, `topBody`,`topJoin`
|
|
101
|
+
- `bottomLeft`, `bottomRight`, `bottomBody`, `bottomJoin`
|
|
102
|
+
- `joinLeft`, `joinRight`, `joinBody`, `joinJoin`
|
|
103
|
+
- `bodyLeft`, `bodyRight`, `bodyJoin`
|
|
104
|
+
- `headerJoin`
|
|
207
105
|
|
|
208
106
|
```js
|
|
209
|
-
|
|
210
|
-
output,
|
|
211
|
-
options;
|
|
212
|
-
|
|
213
|
-
data = [
|
|
214
|
-
['0A', '0B', '0C'],
|
|
215
|
-
['1A', '1B', '1C'],
|
|
216
|
-
['2A', '2B', '2C']
|
|
217
|
-
];
|
|
218
|
-
|
|
219
|
-
options = {
|
|
220
|
-
columns: {
|
|
221
|
-
1: {
|
|
222
|
-
width: 10
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
output = table(data, options);
|
|
228
|
-
|
|
229
|
-
console.log(output);
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
```
|
|
233
|
-
╔════╤════════════╤════╗
|
|
234
|
-
║ 0A │ 0B │ 0C ║
|
|
235
|
-
╟────┼────────────┼────╢
|
|
236
|
-
║ 1A │ 1B │ 1C ║
|
|
237
|
-
╟────┼────────────┼────╢
|
|
238
|
-
║ 2A │ 2B │ 2C ║
|
|
239
|
-
╚════╧════════════╧════╝
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
<a name="table-usage-custom-border"></a>
|
|
243
|
-
### Custom Border
|
|
244
|
-
|
|
245
|
-
`{object} config.border` property describes characters used to draw the table border.
|
|
246
|
-
|
|
247
|
-
```js
|
|
248
|
-
let config,
|
|
249
|
-
data,
|
|
250
|
-
output;
|
|
251
|
-
|
|
252
|
-
data = [
|
|
107
|
+
const data = [
|
|
253
108
|
['0A', '0B', '0C'],
|
|
254
109
|
['1A', '1B', '1C'],
|
|
255
110
|
['2A', '2B', '2C']
|
|
256
111
|
];
|
|
257
112
|
|
|
258
|
-
config = {
|
|
113
|
+
const config = {
|
|
259
114
|
border: {
|
|
260
115
|
topBody: `─`,
|
|
261
116
|
topJoin: `┬`,
|
|
@@ -278,9 +133,7 @@ config = {
|
|
|
278
133
|
}
|
|
279
134
|
};
|
|
280
135
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
console.log(output);
|
|
136
|
+
console.log(table(data, config));
|
|
284
137
|
```
|
|
285
138
|
|
|
286
139
|
```
|
|
@@ -293,17 +146,17 @@ console.log(output);
|
|
|
293
146
|
└────┴────┴────┘
|
|
294
147
|
```
|
|
295
148
|
|
|
296
|
-
<a name="table-
|
|
297
|
-
|
|
149
|
+
<a name="table-api-table-1-config-drawverticalline"></a>
|
|
150
|
+
##### config.drawVerticalLine
|
|
298
151
|
|
|
299
|
-
|
|
152
|
+
Type: `(lineIndex: number, columnCount: number) => boolean`\
|
|
153
|
+
Default: `() => true`
|
|
300
154
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
output,
|
|
304
|
-
options;
|
|
155
|
+
It is used to tell whether to draw a vertical line. This callback is called for each vertical border of the table.
|
|
156
|
+
If the table has `n` columns, then the `index` parameter is alternatively received all numbers in range `[0, n]` inclusively.
|
|
305
157
|
|
|
306
|
-
|
|
158
|
+
```js
|
|
159
|
+
const data = [
|
|
307
160
|
['0A', '0B', '0C'],
|
|
308
161
|
['1A', '1B', '1C'],
|
|
309
162
|
['2A', '2B', '2C'],
|
|
@@ -311,21 +164,13 @@ data = [
|
|
|
311
164
|
['4A', '4B', '4C']
|
|
312
165
|
];
|
|
313
166
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
* @param {number} index
|
|
318
|
-
* @param {number} size
|
|
319
|
-
* @return {boolean}
|
|
320
|
-
*/
|
|
321
|
-
drawVerticalLine: (index, size) => {
|
|
322
|
-
return index === 0 || index === size;
|
|
167
|
+
const config = {
|
|
168
|
+
drawVerticalLine: (lineIndex, columnCount) => {
|
|
169
|
+
return lineIndex === 0 || lineIndex === columnCount;
|
|
323
170
|
}
|
|
324
171
|
};
|
|
325
172
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
console.log(output);
|
|
173
|
+
console.log(table(data, config));
|
|
329
174
|
|
|
330
175
|
```
|
|
331
176
|
|
|
@@ -344,17 +189,18 @@ console.log(output);
|
|
|
344
189
|
|
|
345
190
|
```
|
|
346
191
|
|
|
347
|
-
<a name="table-
|
|
348
|
-
|
|
192
|
+
<a name="table-api-table-1-config-drawhorizontalline"></a>
|
|
193
|
+
##### config.drawHorizontalLine
|
|
349
194
|
|
|
350
|
-
|
|
195
|
+
Type: `(lineIndex: number, rowCount: number) => boolean`\
|
|
196
|
+
Default: `() => true`
|
|
351
197
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
options;
|
|
198
|
+
It is used to tell whether to draw a horizontal line. This callback is called for each horizontal border of the table.
|
|
199
|
+
If the table has `n` rows, then the `index` parameter is alternatively received all numbers in range `[0, n]` inclusively.
|
|
200
|
+
If the table has `n` rows and contains the header, then the range will be `[0, n+1]` inclusively.
|
|
356
201
|
|
|
357
|
-
|
|
202
|
+
```js
|
|
203
|
+
const data = [
|
|
358
204
|
['0A', '0B', '0C'],
|
|
359
205
|
['1A', '1B', '1C'],
|
|
360
206
|
['2A', '2B', '2C'],
|
|
@@ -362,21 +208,13 @@ data = [
|
|
|
362
208
|
['4A', '4B', '4C']
|
|
363
209
|
];
|
|
364
210
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
* @param {number} index
|
|
369
|
-
* @param {number} size
|
|
370
|
-
* @return {boolean}
|
|
371
|
-
*/
|
|
372
|
-
drawHorizontalLine: (index, size) => {
|
|
373
|
-
return index === 0 || index === 1 || index === size - 1 || index === size;
|
|
211
|
+
const config = {
|
|
212
|
+
drawHorizontalLine: (lineIndex, rowCount) => {
|
|
213
|
+
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount - 1 || lineIndex === rowCount;
|
|
374
214
|
}
|
|
375
215
|
};
|
|
376
216
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
console.log(output);
|
|
217
|
+
console.log(table(data, config));
|
|
380
218
|
|
|
381
219
|
```
|
|
382
220
|
|
|
@@ -393,17 +231,15 @@ console.log(output);
|
|
|
393
231
|
|
|
394
232
|
```
|
|
395
233
|
|
|
396
|
-
<a name="table-
|
|
397
|
-
|
|
234
|
+
<a name="table-api-table-1-config-singleline"></a>
|
|
235
|
+
##### config.singleLine
|
|
398
236
|
|
|
399
|
-
|
|
237
|
+
Type: `boolean`\
|
|
238
|
+
Default: `false`
|
|
400
239
|
|
|
401
|
-
|
|
402
|
-
import {
|
|
403
|
-
table,
|
|
404
|
-
getBorderCharacters
|
|
405
|
-
} from 'table';
|
|
240
|
+
If `true`, horizontal lines inside the table are not drawn. This option also overrides the `config.drawHorizontalLine` if specified.
|
|
406
241
|
|
|
242
|
+
```js
|
|
407
243
|
const data = [
|
|
408
244
|
['-rw-r--r--', '1', 'pandorym', 'staff', '1529', 'May 23 11:25', 'LICENSE'],
|
|
409
245
|
['-rw-r--r--', '1', 'pandorym', 'staff', '16327', 'May 23 11:58', 'README.md'],
|
|
@@ -419,8 +255,7 @@ const config = {
|
|
|
419
255
|
singleLine: true
|
|
420
256
|
};
|
|
421
257
|
|
|
422
|
-
|
|
423
|
-
console.log(output);
|
|
258
|
+
console.log(table(data, config));
|
|
424
259
|
```
|
|
425
260
|
|
|
426
261
|
```
|
|
@@ -436,37 +271,163 @@ console.log(output);
|
|
|
436
271
|
╚═════════════╧═════╧══════════╧═══════╧════════╧══════════════╧═══════════════════╝
|
|
437
272
|
```
|
|
438
273
|
|
|
439
|
-
<a name="table-usage-padding-cell-content"></a>
|
|
440
|
-
### Padding Cell Content
|
|
441
274
|
|
|
442
|
-
|
|
275
|
+
<a name="table-api-table-1-config-columns"></a>
|
|
276
|
+
##### config.columns
|
|
277
|
+
|
|
278
|
+
Type: `Column[] | { [columnIndex: number]: Column }`
|
|
279
|
+
|
|
280
|
+
Column specific configurations.
|
|
281
|
+
|
|
282
|
+
<a name="table-api-table-1-config-columns-config-columns-width"></a>
|
|
283
|
+
###### config.columns[*].width
|
|
284
|
+
|
|
285
|
+
Type: `number`\
|
|
286
|
+
Default: the maximum cell widths of the column
|
|
287
|
+
|
|
288
|
+
Column width (excluding the paddings).
|
|
443
289
|
|
|
444
290
|
```js
|
|
445
|
-
let config,
|
|
446
|
-
data,
|
|
447
|
-
output;
|
|
448
291
|
|
|
449
|
-
data = [
|
|
450
|
-
['0A', '
|
|
292
|
+
const data = [
|
|
293
|
+
['0A', '0B', '0C'],
|
|
451
294
|
['1A', '1B', '1C'],
|
|
452
295
|
['2A', '2B', '2C']
|
|
453
296
|
];
|
|
454
297
|
|
|
455
|
-
config = {
|
|
298
|
+
const config = {
|
|
456
299
|
columns: {
|
|
457
|
-
|
|
300
|
+
1: { width: 10 }
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
console.log(table(data, config));
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
```
|
|
308
|
+
╔════╤════════════╤════╗
|
|
309
|
+
║ 0A │ 0B │ 0C ║
|
|
310
|
+
╟────┼────────────┼────╢
|
|
311
|
+
║ 1A │ 1B │ 1C ║
|
|
312
|
+
╟────┼────────────┼────╢
|
|
313
|
+
║ 2A │ 2B │ 2C ║
|
|
314
|
+
╚════╧════════════╧════╝
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
<a name="table-api-table-1-config-columns-config-columns-alignment"></a>
|
|
318
|
+
###### config.columns[*].alignment
|
|
319
|
+
|
|
320
|
+
Type: `'center' | 'justify' | 'left' | 'right'`\
|
|
321
|
+
Default: `'left'`
|
|
322
|
+
|
|
323
|
+
Cell content horizontal alignment
|
|
324
|
+
|
|
325
|
+
```js
|
|
326
|
+
const data = [
|
|
327
|
+
['0A', '0B', '0C', '0D 0E 0F'],
|
|
328
|
+
['1A', '1B', '1C', '1D 1E 1F'],
|
|
329
|
+
['2A', '2B', '2C', '2D 2E 2F'],
|
|
330
|
+
];
|
|
331
|
+
|
|
332
|
+
const config = {
|
|
333
|
+
columnDefault: {
|
|
334
|
+
width: 10,
|
|
335
|
+
},
|
|
336
|
+
columns: [
|
|
337
|
+
{ alignment: 'left' },
|
|
338
|
+
{ alignment: 'center' },
|
|
339
|
+
{ alignment: 'right' },
|
|
340
|
+
{ alignment: 'justify' }
|
|
341
|
+
],
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
console.log(table(data, config));
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
```
|
|
348
|
+
╔════════════╤════════════╤════════════╤════════════╗
|
|
349
|
+
║ 0A │ 0B │ 0C │ 0D 0E 0F ║
|
|
350
|
+
╟────────────┼────────────┼────────────┼────────────╢
|
|
351
|
+
║ 1A │ 1B │ 1C │ 1D 1E 1F ║
|
|
352
|
+
╟────────────┼────────────┼────────────┼────────────╢
|
|
353
|
+
║ 2A │ 2B │ 2C │ 2D 2E 2F ║
|
|
354
|
+
╚════════════╧════════════╧════════════╧════════════╝
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
<a name="table-api-table-1-config-columns-config-columns-verticalalignment"></a>
|
|
358
|
+
###### config.columns[*].verticalAlignment
|
|
359
|
+
|
|
360
|
+
Type: `'top' | 'middle' | 'bottom'`\
|
|
361
|
+
Default: `'top'`
|
|
362
|
+
|
|
363
|
+
Cell content vertical alignment
|
|
364
|
+
|
|
365
|
+
```js
|
|
366
|
+
const data = [
|
|
367
|
+
['A', 'B', 'C', 'DEF'],
|
|
368
|
+
];
|
|
369
|
+
|
|
370
|
+
const config = {
|
|
371
|
+
columnDefault: {
|
|
372
|
+
width: 1,
|
|
373
|
+
},
|
|
374
|
+
columns: [
|
|
375
|
+
{ verticalAlignment: 'top' },
|
|
376
|
+
{ verticalAlignment: 'middle' },
|
|
377
|
+
{ verticalAlignment: 'bottom' },
|
|
378
|
+
],
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
console.log(table(data, config));
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
```
|
|
385
|
+
╔═══╤═══╤═══╤═══╗
|
|
386
|
+
║ A │ │ │ D ║
|
|
387
|
+
║ │ B │ │ E ║
|
|
388
|
+
║ │ │ C │ F ║
|
|
389
|
+
╚═══╧═══╧═══╧═══╝
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
<a name="table-api-table-1-config-columns-config-columns-paddingleft"></a>
|
|
393
|
+
###### config.columns[*].paddingLeft
|
|
394
|
+
|
|
395
|
+
Type: `number`\
|
|
396
|
+
Default: `1`
|
|
397
|
+
|
|
398
|
+
The number of whitespaces used to pad the content on the left.
|
|
399
|
+
|
|
400
|
+
<a name="table-api-table-1-config-columns-config-columns-paddingright"></a>
|
|
401
|
+
###### config.columns[*].paddingRight
|
|
402
|
+
|
|
403
|
+
Type: `number`\
|
|
404
|
+
Default: `1`
|
|
405
|
+
|
|
406
|
+
The number of whitespaces used to pad the content on the right.
|
|
407
|
+
|
|
408
|
+
The `paddingLeft` and `paddingRight` options do not count on the column width. So the column has `width = 5`, `paddingLeft = 2` and `paddingRight = 2` will have the total width is `9`.
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
```js
|
|
412
|
+
const data = [
|
|
413
|
+
['0A', 'AABBCC', '0C'],
|
|
414
|
+
['1A', '1B', '1C'],
|
|
415
|
+
['2A', '2B', '2C']
|
|
416
|
+
];
|
|
417
|
+
|
|
418
|
+
const config = {
|
|
419
|
+
columns: [
|
|
420
|
+
{
|
|
458
421
|
paddingLeft: 3
|
|
459
422
|
},
|
|
460
|
-
|
|
423
|
+
{
|
|
461
424
|
width: 2,
|
|
462
425
|
paddingRight: 3
|
|
463
426
|
}
|
|
464
|
-
|
|
427
|
+
]
|
|
465
428
|
};
|
|
466
429
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
console.log(output);
|
|
430
|
+
console.log(table(data, config));
|
|
470
431
|
```
|
|
471
432
|
|
|
472
433
|
```
|
|
@@ -481,136 +442,180 @@ console.log(output);
|
|
|
481
442
|
╚══════╧══════╧════╝
|
|
482
443
|
```
|
|
483
444
|
|
|
484
|
-
<a name="table-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
You can load one of the predefined border templates using `getBorderCharacters` function.
|
|
445
|
+
<a name="table-api-table-1-config-columns-config-columns-truncate"></a>
|
|
446
|
+
###### config.columns[*].truncate
|
|
488
447
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
table,
|
|
492
|
-
getBorderCharacters
|
|
493
|
-
} from 'table';
|
|
448
|
+
Type: `number`\
|
|
449
|
+
Default: `Infinity`
|
|
494
450
|
|
|
495
|
-
|
|
496
|
-
|
|
451
|
+
The number of characters is which the content will be truncated.
|
|
452
|
+
To handle a content that overflows the container width, `table` package implements [text wrapping](#config.columns[*].wrapWord). However, sometimes you may want to truncate content that is too long to be displayed in the table.
|
|
497
453
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
['
|
|
501
|
-
['2A', '2B', '2C']
|
|
454
|
+
```js
|
|
455
|
+
const data = [
|
|
456
|
+
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
|
502
457
|
];
|
|
503
458
|
|
|
504
|
-
config = {
|
|
505
|
-
|
|
459
|
+
const config = {
|
|
460
|
+
columns: [
|
|
461
|
+
{
|
|
462
|
+
width: 20,
|
|
463
|
+
truncate: 100
|
|
464
|
+
}
|
|
465
|
+
]
|
|
506
466
|
};
|
|
507
467
|
|
|
508
|
-
table(data, config);
|
|
468
|
+
console.log(table(data, config));
|
|
509
469
|
```
|
|
510
470
|
|
|
511
471
|
```
|
|
512
|
-
|
|
472
|
+
╔══════════════════════╗
|
|
473
|
+
║ Lorem ipsum dolor si ║
|
|
474
|
+
║ t amet, consectetur ║
|
|
475
|
+
║ adipiscing elit. Pha ║
|
|
476
|
+
║ sellus pulvinar nibh ║
|
|
477
|
+
║ sed mauris convall… ║
|
|
478
|
+
╚══════════════════════╝
|
|
479
|
+
```
|
|
513
480
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
╟────┼────┼────╢
|
|
517
|
-
║ 1A │ 1B │ 1C ║
|
|
518
|
-
╟────┼────┼────╢
|
|
519
|
-
║ 2A │ 2B │ 2C ║
|
|
520
|
-
╚════╧════╧════╝
|
|
481
|
+
<a name="table-api-table-1-config-columns-config-columns-wrapword"></a>
|
|
482
|
+
###### config.columns[*].wrapWord
|
|
521
483
|
|
|
522
|
-
|
|
484
|
+
Type: `boolean`\
|
|
485
|
+
Default: `false`
|
|
523
486
|
|
|
524
|
-
|
|
525
|
-
│ 0A │ 0B │ 0C │
|
|
526
|
-
├────┼────┼────┤
|
|
527
|
-
│ 1A │ 1B │ 1C │
|
|
528
|
-
├────┼────┼────┤
|
|
529
|
-
│ 2A │ 2B │ 2C │
|
|
530
|
-
└────┴────┴────┘
|
|
487
|
+
The `table` package implements auto text wrapping, i.e., text that has the width greater than the container width will be separated into multiple lines at the nearest space or one of the special characters: `\|/_.,;-`.
|
|
531
488
|
|
|
532
|
-
|
|
489
|
+
When `wrapWord` is `false`:
|
|
533
490
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|----|----|----|
|
|
539
|
-
| 2A | 2B | 2C |
|
|
540
|
-
+----+----+----+
|
|
491
|
+
```js
|
|
492
|
+
const data = [
|
|
493
|
+
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
|
494
|
+
];
|
|
541
495
|
|
|
542
|
-
|
|
496
|
+
const config = {
|
|
497
|
+
columns: [ { width: 20 } ]
|
|
498
|
+
};
|
|
543
499
|
|
|
544
|
-
|
|
500
|
+
console.log(table(data, config));
|
|
501
|
+
```
|
|
545
502
|
|
|
546
|
-
|
|
503
|
+
```
|
|
504
|
+
╔══════════════════════╗
|
|
505
|
+
║ Lorem ipsum dolor si ║
|
|
506
|
+
║ t amet, consectetur ║
|
|
507
|
+
║ adipiscing elit. Pha ║
|
|
508
|
+
║ sellus pulvinar nibh ║
|
|
509
|
+
║ sed mauris convallis ║
|
|
510
|
+
║ dapibus. Nunc venena ║
|
|
511
|
+
║ tis tempus nulla sit ║
|
|
512
|
+
║ amet viverra. ║
|
|
513
|
+
╚══════════════════════╝
|
|
514
|
+
```
|
|
547
515
|
|
|
548
|
-
|
|
516
|
+
When `wrapWord` is `true`:
|
|
549
517
|
|
|
550
518
|
```
|
|
519
|
+
╔══════════════════════╗
|
|
520
|
+
║ Lorem ipsum dolor ║
|
|
521
|
+
║ sit amet, ║
|
|
522
|
+
║ consectetur ║
|
|
523
|
+
║ adipiscing elit. ║
|
|
524
|
+
║ Phasellus pulvinar ║
|
|
525
|
+
║ nibh sed mauris ║
|
|
526
|
+
║ convallis dapibus. ║
|
|
527
|
+
║ Nunc venenatis ║
|
|
528
|
+
║ tempus nulla sit ║
|
|
529
|
+
║ amet viverra. ║
|
|
530
|
+
╚══════════════════════╝
|
|
551
531
|
|
|
552
|
-
|
|
532
|
+
```
|
|
553
533
|
|
|
554
|
-
<a name="table-usage-predefined-border-templates-borderless-table"></a>
|
|
555
|
-
#### Borderless Table
|
|
556
534
|
|
|
557
|
-
|
|
535
|
+
<a name="table-api-table-1-config-columndefault"></a>
|
|
536
|
+
##### config.columnDefault
|
|
537
|
+
|
|
538
|
+
Type: `Column`\
|
|
539
|
+
Default: `{}`
|
|
540
|
+
|
|
541
|
+
The default configuration for all columns. Column-specific settings will overwrite the default values.
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
<a name="table-api-table-1-config-header"></a>
|
|
545
|
+
##### config.header
|
|
546
|
+
|
|
547
|
+
Type: `object`
|
|
558
548
|
|
|
559
|
-
|
|
549
|
+
Header configuration.
|
|
550
|
+
|
|
551
|
+
The header configuration inherits the most of the column's, except:
|
|
552
|
+
- `content` **{string}**: the header content.
|
|
553
|
+
- `width:` calculate based on the content width automatically.
|
|
554
|
+
- `alignment:` `center` be default.
|
|
555
|
+
- `verticalAlignment:` is not supported.
|
|
556
|
+
- `config.border.topJoin` will be `config.border.topBody` for prettier.
|
|
560
557
|
|
|
561
558
|
```js
|
|
562
|
-
|
|
559
|
+
const data = [
|
|
560
|
+
['0A', '0B', '0C'],
|
|
561
|
+
['1A', '1B', '1C'],
|
|
562
|
+
['2A', '2B', '2C'],
|
|
563
|
+
];
|
|
563
564
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
});
|
|
565
|
+
const config = {
|
|
566
|
+
columnDefault: {
|
|
567
|
+
width: 10,
|
|
568
|
+
},
|
|
569
|
+
header: {
|
|
570
|
+
alignment: 'center',
|
|
571
|
+
content: 'THE HEADER\nThis is the table about something',
|
|
572
|
+
},
|
|
573
|
+
}
|
|
574
574
|
|
|
575
|
-
console.log(
|
|
575
|
+
console.log(table(data, config));
|
|
576
576
|
```
|
|
577
577
|
|
|
578
578
|
```
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
579
|
+
╔══════════════════════════════════════╗
|
|
580
|
+
║ THE HEADER ║
|
|
581
|
+
║ This is the table about something ║
|
|
582
|
+
╟────────────┬────────────┬────────────╢
|
|
583
|
+
║ 0A │ 0B │ 0C ║
|
|
584
|
+
╟────────────┼────────────┼────────────╢
|
|
585
|
+
║ 1A │ 1B │ 1C ║
|
|
586
|
+
╟────────────┼────────────┼────────────╢
|
|
587
|
+
║ 2A │ 2B │ 2C ║
|
|
588
|
+
╚════════════╧════════════╧════════════╝
|
|
582
589
|
```
|
|
583
590
|
|
|
584
|
-
|
|
585
|
-
|
|
591
|
+
|
|
592
|
+
<a name="table-api-createstream"></a>
|
|
593
|
+
### createStream
|
|
586
594
|
|
|
587
595
|
`table` package exports `createStream` function used to draw a table and append rows.
|
|
588
596
|
|
|
589
|
-
|
|
597
|
+
**Parameter:**
|
|
598
|
+
- _**config:**_ the same as `table`'s, except `config.columnDefault.width` and `config.columnCount` must be provided.
|
|
590
599
|
|
|
591
|
-
```js
|
|
592
|
-
import {
|
|
593
|
-
createStream
|
|
594
|
-
} from 'table';
|
|
595
600
|
|
|
596
|
-
|
|
597
|
-
|
|
601
|
+
```js
|
|
602
|
+
import { createStream } from 'table';
|
|
598
603
|
|
|
599
|
-
config = {
|
|
604
|
+
const config = {
|
|
600
605
|
columnDefault: {
|
|
601
606
|
width: 50
|
|
602
607
|
},
|
|
603
608
|
columnCount: 1
|
|
604
609
|
};
|
|
605
610
|
|
|
606
|
-
stream = createStream(config);
|
|
611
|
+
const stream = createStream(config);
|
|
607
612
|
|
|
608
613
|
setInterval(() => {
|
|
609
614
|
stream.write([new Date()]);
|
|
610
615
|
}, 500);
|
|
611
616
|
```
|
|
612
617
|
|
|
613
|
-

|
|
618
|
+

|
|
614
619
|
|
|
615
620
|
`table` package uses ANSI escape codes to overwrite the output of the last line when a new row is printed.
|
|
616
621
|
|
|
@@ -619,38 +624,29 @@ The underlying implementation is explained in this [Stack Overflow answer](http:
|
|
|
619
624
|
Streaming supports all of the configuration properties and functionality of a static table (such as auto text wrapping, alignment and padding), e.g.
|
|
620
625
|
|
|
621
626
|
```js
|
|
622
|
-
import {
|
|
623
|
-
createStream
|
|
624
|
-
} from 'table';
|
|
627
|
+
import { createStream } from 'table';
|
|
625
628
|
|
|
626
629
|
import _ from 'lodash';
|
|
627
630
|
|
|
628
|
-
|
|
629
|
-
stream,
|
|
630
|
-
i;
|
|
631
|
-
|
|
632
|
-
config = {
|
|
631
|
+
const config = {
|
|
633
632
|
columnDefault: {
|
|
634
633
|
width: 50
|
|
635
634
|
},
|
|
636
635
|
columnCount: 3,
|
|
637
|
-
columns:
|
|
638
|
-
|
|
636
|
+
columns: [
|
|
637
|
+
{
|
|
639
638
|
width: 10,
|
|
640
639
|
alignment: 'right'
|
|
641
640
|
},
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
width: 10
|
|
647
|
-
}
|
|
648
|
-
}
|
|
641
|
+
{ alignment: 'center' },
|
|
642
|
+
{ width: 10 }
|
|
643
|
+
|
|
644
|
+
]
|
|
649
645
|
};
|
|
650
646
|
|
|
651
|
-
stream = createStream(config);
|
|
647
|
+
const stream = createStream(config);
|
|
652
648
|
|
|
653
|
-
i = 0;
|
|
649
|
+
let i = 0;
|
|
654
650
|
|
|
655
651
|
setInterval(() => {
|
|
656
652
|
let random;
|
|
@@ -661,126 +657,103 @@ setInterval(() => {
|
|
|
661
657
|
}, 500);
|
|
662
658
|
```
|
|
663
659
|
|
|
664
|
-

|
|
660
|
+

|
|
665
661
|
|
|
666
|
-
<a name="table-usage-text-truncation"></a>
|
|
667
|
-
### Text Truncation
|
|
668
662
|
|
|
669
|
-
|
|
663
|
+
<a name="table-api-getbordercharacters"></a>
|
|
664
|
+
### getBorderCharacters
|
|
670
665
|
|
|
671
|
-
|
|
666
|
+
**Parameter:**
|
|
667
|
+
- **_template_**
|
|
668
|
+
- Type: `'honeywell' | 'norc' | 'ramac' | 'void'`
|
|
669
|
+
- Required: `true`
|
|
670
|
+
|
|
671
|
+
You can load one of the predefined border templates using `getBorderCharacters` function.
|
|
672
672
|
|
|
673
673
|
```js
|
|
674
|
-
|
|
675
|
-
data,
|
|
676
|
-
output;
|
|
674
|
+
import { table, getBorderCharacters } from 'table';
|
|
677
675
|
|
|
678
|
-
data = [
|
|
679
|
-
['
|
|
676
|
+
const data = [
|
|
677
|
+
['0A', '0B', '0C'],
|
|
678
|
+
['1A', '1B', '1C'],
|
|
679
|
+
['2A', '2B', '2C']
|
|
680
680
|
];
|
|
681
681
|
|
|
682
|
-
config = {
|
|
683
|
-
|
|
684
|
-
0: {
|
|
685
|
-
width: 20,
|
|
686
|
-
truncate: 100
|
|
687
|
-
}
|
|
688
|
-
}
|
|
682
|
+
const config = {
|
|
683
|
+
border: getBorderCharacters(`name of the template`)
|
|
689
684
|
};
|
|
690
685
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
console.log(output);
|
|
686
|
+
console.log(table(data, config));
|
|
694
687
|
```
|
|
695
688
|
|
|
696
689
|
```
|
|
697
|
-
|
|
698
|
-
║ Lorem ipsum dolor si ║
|
|
699
|
-
║ t amet, consectetur ║
|
|
700
|
-
║ adipiscing elit. Pha ║
|
|
701
|
-
║ sellus pulvinar nibh ║
|
|
702
|
-
║ sed mauris convall… ║
|
|
703
|
-
╚══════════════════════╝
|
|
704
|
-
```
|
|
690
|
+
# honeywell
|
|
705
691
|
|
|
706
|
-
|
|
707
|
-
|
|
692
|
+
╔════╤════╤════╗
|
|
693
|
+
║ 0A │ 0B │ 0C ║
|
|
694
|
+
╟────┼────┼────╢
|
|
695
|
+
║ 1A │ 1B │ 1C ║
|
|
696
|
+
╟────┼────┼────╢
|
|
697
|
+
║ 2A │ 2B │ 2C ║
|
|
698
|
+
╚════╧════╧════╝
|
|
708
699
|
|
|
709
|
-
|
|
700
|
+
# norc
|
|
710
701
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
702
|
+
┌────┬────┬────┐
|
|
703
|
+
│ 0A │ 0B │ 0C │
|
|
704
|
+
├────┼────┼────┤
|
|
705
|
+
│ 1A │ 1B │ 1C │
|
|
706
|
+
├────┼────┼────┤
|
|
707
|
+
│ 2A │ 2B │ 2C │
|
|
708
|
+
└────┴────┴────┘
|
|
715
709
|
|
|
716
|
-
|
|
717
|
-
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
|
718
|
-
];
|
|
710
|
+
# ramac (ASCII; for use in terminals that do not support Unicode characters)
|
|
719
711
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
712
|
+
+----+----+----+
|
|
713
|
+
| 0A | 0B | 0C |
|
|
714
|
+
|----|----|----|
|
|
715
|
+
| 1A | 1B | 1C |
|
|
716
|
+
|----|----|----|
|
|
717
|
+
| 2A | 2B | 2C |
|
|
718
|
+
+----+----+----+
|
|
727
719
|
|
|
728
|
-
|
|
720
|
+
# void (no borders; see "borderless table" section of the documentation)
|
|
729
721
|
|
|
730
|
-
|
|
731
|
-
|
|
722
|
+
0A 0B 0C
|
|
723
|
+
|
|
724
|
+
1A 1B 1C
|
|
725
|
+
|
|
726
|
+
2A 2B 2C
|
|
732
727
|
|
|
733
|
-
```
|
|
734
|
-
╔══════════════════════╗
|
|
735
|
-
║ Lorem ipsum dolor si ║
|
|
736
|
-
║ t amet, consectetur ║
|
|
737
|
-
║ adipiscing elit. Pha ║
|
|
738
|
-
║ sellus pulvinar nibh ║
|
|
739
|
-
║ sed mauris convallis ║
|
|
740
|
-
║ dapibus. Nunc venena ║
|
|
741
|
-
║ tis tempus nulla sit ║
|
|
742
|
-
║ amet viverra. ║
|
|
743
|
-
╚══════════════════════╝
|
|
744
728
|
```
|
|
745
729
|
|
|
746
|
-
|
|
730
|
+
Raise [an issue](https://github.com/gajus/table/issues) if you'd like to contribute a new border template.
|
|
747
731
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
data,
|
|
751
|
-
output;
|
|
732
|
+
<a name="table-api-getbordercharacters-borderless-table"></a>
|
|
733
|
+
#### Borderless Table
|
|
752
734
|
|
|
753
|
-
|
|
754
|
-
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
|
755
|
-
];
|
|
735
|
+
Simply using `void` border character template creates a table with a lot of unnecessary spacing.
|
|
756
736
|
|
|
757
|
-
|
|
758
|
-
columns: {
|
|
759
|
-
0: {
|
|
760
|
-
width: 20,
|
|
761
|
-
wrapWord: true
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
};
|
|
737
|
+
To create a more pleasant to the eye table, reset the padding and remove the joining rows, e.g.
|
|
765
738
|
|
|
766
|
-
|
|
739
|
+
```js
|
|
740
|
+
|
|
741
|
+
const output = table(data, {
|
|
742
|
+
border: getBorderCharacters('void'),
|
|
743
|
+
columnDefault: {
|
|
744
|
+
paddingLeft: 0,
|
|
745
|
+
paddingRight: 1
|
|
746
|
+
},
|
|
747
|
+
drawHorizontalLine: () => false
|
|
748
|
+
}
|
|
749
|
+
);
|
|
767
750
|
|
|
768
751
|
console.log(output);
|
|
769
752
|
```
|
|
770
753
|
|
|
771
754
|
```
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
║ consectetur ║
|
|
776
|
-
║ adipiscing elit. ║
|
|
777
|
-
║ Phasellus pulvinar ║
|
|
778
|
-
║ nibh sed mauris ║
|
|
779
|
-
║ convallis dapibus. ║
|
|
780
|
-
║ Nunc venenatis ║
|
|
781
|
-
║ tempus nulla sit ║
|
|
782
|
-
║ amet viverra. ║
|
|
783
|
-
╚══════════════════════╝
|
|
784
|
-
|
|
755
|
+
0A 0B 0C
|
|
756
|
+
1A 1B 1C
|
|
757
|
+
2A 2B 2C
|
|
785
758
|
```
|
|
786
759
|
|