table 6.0.6 → 6.1.0
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 +52 -1
- package/dist/alignString.js +6 -7
- package/dist/alignString.js.flow +5 -4
- package/dist/alignTableData.js +1 -2
- package/dist/calculateCellHeight.js +3 -4
- package/dist/calculateCellHeight.js.flow +2 -2
- package/dist/calculateCellWidthIndex.js +1 -2
- package/dist/calculateMaximumColumnWidthIndex.js +1 -2
- package/dist/calculateRowHeightIndex.js +6 -9
- package/dist/calculateRowHeightIndex.js.flow +5 -4
- package/dist/createStream.js +13 -16
- package/dist/createStream.js.flow +12 -13
- package/dist/drawBorder.js +58 -53
- package/dist/drawBorder.js.flow +43 -55
- package/dist/drawHorizontalContent.js +41 -0
- package/dist/drawHorizontalContent.js.flow +31 -0
- package/dist/drawRow.js +21 -6
- package/dist/drawRow.js.flow +18 -4
- package/dist/drawTable.js +12 -11
- package/dist/drawTable.js.flow +24 -13
- package/dist/getBorderCharacters.js +1 -2
- package/dist/index.js +1 -2
- package/dist/makeConfig.js +19 -13
- package/dist/makeConfig.js.flow +16 -7
- package/dist/makeStreamConfig.js +17 -11
- package/dist/makeStreamConfig.js.flow +14 -5
- package/dist/mapDataUsingRowHeightIndex.js +4 -7
- package/dist/mapDataUsingRowHeightIndex.js.flow +3 -3
- package/dist/padTableData.js +1 -2
- package/dist/schemas/config.json +6 -0
- package/dist/schemas/streamConfig.json +3 -0
- package/dist/stringifyTableData.js +1 -2
- package/dist/table.js +14 -3
- package/dist/table.js.flow +13 -1
- package/dist/truncateTableData.js +3 -4
- package/dist/truncateTableData.js.flow +2 -2
- package/dist/validateConfig.js +1 -4
- package/dist/validateConfig.js.flow +0 -1
- package/dist/validateTableData.js +1 -2
- package/dist/validators.js +247 -186
- package/dist/wrapCell.js +1 -2
- package/dist/wrapString.js +1 -2
- package/dist/wrapWord.js +1 -2
- package/package.json +14 -8
- package/dist/alignString.js.map +0 -1
- package/dist/alignTableData.js.map +0 -1
- package/dist/calculateCellHeight.js.map +0 -1
- package/dist/calculateCellWidthIndex.js.map +0 -1
- package/dist/calculateMaximumColumnWidthIndex.js.map +0 -1
- package/dist/calculateRowHeightIndex.js.map +0 -1
- package/dist/createStream.js.map +0 -1
- package/dist/drawBorder.js.map +0 -1
- package/dist/drawRow.js.map +0 -1
- package/dist/drawTable.js.map +0 -1
- package/dist/getBorderCharacters.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/makeConfig.js.map +0 -1
- package/dist/makeStreamConfig.js.map +0 -1
- package/dist/mapDataUsingRowHeightIndex.js.map +0 -1
- package/dist/padTableData.js.map +0 -1
- package/dist/stringifyTableData.js.map +0 -1
- package/dist/table.js.map +0 -1
- package/dist/truncateTableData.js.map +0 -1
- package/dist/validateConfig.js.map +0 -1
- package/dist/validateTableData.js.map +0 -1
- package/dist/wrapCell.js.map +0 -1
- package/dist/wrapString.js.map +0 -1
- package/dist/wrapWord.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<a name="table"></a>
|
|
2
2
|
# Table
|
|
3
3
|
|
|
4
|
-
[](https://gitspo.com/mentions/gajus/table)
|
|
5
4
|
[](https://travis-ci.org/gajus/table)
|
|
6
5
|
[](https://coveralls.io/github/gajus/table)
|
|
7
6
|
[](https://www.npmjs.org/package/table)
|
|
@@ -15,6 +14,7 @@
|
|
|
15
14
|
* [Cell Content Alignment](#table-usage-cell-content-alignment)
|
|
16
15
|
* [Column Width](#table-usage-column-width)
|
|
17
16
|
* [Custom Border](#table-usage-custom-border)
|
|
17
|
+
* [Draw Vertical Line](#table-usage-draw-vertical-line)
|
|
18
18
|
* [Draw Horizontal Line](#table-usage-draw-horizontal-line)
|
|
19
19
|
* [Single Line Mode](#table-usage-single-line-mode)
|
|
20
20
|
* [Padding Cell Content](#table-usage-padding-cell-content)
|
|
@@ -293,6 +293,57 @@ console.log(output);
|
|
|
293
293
|
└────┴────┴────┘
|
|
294
294
|
```
|
|
295
295
|
|
|
296
|
+
<a name="table-usage-draw-vertical-line"></a>
|
|
297
|
+
### Draw Vertical Line
|
|
298
|
+
|
|
299
|
+
`{function} config.drawVerticalLine` property is a function that is called for every non-content column in the table. The result of the function `{boolean}` determines whether a border is drawn.
|
|
300
|
+
|
|
301
|
+
```js
|
|
302
|
+
let data,
|
|
303
|
+
output,
|
|
304
|
+
options;
|
|
305
|
+
|
|
306
|
+
data = [
|
|
307
|
+
['0A', '0B', '0C'],
|
|
308
|
+
['1A', '1B', '1C'],
|
|
309
|
+
['2A', '2B', '2C'],
|
|
310
|
+
['3A', '3B', '3C'],
|
|
311
|
+
['4A', '4B', '4C']
|
|
312
|
+
];
|
|
313
|
+
|
|
314
|
+
options = {
|
|
315
|
+
/**
|
|
316
|
+
* @typedef {function} drawVerticalLine
|
|
317
|
+
* @param {number} index
|
|
318
|
+
* @param {number} size
|
|
319
|
+
* @return {boolean}
|
|
320
|
+
*/
|
|
321
|
+
drawVerticalLine: (index, size) => {
|
|
322
|
+
return index === 0 || index === size;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
output = table(data, options);
|
|
327
|
+
|
|
328
|
+
console.log(output);
|
|
329
|
+
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
```
|
|
333
|
+
╔════════════╗
|
|
334
|
+
║ 0A 0B 0C ║
|
|
335
|
+
╟────────────╢
|
|
336
|
+
║ 1A 1B 1C ║
|
|
337
|
+
╟────────────╢
|
|
338
|
+
║ 2A 2B 2C ║
|
|
339
|
+
╟────────────╢
|
|
340
|
+
║ 3A 3B 3C ║
|
|
341
|
+
╟────────────╢
|
|
342
|
+
║ 4A 4B 4C ║
|
|
343
|
+
╚════════════╝
|
|
344
|
+
|
|
345
|
+
```
|
|
346
|
+
|
|
296
347
|
<a name="table-usage-draw-horizontal-line"></a>
|
|
297
348
|
### Draw Horizontal Line
|
|
298
349
|
|
package/dist/alignString.js
CHANGED
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _isNumberObject = _interopRequireDefault(require("is-number-object"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _isString = _interopRequireDefault(require("is-string"));
|
|
11
11
|
|
|
12
12
|
var _stringWidth = _interopRequireDefault(require("string-width"));
|
|
13
13
|
|
|
@@ -63,11 +63,11 @@ const alignCenter = (subject, width) => {
|
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
const alignString = (subject, containerWidth, alignment) => {
|
|
66
|
-
if (!(0,
|
|
66
|
+
if (!(0, _isString.default)(subject)) {
|
|
67
67
|
throw new TypeError('Subject parameter value must be a string.');
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
if (!(0,
|
|
70
|
+
if (!(0, _isNumberObject.default)(containerWidth)) {
|
|
71
71
|
throw new TypeError('Container width parameter value must be a number.');
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -78,7 +78,7 @@ const alignString = (subject, containerWidth, alignment) => {
|
|
|
78
78
|
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
if (!(0,
|
|
81
|
+
if (!(0, _isString.default)(alignment)) {
|
|
82
82
|
throw new TypeError('Alignment parameter value must be a string.');
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -104,5 +104,4 @@ const alignString = (subject, containerWidth, alignment) => {
|
|
|
104
104
|
};
|
|
105
105
|
|
|
106
106
|
var _default = alignString;
|
|
107
|
-
exports.default = _default;
|
|
108
|
-
//# sourceMappingURL=alignString.js.map
|
|
107
|
+
exports.default = _default;
|
package/dist/alignString.js.flow
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isNumber from 'is-number-object';
|
|
2
|
+
import isString from 'is-string';
|
|
2
3
|
import stringWidth from 'string-width';
|
|
3
4
|
|
|
4
5
|
const alignments = [
|
|
@@ -54,11 +55,11 @@ const alignCenter = (subject, width) => {
|
|
|
54
55
|
* @returns {string}
|
|
55
56
|
*/
|
|
56
57
|
export default (subject, containerWidth, alignment) => {
|
|
57
|
-
if (!
|
|
58
|
+
if (!isString(subject)) {
|
|
58
59
|
throw new TypeError('Subject parameter value must be a string.');
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
if (!
|
|
62
|
+
if (!isNumber(containerWidth)) {
|
|
62
63
|
throw new TypeError('Container width parameter value must be a number.');
|
|
63
64
|
}
|
|
64
65
|
|
|
@@ -70,7 +71,7 @@ export default (subject, containerWidth, alignment) => {
|
|
|
70
71
|
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
if (!
|
|
74
|
+
if (!isString(alignment)) {
|
|
74
75
|
throw new TypeError('Alignment parameter value must be a string.');
|
|
75
76
|
}
|
|
76
77
|
|
package/dist/alignTableData.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _isString = _interopRequireDefault(require("is-string"));
|
|
9
9
|
|
|
10
10
|
var _wrapCell = _interopRequireDefault(require("./wrapCell"));
|
|
11
11
|
|
|
@@ -18,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
* @returns {number}
|
|
19
19
|
*/
|
|
20
20
|
const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
|
|
21
|
-
if (!(0,
|
|
21
|
+
if (!(0, _isString.default)(value)) {
|
|
22
22
|
throw new TypeError('Value must be a string.');
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -34,5 +34,4 @@ const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
var _default = calculateCellHeight;
|
|
37
|
-
exports.default = _default;
|
|
38
|
-
//# sourceMappingURL=calculateCellHeight.js.map
|
|
37
|
+
exports.default = _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isString from 'is-string';
|
|
2
2
|
import wrapCell from './wrapCell';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -8,7 +8,7 @@ import wrapCell from './wrapCell';
|
|
|
8
8
|
* @returns {number}
|
|
9
9
|
*/
|
|
10
10
|
export default (value, columnWidth, useWrapWord = false) => {
|
|
11
|
-
if (!
|
|
11
|
+
if (!isString(value)) {
|
|
12
12
|
throw new TypeError('Value must be a string.');
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -5,11 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _isBooleanObject = _interopRequireDefault(require("is-boolean-object"));
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _isNumber2 = _interopRequireDefault(require("lodash/isNumber"));
|
|
10
|
+
var _isNumberObject = _interopRequireDefault(require("is-number-object"));
|
|
13
11
|
|
|
14
12
|
var _calculateCellHeight = _interopRequireDefault(require("./calculateCellHeight"));
|
|
15
13
|
|
|
@@ -28,21 +26,20 @@ const calculateRowHeightIndex = (rows, config) => {
|
|
|
28
26
|
rows.forEach(cells => {
|
|
29
27
|
const cellHeightIndex = new Array(tableWidth).fill(1);
|
|
30
28
|
cells.forEach((value, index1) => {
|
|
31
|
-
if (!(0,
|
|
29
|
+
if (!(0, _isNumberObject.default)(config.columns[index1].width)) {
|
|
32
30
|
throw new TypeError('column[index].width must be a number.');
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
if (!(0,
|
|
33
|
+
if (!(0, _isBooleanObject.default)(config.columns[index1].wrapWord)) {
|
|
36
34
|
throw new TypeError('column[index].wrapWord must be a boolean.');
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
cellHeightIndex[index1] = (0, _calculateCellHeight.default)(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
40
38
|
});
|
|
41
|
-
rowSpanIndex.push(
|
|
39
|
+
rowSpanIndex.push(Math.max(...cellHeightIndex));
|
|
42
40
|
});
|
|
43
41
|
return rowSpanIndex;
|
|
44
42
|
};
|
|
45
43
|
|
|
46
44
|
var _default = calculateRowHeightIndex;
|
|
47
|
-
exports.default = _default;
|
|
48
|
-
//# sourceMappingURL=calculateRowHeightIndex.js.map
|
|
45
|
+
exports.default = _default;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isBoolean from 'is-boolean-object';
|
|
2
|
+
import isNumber from 'is-number-object';
|
|
2
3
|
import calculateCellHeight from './calculateCellHeight';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -17,18 +18,18 @@ export default (rows, config) => {
|
|
|
17
18
|
const cellHeightIndex = new Array(tableWidth).fill(1);
|
|
18
19
|
|
|
19
20
|
cells.forEach((value, index1) => {
|
|
20
|
-
if (!
|
|
21
|
+
if (!isNumber(config.columns[index1].width)) {
|
|
21
22
|
throw new TypeError('column[index].width must be a number.');
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
if (!
|
|
25
|
+
if (!isBoolean(config.columns[index1].wrapWord)) {
|
|
25
26
|
throw new TypeError('column[index].wrapWord must be a boolean.');
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
rowSpanIndex.push(
|
|
32
|
+
rowSpanIndex.push(Math.max(...cellHeightIndex));
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
return rowSpanIndex;
|
package/dist/createStream.js
CHANGED
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _mapValues2 = _interopRequireDefault(require("lodash/mapValues"));
|
|
9
|
-
|
|
10
8
|
var _alignTableData = _interopRequireDefault(require("./alignTableData"));
|
|
11
9
|
|
|
12
10
|
var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex"));
|
|
@@ -29,13 +27,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
29
27
|
|
|
30
28
|
/**
|
|
31
29
|
* @param {Array} data
|
|
32
|
-
* @param {
|
|
30
|
+
* @param {streamConfig} config
|
|
33
31
|
* @returns {Array}
|
|
34
32
|
*/
|
|
35
33
|
const prepareData = (data, config) => {
|
|
36
34
|
let rows;
|
|
37
35
|
rows = (0, _stringifyTableData.default)(data);
|
|
38
|
-
rows = (0, _truncateTableData.default)(
|
|
36
|
+
rows = (0, _truncateTableData.default)(rows, config);
|
|
39
37
|
const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config);
|
|
40
38
|
rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config);
|
|
41
39
|
rows = (0, _alignTableData.default)(rows, config);
|
|
@@ -45,7 +43,7 @@ const prepareData = (data, config) => {
|
|
|
45
43
|
/**
|
|
46
44
|
* @param {string[]} row
|
|
47
45
|
* @param {number[]} columnWidthIndex
|
|
48
|
-
* @param {
|
|
46
|
+
* @param {streamConfig} config
|
|
49
47
|
* @returns {undefined}
|
|
50
48
|
*/
|
|
51
49
|
|
|
@@ -53,20 +51,20 @@ const prepareData = (data, config) => {
|
|
|
53
51
|
const create = (row, columnWidthIndex, config) => {
|
|
54
52
|
const rows = prepareData([row], config);
|
|
55
53
|
const body = rows.map(literalRow => {
|
|
56
|
-
return (0, _drawRow.default)(literalRow, config
|
|
54
|
+
return (0, _drawRow.default)(literalRow, config);
|
|
57
55
|
}).join('');
|
|
58
56
|
let output;
|
|
59
57
|
output = '';
|
|
60
|
-
output += (0, _drawBorder.drawBorderTop)(columnWidthIndex, config
|
|
58
|
+
output += (0, _drawBorder.drawBorderTop)(columnWidthIndex, config);
|
|
61
59
|
output += body;
|
|
62
|
-
output += (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config
|
|
60
|
+
output += (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config);
|
|
63
61
|
output = output.trimEnd();
|
|
64
62
|
process.stdout.write(output);
|
|
65
63
|
};
|
|
66
64
|
/**
|
|
67
65
|
* @param {string[]} row
|
|
68
66
|
* @param {number[]} columnWidthIndex
|
|
69
|
-
* @param {
|
|
67
|
+
* @param {streamConfig} config
|
|
70
68
|
* @returns {undefined}
|
|
71
69
|
*/
|
|
72
70
|
|
|
@@ -74,16 +72,16 @@ const create = (row, columnWidthIndex, config) => {
|
|
|
74
72
|
const append = (row, columnWidthIndex, config) => {
|
|
75
73
|
const rows = prepareData([row], config);
|
|
76
74
|
const body = rows.map(literalRow => {
|
|
77
|
-
return (0, _drawRow.default)(literalRow, config
|
|
75
|
+
return (0, _drawRow.default)(literalRow, config);
|
|
78
76
|
}).join('');
|
|
79
77
|
let output = '';
|
|
80
|
-
const bottom = (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config
|
|
78
|
+
const bottom = (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config);
|
|
81
79
|
|
|
82
80
|
if (bottom !== '\n') {
|
|
83
81
|
output = '\r\u001B[K';
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
output += (0, _drawBorder.drawBorderJoin)(columnWidthIndex, config
|
|
84
|
+
output += (0, _drawBorder.drawBorderJoin)(columnWidthIndex, config);
|
|
87
85
|
output += body;
|
|
88
86
|
output += bottom;
|
|
89
87
|
output = output.trimEnd();
|
|
@@ -97,9 +95,9 @@ const append = (row, columnWidthIndex, config) => {
|
|
|
97
95
|
|
|
98
96
|
const createStream = (userConfig = {}) => {
|
|
99
97
|
const config = (0, _makeStreamConfig.default)(userConfig);
|
|
100
|
-
const columnWidthIndex = Object.values(
|
|
98
|
+
const columnWidthIndex = Object.values(config.columns).map(column => {
|
|
101
99
|
return column.width + column.paddingLeft + column.paddingRight;
|
|
102
|
-
})
|
|
100
|
+
});
|
|
103
101
|
let empty;
|
|
104
102
|
empty = true;
|
|
105
103
|
return {
|
|
@@ -123,5 +121,4 @@ const createStream = (userConfig = {}) => {
|
|
|
123
121
|
};
|
|
124
122
|
|
|
125
123
|
var _default = createStream;
|
|
126
|
-
exports.default = _default;
|
|
127
|
-
//# sourceMappingURL=createStream.js.map
|
|
124
|
+
exports.default = _default;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
1
|
import alignTableData from './alignTableData';
|
|
3
2
|
import calculateRowHeightIndex from './calculateRowHeightIndex';
|
|
4
3
|
import {
|
|
@@ -15,7 +14,7 @@ import truncateTableData from './truncateTableData';
|
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* @param {Array} data
|
|
18
|
-
* @param {
|
|
17
|
+
* @param {streamConfig} config
|
|
19
18
|
* @returns {Array}
|
|
20
19
|
*/
|
|
21
20
|
const prepareData = (data, config) => {
|
|
@@ -23,7 +22,7 @@ const prepareData = (data, config) => {
|
|
|
23
22
|
|
|
24
23
|
rows = stringifyTableData(data);
|
|
25
24
|
|
|
26
|
-
rows = truncateTableData(
|
|
25
|
+
rows = truncateTableData(rows, config);
|
|
27
26
|
|
|
28
27
|
const rowHeightIndex = calculateRowHeightIndex(rows, config);
|
|
29
28
|
|
|
@@ -37,23 +36,23 @@ const prepareData = (data, config) => {
|
|
|
37
36
|
/**
|
|
38
37
|
* @param {string[]} row
|
|
39
38
|
* @param {number[]} columnWidthIndex
|
|
40
|
-
* @param {
|
|
39
|
+
* @param {streamConfig} config
|
|
41
40
|
* @returns {undefined}
|
|
42
41
|
*/
|
|
43
42
|
const create = (row, columnWidthIndex, config) => {
|
|
44
43
|
const rows = prepareData([row], config);
|
|
45
44
|
|
|
46
45
|
const body = rows.map((literalRow) => {
|
|
47
|
-
return drawRow(literalRow, config
|
|
46
|
+
return drawRow(literalRow, config);
|
|
48
47
|
}).join('');
|
|
49
48
|
|
|
50
49
|
let output;
|
|
51
50
|
|
|
52
51
|
output = '';
|
|
53
52
|
|
|
54
|
-
output += drawBorderTop(columnWidthIndex, config
|
|
53
|
+
output += drawBorderTop(columnWidthIndex, config);
|
|
55
54
|
output += body;
|
|
56
|
-
output += drawBorderBottom(columnWidthIndex, config
|
|
55
|
+
output += drawBorderBottom(columnWidthIndex, config);
|
|
57
56
|
|
|
58
57
|
output = output.trimEnd();
|
|
59
58
|
|
|
@@ -63,24 +62,24 @@ const create = (row, columnWidthIndex, config) => {
|
|
|
63
62
|
/**
|
|
64
63
|
* @param {string[]} row
|
|
65
64
|
* @param {number[]} columnWidthIndex
|
|
66
|
-
* @param {
|
|
65
|
+
* @param {streamConfig} config
|
|
67
66
|
* @returns {undefined}
|
|
68
67
|
*/
|
|
69
68
|
const append = (row, columnWidthIndex, config) => {
|
|
70
69
|
const rows = prepareData([row], config);
|
|
71
70
|
|
|
72
71
|
const body = rows.map((literalRow) => {
|
|
73
|
-
return drawRow(literalRow, config
|
|
72
|
+
return drawRow(literalRow, config);
|
|
74
73
|
}).join('');
|
|
75
74
|
|
|
76
75
|
let output = '';
|
|
77
|
-
const bottom = drawBorderBottom(columnWidthIndex, config
|
|
76
|
+
const bottom = drawBorderBottom(columnWidthIndex, config);
|
|
78
77
|
|
|
79
78
|
if (bottom !== '\n') {
|
|
80
79
|
output = '\r\u001B[K';
|
|
81
80
|
}
|
|
82
81
|
|
|
83
|
-
output += drawBorderJoin(columnWidthIndex, config
|
|
82
|
+
output += drawBorderJoin(columnWidthIndex, config);
|
|
84
83
|
output += body;
|
|
85
84
|
output += bottom;
|
|
86
85
|
|
|
@@ -96,9 +95,9 @@ const append = (row, columnWidthIndex, config) => {
|
|
|
96
95
|
export default (userConfig = {}) => {
|
|
97
96
|
const config = makeStreamConfig(userConfig);
|
|
98
97
|
|
|
99
|
-
const columnWidthIndex = Object.values(
|
|
98
|
+
const columnWidthIndex = Object.values(config.columns).map((column) => {
|
|
100
99
|
return column.width + column.paddingLeft + column.paddingRight;
|
|
101
|
-
})
|
|
100
|
+
});
|
|
102
101
|
|
|
103
102
|
let empty;
|
|
104
103
|
|
package/dist/drawBorder.js
CHANGED
|
@@ -5,8 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = void 0;
|
|
7
7
|
|
|
8
|
+
var _drawHorizontalContent = _interopRequireDefault(require("./drawHorizontalContent"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
|
-
* @typedef drawBorder~
|
|
13
|
+
* @typedef drawBorder~border
|
|
10
14
|
* @property {string} left
|
|
11
15
|
* @property {string} right
|
|
12
16
|
* @property {string} body
|
|
@@ -15,96 +19,97 @@ exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = expo
|
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
21
|
* @param {number[]} columnSizeIndex
|
|
18
|
-
* @param {
|
|
22
|
+
* @param {object} config
|
|
23
|
+
* @param {drawBorder~border} config.border
|
|
24
|
+
* @param {Function} config.drawVerticalLine
|
|
19
25
|
* @returns {string}
|
|
20
26
|
*/
|
|
21
|
-
const drawBorder = (columnSizeIndex,
|
|
27
|
+
const drawBorder = (columnSizeIndex, {
|
|
28
|
+
border,
|
|
29
|
+
drawVerticalLine
|
|
30
|
+
}) => {
|
|
22
31
|
const columns = columnSizeIndex.map(size => {
|
|
23
|
-
return
|
|
24
|
-
})
|
|
25
|
-
return
|
|
32
|
+
return border.body.repeat(size);
|
|
33
|
+
});
|
|
34
|
+
return (0, _drawHorizontalContent.default)(columns, {
|
|
35
|
+
drawVerticalLine,
|
|
36
|
+
separator: border
|
|
37
|
+
});
|
|
26
38
|
};
|
|
27
|
-
/**
|
|
28
|
-
* @typedef drawBorderTop~parts
|
|
29
|
-
* @property {string} topLeft
|
|
30
|
-
* @property {string} topRight
|
|
31
|
-
* @property {string} topBody
|
|
32
|
-
* @property {string} topJoin
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
39
|
/**
|
|
36
40
|
* @param {number[]} columnSizeIndex
|
|
37
|
-
* @param {
|
|
41
|
+
* @param {table~config} config
|
|
38
42
|
* @returns {string}
|
|
39
43
|
*/
|
|
40
44
|
|
|
41
45
|
|
|
42
46
|
exports.drawBorder = drawBorder;
|
|
43
47
|
|
|
44
|
-
const drawBorderTop = (columnSizeIndex,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const drawBorderTop = (columnSizeIndex, {
|
|
49
|
+
border,
|
|
50
|
+
drawVerticalLine
|
|
51
|
+
}) => {
|
|
52
|
+
const result = drawBorder(columnSizeIndex, {
|
|
53
|
+
border: {
|
|
54
|
+
body: border.topBody,
|
|
55
|
+
join: border.topJoin,
|
|
56
|
+
left: border.topLeft,
|
|
57
|
+
right: border.topRight
|
|
58
|
+
},
|
|
59
|
+
drawVerticalLine
|
|
50
60
|
});
|
|
51
61
|
|
|
52
|
-
if (
|
|
62
|
+
if (result === '\n') {
|
|
53
63
|
return '';
|
|
54
64
|
}
|
|
55
65
|
|
|
56
|
-
return
|
|
66
|
+
return result;
|
|
57
67
|
};
|
|
58
|
-
/**
|
|
59
|
-
* @typedef drawBorderJoin~parts
|
|
60
|
-
* @property {string} joinLeft
|
|
61
|
-
* @property {string} joinRight
|
|
62
|
-
* @property {string} joinBody
|
|
63
|
-
* @property {string} joinJoin
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
68
|
/**
|
|
67
69
|
* @param {number[]} columnSizeIndex
|
|
68
|
-
* @param {
|
|
70
|
+
* @param {table~config} config
|
|
69
71
|
* @returns {string}
|
|
70
72
|
*/
|
|
71
73
|
|
|
72
74
|
|
|
73
75
|
exports.drawBorderTop = drawBorderTop;
|
|
74
76
|
|
|
75
|
-
const drawBorderJoin = (columnSizeIndex,
|
|
77
|
+
const drawBorderJoin = (columnSizeIndex, {
|
|
78
|
+
border,
|
|
79
|
+
drawVerticalLine
|
|
80
|
+
}) => {
|
|
76
81
|
return drawBorder(columnSizeIndex, {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
border: {
|
|
83
|
+
body: border.joinBody,
|
|
84
|
+
join: border.joinJoin,
|
|
85
|
+
left: border.joinLeft,
|
|
86
|
+
right: border.joinRight
|
|
87
|
+
},
|
|
88
|
+
drawVerticalLine
|
|
81
89
|
});
|
|
82
90
|
};
|
|
83
|
-
/**
|
|
84
|
-
* @typedef drawBorderBottom~parts
|
|
85
|
-
* @property {string} topLeft
|
|
86
|
-
* @property {string} topRight
|
|
87
|
-
* @property {string} topBody
|
|
88
|
-
* @property {string} topJoin
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
91
|
/**
|
|
92
92
|
* @param {number[]} columnSizeIndex
|
|
93
|
-
* @param {
|
|
93
|
+
* @param {table~config} config
|
|
94
94
|
* @returns {string}
|
|
95
95
|
*/
|
|
96
96
|
|
|
97
97
|
|
|
98
98
|
exports.drawBorderJoin = drawBorderJoin;
|
|
99
99
|
|
|
100
|
-
const drawBorderBottom = (columnSizeIndex,
|
|
100
|
+
const drawBorderBottom = (columnSizeIndex, {
|
|
101
|
+
border,
|
|
102
|
+
drawVerticalLine
|
|
103
|
+
}) => {
|
|
101
104
|
return drawBorder(columnSizeIndex, {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
border: {
|
|
106
|
+
body: border.bottomBody,
|
|
107
|
+
join: border.bottomJoin,
|
|
108
|
+
left: border.bottomLeft,
|
|
109
|
+
right: border.bottomRight
|
|
110
|
+
},
|
|
111
|
+
drawVerticalLine
|
|
106
112
|
});
|
|
107
113
|
};
|
|
108
114
|
|
|
109
|
-
exports.drawBorderBottom = drawBorderBottom;
|
|
110
|
-
//# sourceMappingURL=drawBorder.js.map
|
|
115
|
+
exports.drawBorderBottom = drawBorderBottom;
|