table 6.0.5 → 6.0.9
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 +4 -4
- 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 +3 -6
- package/dist/createStream.js.flow +2 -3
- package/dist/drawBorder.js +1 -2
- package/dist/drawRow.js +1 -2
- package/dist/drawTable.js +1 -2
- package/dist/getBorderCharacters.js +1 -2
- package/dist/index.js +1 -2
- package/dist/makeConfig.js +9 -12
- package/dist/makeConfig.js.flow +6 -6
- package/dist/makeStreamConfig.js +8 -12
- package/dist/makeStreamConfig.js.flow +6 -6
- package/dist/mapDataUsingRowHeightIndex.js +4 -7
- package/dist/mapDataUsingRowHeightIndex.js.flow +3 -3
- package/dist/padTableData.js +1 -2
- package/dist/schemas/config.json +3 -0
- package/dist/stringifyTableData.js +1 -2
- package/dist/table.js +1 -2
- 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 +201 -180
- package/dist/wrapCell.js +1 -2
- package/dist/wrapString.js +1 -2
- package/dist/wrapWord.js +1 -2
- package/package.json +27 -21
- 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)
|
|
@@ -56,8 +55,9 @@ npm install table
|
|
|
56
55
|
Table data is described using an array (rows) of array (cells).
|
|
57
56
|
|
|
58
57
|
```js
|
|
59
|
-
import
|
|
60
|
-
|
|
58
|
+
import {
|
|
59
|
+
table
|
|
60
|
+
} from 'table';
|
|
61
61
|
|
|
62
62
|
// Using commonjs?
|
|
63
63
|
// const {table} = require('table');
|
|
@@ -487,7 +487,7 @@ table(data, config);
|
|
|
487
487
|
| 2A | 2B | 2C |
|
|
488
488
|
+----+----+----+
|
|
489
489
|
|
|
490
|
-
# void (no borders; see "
|
|
490
|
+
# void (no borders; see "bordless table" section of the documentation)
|
|
491
491
|
|
|
492
492
|
0A 0B 0C
|
|
493
493
|
|
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"));
|
|
@@ -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 {
|
|
@@ -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
package/dist/drawRow.js
CHANGED
package/dist/drawTable.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -28,5 +28,4 @@ var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters
|
|
|
28
28
|
|
|
29
29
|
var _table = _interopRequireDefault(require("./table"));
|
|
30
30
|
|
|
31
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
32
|
-
//# sourceMappingURL=index.js.map
|
|
31
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/dist/makeConfig.js
CHANGED
|
@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
|
|
11
|
-
|
|
12
|
-
var _times2 = _interopRequireDefault(require("lodash/times"));
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash.clonedeep"));
|
|
13
9
|
|
|
14
10
|
var _calculateMaximumColumnWidthIndex = _interopRequireDefault(require("./calculateMaximumColumnWidthIndex"));
|
|
15
11
|
|
|
@@ -41,8 +37,9 @@ const makeBorder = (border = {}) => {
|
|
|
41
37
|
|
|
42
38
|
const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
43
39
|
const maximumColumnWidthIndex = (0, _calculateMaximumColumnWidthIndex.default)(rows);
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
|
|
41
|
+
for (let index = 0; index < rows[0].length; index++) {
|
|
42
|
+
if (typeof columns[index] === 'undefined') {
|
|
46
43
|
columns[index] = {};
|
|
47
44
|
}
|
|
48
45
|
|
|
@@ -50,11 +47,12 @@ const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
|
50
47
|
alignment: 'left',
|
|
51
48
|
paddingLeft: 1,
|
|
52
49
|
paddingRight: 1,
|
|
53
|
-
truncate:
|
|
50
|
+
truncate: Number.POSITIVE_INFINITY,
|
|
54
51
|
width: maximumColumnWidthIndex[index],
|
|
55
52
|
wrapWord: false
|
|
56
53
|
}, columnDefault, columns[index]);
|
|
57
|
-
}
|
|
54
|
+
}
|
|
55
|
+
|
|
58
56
|
return columns;
|
|
59
57
|
};
|
|
60
58
|
/**
|
|
@@ -69,7 +67,7 @@ const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
|
69
67
|
|
|
70
68
|
const makeConfig = (rows, userConfig = {}) => {
|
|
71
69
|
(0, _validateConfig.default)('config.json', userConfig);
|
|
72
|
-
const config = (0,
|
|
70
|
+
const config = (0, _lodash.default)(userConfig);
|
|
73
71
|
config.border = makeBorder(config.border);
|
|
74
72
|
config.columns = makeColumns(rows, config.columns, config.columnDefault);
|
|
75
73
|
|
|
@@ -90,5 +88,4 @@ const makeConfig = (rows, userConfig = {}) => {
|
|
|
90
88
|
};
|
|
91
89
|
|
|
92
90
|
var _default = makeConfig;
|
|
93
|
-
exports.default = _default;
|
|
94
|
-
//# sourceMappingURL=makeConfig.js.map
|
|
91
|
+
exports.default = _default;
|
package/dist/makeConfig.js.flow
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cloneDeep from 'lodash.clonedeep';
|
|
2
2
|
import calculateMaximumColumnWidthIndex from './calculateMaximumColumnWidthIndex';
|
|
3
3
|
import getBorderCharacters from './getBorderCharacters';
|
|
4
4
|
import validateConfig from './validateConfig';
|
|
@@ -25,8 +25,8 @@ const makeBorder = (border = {}) => {
|
|
|
25
25
|
const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
26
26
|
const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex(rows);
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
if (
|
|
28
|
+
for (let index = 0; index < rows[0].length; index++) {
|
|
29
|
+
if (typeof columns[index] === 'undefined') {
|
|
30
30
|
columns[index] = {};
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -34,11 +34,11 @@ const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
|
34
34
|
alignment: 'left',
|
|
35
35
|
paddingLeft: 1,
|
|
36
36
|
paddingRight: 1,
|
|
37
|
-
truncate:
|
|
37
|
+
truncate: Number.POSITIVE_INFINITY,
|
|
38
38
|
width: maximumColumnWidthIndex[index],
|
|
39
39
|
wrapWord: false,
|
|
40
40
|
}, columnDefault, columns[index]);
|
|
41
|
-
}
|
|
41
|
+
}
|
|
42
42
|
|
|
43
43
|
return columns;
|
|
44
44
|
};
|
|
@@ -54,7 +54,7 @@ const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
|
54
54
|
export default (rows, userConfig = {}) => {
|
|
55
55
|
validateConfig('config.json', userConfig);
|
|
56
56
|
|
|
57
|
-
const config =
|
|
57
|
+
const config = cloneDeep(userConfig);
|
|
58
58
|
|
|
59
59
|
config.border = makeBorder(config.border);
|
|
60
60
|
config.columns = makeColumns(rows, config.columns, config.columnDefault);
|
package/dist/makeStreamConfig.js
CHANGED
|
@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
|
|
11
|
-
|
|
12
|
-
var _times2 = _interopRequireDefault(require("lodash/times"));
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash.clonedeep"));
|
|
13
9
|
|
|
14
10
|
var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters"));
|
|
15
11
|
|
|
@@ -38,8 +34,8 @@ const makeBorder = (border = {}) => {
|
|
|
38
34
|
|
|
39
35
|
|
|
40
36
|
const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
41
|
-
(0
|
|
42
|
-
if (
|
|
37
|
+
for (let index = 0; index < columnCount; index++) {
|
|
38
|
+
if (typeof columns[index] === 'undefined') {
|
|
43
39
|
columns[index] = {};
|
|
44
40
|
}
|
|
45
41
|
|
|
@@ -47,10 +43,11 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
47
43
|
alignment: 'left',
|
|
48
44
|
paddingLeft: 1,
|
|
49
45
|
paddingRight: 1,
|
|
50
|
-
truncate:
|
|
46
|
+
truncate: Number.POSITIVE_INFINITY,
|
|
51
47
|
wrapWord: false
|
|
52
48
|
}, columnDefault, columns[index]);
|
|
53
|
-
}
|
|
49
|
+
}
|
|
50
|
+
|
|
54
51
|
return columns;
|
|
55
52
|
};
|
|
56
53
|
/**
|
|
@@ -81,7 +78,7 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
81
78
|
|
|
82
79
|
const makeStreamConfig = (userConfig = {}) => {
|
|
83
80
|
(0, _validateConfig.default)('streamConfig.json', userConfig);
|
|
84
|
-
const config = (0,
|
|
81
|
+
const config = (0, _lodash.default)(userConfig);
|
|
85
82
|
|
|
86
83
|
if (!config.columnDefault || !config.columnDefault.width) {
|
|
87
84
|
throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
|
@@ -97,5 +94,4 @@ const makeStreamConfig = (userConfig = {}) => {
|
|
|
97
94
|
};
|
|
98
95
|
|
|
99
96
|
var _default = makeStreamConfig;
|
|
100
|
-
exports.default = _default;
|
|
101
|
-
//# sourceMappingURL=makeStreamConfig.js.map
|
|
97
|
+
exports.default = _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cloneDeep from 'lodash.clonedeep';
|
|
2
2
|
import getBorderCharacters from './getBorderCharacters';
|
|
3
3
|
import validateConfig from './validateConfig';
|
|
4
4
|
|
|
@@ -22,8 +22,8 @@ const makeBorder = (border = {}) => {
|
|
|
22
22
|
* @returns {object}
|
|
23
23
|
*/
|
|
24
24
|
const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
25
|
-
|
|
26
|
-
if (
|
|
25
|
+
for (let index = 0; index < columnCount; index++) {
|
|
26
|
+
if (typeof columns[index] === 'undefined') {
|
|
27
27
|
columns[index] = {};
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -31,10 +31,10 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
31
31
|
alignment: 'left',
|
|
32
32
|
paddingLeft: 1,
|
|
33
33
|
paddingRight: 1,
|
|
34
|
-
truncate:
|
|
34
|
+
truncate: Number.POSITIVE_INFINITY,
|
|
35
35
|
wrapWord: false,
|
|
36
36
|
}, columnDefault, columns[index]);
|
|
37
|
-
}
|
|
37
|
+
}
|
|
38
38
|
|
|
39
39
|
return columns;
|
|
40
40
|
};
|
|
@@ -66,7 +66,7 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
66
66
|
export default (userConfig = {}) => {
|
|
67
67
|
validateConfig('streamConfig.json', userConfig);
|
|
68
68
|
|
|
69
|
-
const config =
|
|
69
|
+
const config = cloneDeep(userConfig);
|
|
70
70
|
|
|
71
71
|
if (!config.columnDefault || !config.columnDefault.width) {
|
|
72
72
|
throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
|
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _times2 = _interopRequireDefault(require("lodash/times"));
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash.flatten"));
|
|
11
9
|
|
|
12
10
|
var _wrapCell = _interopRequireDefault(require("./wrapCell"));
|
|
13
11
|
|
|
@@ -22,7 +20,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
22
20
|
const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
|
|
23
21
|
const tableWidth = unmappedRows[0].length;
|
|
24
22
|
const mappedRows = unmappedRows.map((cells, index0) => {
|
|
25
|
-
const rowHeight = (
|
|
23
|
+
const rowHeight = Array.from(new Array(rowHeightIndex[index0]), () => {
|
|
26
24
|
return new Array(tableWidth).fill('');
|
|
27
25
|
}); // rowHeight
|
|
28
26
|
// [{row index within rowSaw; index2}]
|
|
@@ -36,9 +34,8 @@ const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
|
|
|
36
34
|
});
|
|
37
35
|
return rowHeight;
|
|
38
36
|
});
|
|
39
|
-
return (0,
|
|
37
|
+
return (0, _lodash.default)(mappedRows);
|
|
40
38
|
};
|
|
41
39
|
|
|
42
40
|
var _default = mapDataUsingRowHeightIndex;
|
|
43
|
-
exports.default = _default;
|
|
44
|
-
//# sourceMappingURL=mapDataUsingRowHeightIndex.js.map
|
|
41
|
+
exports.default = _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import flatten from 'lodash.flatten';
|
|
2
2
|
import wrapCell from './wrapCell';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -11,7 +11,7 @@ export default (unmappedRows, rowHeightIndex, config) => {
|
|
|
11
11
|
const tableWidth = unmappedRows[0].length;
|
|
12
12
|
|
|
13
13
|
const mappedRows = unmappedRows.map((cells, index0) => {
|
|
14
|
-
const rowHeight =
|
|
14
|
+
const rowHeight = Array.from(new Array(rowHeightIndex[index0]), () => {
|
|
15
15
|
return new Array(tableWidth).fill('');
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -30,5 +30,5 @@ export default (unmappedRows, rowHeightIndex, config) => {
|
|
|
30
30
|
return rowHeight;
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
return
|
|
33
|
+
return flatten(mappedRows);
|
|
34
34
|
};
|
package/dist/padTableData.js
CHANGED
package/dist/schemas/config.json
CHANGED
package/dist/table.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash.truncate"));
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
@@ -18,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
const truncateTableData = (rows, config) => {
|
|
19
19
|
return rows.map(cells => {
|
|
20
20
|
return cells.map((content, index) => {
|
|
21
|
-
return (0,
|
|
21
|
+
return (0, _lodash.default)(content, {
|
|
22
22
|
length: config.columns[index].truncate
|
|
23
23
|
});
|
|
24
24
|
});
|
|
@@ -26,5 +26,4 @@ const truncateTableData = (rows, config) => {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
var _default = truncateTableData;
|
|
29
|
-
exports.default = _default;
|
|
30
|
-
//# sourceMappingURL=truncateTableData.js.map
|
|
29
|
+
exports.default = _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import truncate from 'lodash.truncate';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @todo Make it work with ASCII content.
|
|
@@ -9,7 +9,7 @@ import _ from 'lodash';
|
|
|
9
9
|
export default (rows, config) => {
|
|
10
10
|
return rows.map((cells) => {
|
|
11
11
|
return cells.map((content, index) => {
|
|
12
|
-
return
|
|
12
|
+
return truncate(content, {
|
|
13
13
|
length: config.columns[index].truncate,
|
|
14
14
|
});
|
|
15
15
|
});
|
package/dist/validateConfig.js
CHANGED
|
@@ -9,8 +9,6 @@ var _validators = _interopRequireDefault(require("../dist/validators"));
|
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
-
// eslint-disable-next-line import/default
|
|
13
|
-
|
|
14
12
|
/**
|
|
15
13
|
* @param {string} schemaId
|
|
16
14
|
* @param {formatData~config} config
|
|
@@ -39,5 +37,4 @@ const validateConfig = (schemaId, config = {}) => {
|
|
|
39
37
|
};
|
|
40
38
|
|
|
41
39
|
var _default = validateConfig;
|
|
42
|
-
exports.default = _default;
|
|
43
|
-
//# sourceMappingURL=validateConfig.js.map
|
|
40
|
+
exports.default = _default;
|