table 4.0.3 → 5.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/LICENSE +1 -1
- package/README.md +10 -6
- package/dist/alignString.js +20 -20
- package/dist/alignString.js.flow +96 -0
- package/dist/alignString.js.map +1 -0
- package/dist/alignTableData.js +12 -11
- package/dist/alignTableData.js.flow +21 -0
- package/dist/alignTableData.js.map +1 -0
- package/dist/calculateCellHeight.js +14 -17
- package/dist/calculateCellHeight.js.flow +29 -0
- package/dist/calculateCellHeight.js.map +1 -0
- package/dist/calculateCellWidthIndex.js +10 -7
- package/dist/calculateCellWidthIndex.js.flow +13 -0
- package/dist/calculateCellWidthIndex.js.map +1 -0
- package/dist/calculateMaximumColumnWidthIndex.js +11 -11
- package/dist/calculateMaximumColumnWidthIndex.js.flow +27 -0
- package/dist/calculateMaximumColumnWidthIndex.js.map +1 -0
- package/dist/calculateRowHeightIndex.js +15 -19
- package/dist/calculateRowHeightIndex.js.flow +35 -0
- package/dist/calculateRowHeightIndex.js.map +1 -0
- package/dist/createStream.js +35 -68
- package/dist/createStream.js.flow +124 -0
- package/dist/createStream.js.map +1 -0
- package/dist/drawBorder.js +16 -8
- package/dist/drawBorder.js.flow +95 -0
- package/dist/drawBorder.js.map +1 -0
- package/dist/drawRow.js +8 -3
- package/dist/drawRow.js.flow +15 -0
- package/dist/drawRow.js.map +1 -0
- package/dist/drawTable.js +11 -12
- package/dist/drawTable.js.flow +52 -0
- package/dist/drawTable.js.map +1 -0
- package/dist/getBorderCharacters.js +8 -15
- package/dist/getBorderCharacters.js.flow +120 -0
- package/dist/getBorderCharacters.js.map +1 -0
- package/dist/index.js +23 -15
- package/dist/index.js.flow +9 -0
- package/dist/index.js.map +1 -0
- package/dist/makeConfig.js +21 -30
- package/dist/makeConfig.js.flow +72 -0
- package/dist/makeConfig.js.map +1 -0
- package/dist/makeStreamConfig.js +19 -27
- package/dist/makeStreamConfig.js.flow +83 -0
- package/dist/makeStreamConfig.js.map +1 -0
- package/dist/mapDataUsingRowHeightIndex.js +17 -22
- package/dist/mapDataUsingRowHeightIndex.js.flow +41 -0
- package/dist/mapDataUsingRowHeightIndex.js.map +1 -0
- package/dist/padTableData.js +8 -4
- package/dist/padTableData.js.flow +14 -0
- package/dist/padTableData.js.map +1 -0
- package/dist/schemas/config.json +1 -1
- package/dist/schemas/streamConfig.json +1 -1
- package/dist/stringifyTableData.js +7 -2
- package/dist/stringifyTableData.js.flow +11 -0
- package/dist/stringifyTableData.js.map +1 -0
- package/dist/table.js +29 -53
- package/dist/table.js.flow +95 -0
- package/dist/table.js.map +1 -0
- package/dist/truncateTableData.js +10 -7
- package/dist/truncateTableData.js.flow +17 -0
- package/dist/truncateTableData.js.map +1 -0
- package/dist/validateConfig.js +4 -5
- package/dist/validateConfig.js.flow +34 -0
- package/dist/validateConfig.js.map +1 -0
- package/dist/validateStreamConfig.js +4 -5
- package/dist/validateTableData.js +62 -15
- package/dist/validateTableData.js.flow +46 -0
- package/dist/validateTableData.js.map +1 -0
- package/dist/wrapString.js +13 -15
- package/dist/wrapString.js.flow +29 -0
- package/dist/wrapString.js.map +1 -0
- package/dist/wrapWord.js +15 -20
- package/dist/wrapWord.js.flow +39 -0
- package/dist/wrapWord.js.map +1 -0
- package/package.json +42 -30
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
<a name="table"></a>
|
|
2
2
|
# Table
|
|
3
3
|
|
|
4
|
-
[](https://travis-ci.org/gajus/table)
|
|
5
|
-
[](https://travis-ci.org/gajus/table)
|
|
5
|
+
[](https://coveralls.io/github/gajus/table)
|
|
6
|
+
[](https://www.npmjs.org/package/table)
|
|
7
|
+
[](https://github.com/gajus/canonical)
|
|
8
|
+
[](https://twitter.com/kuizinas)
|
|
7
9
|
|
|
8
10
|
* [Table](#table)
|
|
9
11
|
* [Features](#table-features)
|
|
@@ -96,7 +98,7 @@ data = [
|
|
|
96
98
|
* Used to dynamically tell table whether to draw a line separating rows or not.
|
|
97
99
|
* The default behavior is to always return true.
|
|
98
100
|
*
|
|
99
|
-
* @typedef {function}
|
|
101
|
+
* @typedef {function} drawHorizontalLine
|
|
100
102
|
* @param {number} index
|
|
101
103
|
* @param {number} size
|
|
102
104
|
* @return {boolean}
|
|
@@ -107,7 +109,7 @@ data = [
|
|
|
107
109
|
* @property {table~border} border
|
|
108
110
|
* @property {table~columns[]} columns Column specific configuration.
|
|
109
111
|
* @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
|
|
110
|
-
* @property {table~
|
|
112
|
+
* @property {table~drawHorizontalLine} drawHorizontalLine
|
|
111
113
|
*/
|
|
112
114
|
|
|
113
115
|
/**
|
|
@@ -296,7 +298,7 @@ data = [
|
|
|
296
298
|
|
|
297
299
|
options = {
|
|
298
300
|
/**
|
|
299
|
-
* @typedef {function}
|
|
301
|
+
* @typedef {function} drawHorizontalLine
|
|
300
302
|
* @param {number} index
|
|
301
303
|
* @param {number} size
|
|
302
304
|
* @return {boolean}
|
|
@@ -309,6 +311,7 @@ options = {
|
|
|
309
311
|
output = table(data, options);
|
|
310
312
|
|
|
311
313
|
console.log(output);
|
|
314
|
+
|
|
312
315
|
```
|
|
313
316
|
|
|
314
317
|
```
|
|
@@ -321,6 +324,7 @@ console.log(output);
|
|
|
321
324
|
╟────┼────┼────╢
|
|
322
325
|
║ 4A │ 4B │ 4C ║
|
|
323
326
|
╚════╧════╧════╝
|
|
327
|
+
|
|
324
328
|
```
|
|
325
329
|
|
|
326
330
|
<a name="table-usage-padding-cell-content"></a>
|
package/dist/alignString.js
CHANGED
|
@@ -1,58 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _lodash = require(
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var _stringWidth = require('string-width');
|
|
12
|
-
|
|
13
|
-
var _stringWidth2 = _interopRequireDefault(_stringWidth);
|
|
10
|
+
var _stringWidth = _interopRequireDefault(require("string-width"));
|
|
14
11
|
|
|
15
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
13
|
|
|
17
14
|
const alignments = ['left', 'right', 'center'];
|
|
18
|
-
|
|
19
15
|
/**
|
|
20
16
|
* @param {string} subject
|
|
21
17
|
* @param {number} width
|
|
22
18
|
* @returns {string}
|
|
23
19
|
*/
|
|
20
|
+
|
|
24
21
|
const alignLeft = (subject, width) => {
|
|
25
22
|
return subject + ' '.repeat(width);
|
|
26
23
|
};
|
|
27
|
-
|
|
28
24
|
/**
|
|
29
25
|
* @param {string} subject
|
|
30
26
|
* @param {number} width
|
|
31
27
|
* @returns {string}
|
|
32
28
|
*/
|
|
29
|
+
|
|
30
|
+
|
|
33
31
|
const alignRight = (subject, width) => {
|
|
34
32
|
return ' '.repeat(width) + subject;
|
|
35
33
|
};
|
|
36
|
-
|
|
37
34
|
/**
|
|
38
35
|
* @param {string} subject
|
|
39
36
|
* @param {number} width
|
|
40
37
|
* @returns {string}
|
|
41
38
|
*/
|
|
39
|
+
|
|
40
|
+
|
|
42
41
|
const alignCenter = (subject, width) => {
|
|
43
42
|
let halfWidth;
|
|
44
|
-
|
|
45
43
|
halfWidth = width / 2;
|
|
46
44
|
|
|
47
45
|
if (halfWidth % 2 === 0) {
|
|
48
46
|
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
|
|
49
47
|
} else {
|
|
50
48
|
halfWidth = Math.floor(halfWidth);
|
|
51
|
-
|
|
52
49
|
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
|
|
53
50
|
}
|
|
54
51
|
};
|
|
55
|
-
|
|
56
52
|
/**
|
|
57
53
|
* Pads a string to the left and/or right to position the subject
|
|
58
54
|
* text in a desired alignment within a container.
|
|
@@ -63,24 +59,24 @@ const alignCenter = (subject, width) => {
|
|
|
63
59
|
* @returns {string}
|
|
64
60
|
*/
|
|
65
61
|
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
|
|
63
|
+
const alignString = (subject, containerWidth, alignment) => {
|
|
64
|
+
if (!_lodash.default.isString(subject)) {
|
|
68
65
|
throw new TypeError('Subject parameter value must be a string.');
|
|
69
66
|
}
|
|
70
67
|
|
|
71
|
-
if (!
|
|
68
|
+
if (!_lodash.default.isNumber(containerWidth)) {
|
|
72
69
|
throw new TypeError('Container width parameter value must be a number.');
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
const subjectWidth = (0,
|
|
72
|
+
const subjectWidth = (0, _stringWidth.default)(subject);
|
|
76
73
|
|
|
77
74
|
if (subjectWidth > containerWidth) {
|
|
78
75
|
// console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);
|
|
79
|
-
|
|
80
76
|
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
|
81
77
|
}
|
|
82
78
|
|
|
83
|
-
if (!
|
|
79
|
+
if (!_lodash.default.isString(alignment)) {
|
|
84
80
|
throw new TypeError('Alignment parameter value must be a string.');
|
|
85
81
|
}
|
|
86
82
|
|
|
@@ -103,4 +99,8 @@ exports.default = (subject, containerWidth, alignment) => {
|
|
|
103
99
|
}
|
|
104
100
|
|
|
105
101
|
return alignCenter(subject, availableWidth);
|
|
106
|
-
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
var _default = alignString;
|
|
105
|
+
exports.default = _default;
|
|
106
|
+
//# sourceMappingURL=alignString.js.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import stringWidth from 'string-width';
|
|
3
|
+
|
|
4
|
+
const alignments = [
|
|
5
|
+
'left',
|
|
6
|
+
'right',
|
|
7
|
+
'center'
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} subject
|
|
12
|
+
* @param {number} width
|
|
13
|
+
* @returns {string}
|
|
14
|
+
*/
|
|
15
|
+
const alignLeft = (subject, width) => {
|
|
16
|
+
return subject + ' '.repeat(width);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} subject
|
|
21
|
+
* @param {number} width
|
|
22
|
+
* @returns {string}
|
|
23
|
+
*/
|
|
24
|
+
const alignRight = (subject, width) => {
|
|
25
|
+
return ' '.repeat(width) + subject;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} subject
|
|
30
|
+
* @param {number} width
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
const alignCenter = (subject, width) => {
|
|
34
|
+
let halfWidth;
|
|
35
|
+
|
|
36
|
+
halfWidth = width / 2;
|
|
37
|
+
|
|
38
|
+
if (halfWidth % 2 === 0) {
|
|
39
|
+
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
|
|
40
|
+
} else {
|
|
41
|
+
halfWidth = Math.floor(halfWidth);
|
|
42
|
+
|
|
43
|
+
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Pads a string to the left and/or right to position the subject
|
|
49
|
+
* text in a desired alignment within a container.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} subject
|
|
52
|
+
* @param {number} containerWidth
|
|
53
|
+
* @param {string} alignment One of the valid options (left, right, center).
|
|
54
|
+
* @returns {string}
|
|
55
|
+
*/
|
|
56
|
+
export default (subject, containerWidth, alignment) => {
|
|
57
|
+
if (!_.isString(subject)) {
|
|
58
|
+
throw new TypeError('Subject parameter value must be a string.');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!_.isNumber(containerWidth)) {
|
|
62
|
+
throw new TypeError('Container width parameter value must be a number.');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const subjectWidth = stringWidth(subject);
|
|
66
|
+
|
|
67
|
+
if (subjectWidth > containerWidth) {
|
|
68
|
+
// console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);
|
|
69
|
+
|
|
70
|
+
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!_.isString(alignment)) {
|
|
74
|
+
throw new TypeError('Alignment parameter value must be a string.');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (alignments.indexOf(alignment) === -1) {
|
|
78
|
+
throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (subjectWidth === 0) {
|
|
82
|
+
return ' '.repeat(containerWidth);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const availableWidth = containerWidth - subjectWidth;
|
|
86
|
+
|
|
87
|
+
if (alignment === 'left') {
|
|
88
|
+
return alignLeft(subject, availableWidth);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (alignment === 'right') {
|
|
92
|
+
return alignRight(subject, availableWidth);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return alignCenter(subject, availableWidth);
|
|
96
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/alignString.js"],"names":["alignments","alignLeft","subject","width","repeat","alignRight","alignCenter","halfWidth","Math","floor","containerWidth","alignment","_","isString","TypeError","isNumber","subjectWidth","Error","indexOf","availableWidth"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA,MAAMA,UAAU,GAAG,CACjB,MADiB,EAEjB,OAFiB,EAGjB,QAHiB,CAAnB;AAMA;;;;;;AAKA,MAAMC,SAAS,GAAG,CAACC,OAAD,EAAUC,KAAV,KAAoB;AACpC,SAAOD,OAAO,GAAG,IAAIE,MAAJ,CAAWD,KAAX,CAAjB;AACD,CAFD;AAIA;;;;;;;AAKA,MAAME,UAAU,GAAG,CAACH,OAAD,EAAUC,KAAV,KAAoB;AACrC,SAAO,IAAIC,MAAJ,CAAWD,KAAX,IAAoBD,OAA3B;AACD,CAFD;AAIA;;;;;;;AAKA,MAAMI,WAAW,GAAG,CAACJ,OAAD,EAAUC,KAAV,KAAoB;AACtC,MAAII,SAAJ;AAEAA,EAAAA,SAAS,GAAGJ,KAAK,GAAG,CAApB;;AAEA,MAAII,SAAS,GAAG,CAAZ,KAAkB,CAAtB,EAAyB;AACvB,WAAO,IAAIH,MAAJ,CAAWG,SAAX,IAAwBL,OAAxB,GAAkC,IAAIE,MAAJ,CAAWG,SAAX,CAAzC;AACD,GAFD,MAEO;AACLA,IAAAA,SAAS,GAAGC,IAAI,CAACC,KAAL,CAAWF,SAAX,CAAZ;AAEA,WAAO,IAAIH,MAAJ,CAAWG,SAAX,IAAwBL,OAAxB,GAAkC,IAAIE,MAAJ,CAAWG,SAAS,GAAG,CAAvB,CAAzC;AACD;AACF,CAZD;AAcA;;;;;;;;;;;qBASgBL,O,EAASQ,c,EAAgBC,S,KAAc;AACrD,MAAI,CAACC,gBAAEC,QAAF,CAAWX,OAAX,CAAL,EAA0B;AACxB,UAAM,IAAIY,SAAJ,CAAc,2CAAd,CAAN;AACD;;AAED,MAAI,CAACF,gBAAEG,QAAF,CAAWL,cAAX,CAAL,EAAiC;AAC/B,UAAM,IAAII,SAAJ,CAAc,mDAAd,CAAN;AACD;;AAED,QAAME,YAAY,GAAG,0BAAYd,OAAZ,CAArB;;AAEA,MAAIc,YAAY,GAAGN,cAAnB,EAAmC;AACjC;AAEA,UAAM,IAAIO,KAAJ,CAAU,2EAAV,CAAN;AACD;;AAED,MAAI,CAACL,gBAAEC,QAAF,CAAWF,SAAX,CAAL,EAA4B;AAC1B,UAAM,IAAIG,SAAJ,CAAc,6CAAd,CAAN;AACD;;AAED,MAAId,UAAU,CAACkB,OAAX,CAAmBP,SAAnB,MAAkC,CAAC,CAAvC,EAA0C;AACxC,UAAM,IAAIM,KAAJ,CAAU,4FAAV,CAAN;AACD;;AAED,MAAID,YAAY,KAAK,CAArB,EAAwB;AACtB,WAAO,IAAIZ,MAAJ,CAAWM,cAAX,CAAP;AACD;;AAED,QAAMS,cAAc,GAAGT,cAAc,GAAGM,YAAxC;;AAEA,MAAIL,SAAS,KAAK,MAAlB,EAA0B;AACxB,WAAOV,SAAS,CAACC,OAAD,EAAUiB,cAAV,CAAhB;AACD;;AAED,MAAIR,SAAS,KAAK,OAAlB,EAA2B;AACzB,WAAON,UAAU,CAACH,OAAD,EAAUiB,cAAV,CAAjB;AACD;;AAED,SAAOb,WAAW,CAACJ,OAAD,EAAUiB,cAAV,CAAlB;AACD,C","sourcesContent":["import _ from 'lodash';\nimport stringWidth from 'string-width';\n\nconst alignments = [\n 'left',\n 'right',\n 'center'\n];\n\n/**\n * @param {string} subject\n * @param {number} width\n * @returns {string}\n */\nconst alignLeft = (subject, width) => {\n return subject + ' '.repeat(width);\n};\n\n/**\n * @param {string} subject\n * @param {number} width\n * @returns {string}\n */\nconst alignRight = (subject, width) => {\n return ' '.repeat(width) + subject;\n};\n\n/**\n * @param {string} subject\n * @param {number} width\n * @returns {string}\n */\nconst alignCenter = (subject, width) => {\n let halfWidth;\n\n halfWidth = width / 2;\n\n if (halfWidth % 2 === 0) {\n return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);\n } else {\n halfWidth = Math.floor(halfWidth);\n\n return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);\n }\n};\n\n/**\n * Pads a string to the left and/or right to position the subject\n * text in a desired alignment within a container.\n *\n * @param {string} subject\n * @param {number} containerWidth\n * @param {string} alignment One of the valid options (left, right, center).\n * @returns {string}\n */\nexport default (subject, containerWidth, alignment) => {\n if (!_.isString(subject)) {\n throw new TypeError('Subject parameter value must be a string.');\n }\n\n if (!_.isNumber(containerWidth)) {\n throw new TypeError('Container width parameter value must be a number.');\n }\n\n const subjectWidth = stringWidth(subject);\n\n if (subjectWidth > containerWidth) {\n // console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);\n\n throw new Error('Subject parameter value width cannot be greater than the container width.');\n }\n\n if (!_.isString(alignment)) {\n throw new TypeError('Alignment parameter value must be a string.');\n }\n\n if (alignments.indexOf(alignment) === -1) {\n throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');\n }\n\n if (subjectWidth === 0) {\n return ' '.repeat(containerWidth);\n }\n\n const availableWidth = containerWidth - subjectWidth;\n\n if (alignment === 'left') {\n return alignLeft(subject, availableWidth);\n }\n\n if (alignment === 'right') {\n return alignRight(subject, availableWidth);\n }\n\n return alignCenter(subject, availableWidth);\n};\n"],"file":"alignString.js"}
|
package/dist/alignTableData.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _stringWidth = require(
|
|
8
|
+
var _stringWidth = _interopRequireDefault(require("string-width"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var _alignString = require('./alignString');
|
|
12
|
-
|
|
13
|
-
var _alignString2 = _interopRequireDefault(_alignString);
|
|
10
|
+
var _alignString = _interopRequireDefault(require("./alignString"));
|
|
14
11
|
|
|
15
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
13
|
|
|
@@ -19,16 +16,20 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
19
16
|
* @param {Object} config
|
|
20
17
|
* @returns {table~row[]}
|
|
21
18
|
*/
|
|
22
|
-
|
|
19
|
+
const alignTableData = (rows, config) => {
|
|
23
20
|
return rows.map(cells => {
|
|
24
21
|
return cells.map((value, index1) => {
|
|
25
22
|
const column = config.columns[index1];
|
|
26
23
|
|
|
27
|
-
if ((0,
|
|
24
|
+
if ((0, _stringWidth.default)(value) === column.width) {
|
|
28
25
|
return value;
|
|
29
26
|
} else {
|
|
30
|
-
return (0,
|
|
27
|
+
return (0, _alignString.default)(value, column.width, column.alignment);
|
|
31
28
|
}
|
|
32
29
|
});
|
|
33
30
|
});
|
|
34
|
-
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var _default = alignTableData;
|
|
34
|
+
exports.default = _default;
|
|
35
|
+
//# sourceMappingURL=alignTableData.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import stringWidth from 'string-width';
|
|
2
|
+
import alignString from './alignString';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {table~row[]} rows
|
|
6
|
+
* @param {Object} config
|
|
7
|
+
* @returns {table~row[]}
|
|
8
|
+
*/
|
|
9
|
+
export default (rows, config) => {
|
|
10
|
+
return rows.map((cells) => {
|
|
11
|
+
return cells.map((value, index1) => {
|
|
12
|
+
const column = config.columns[index1];
|
|
13
|
+
|
|
14
|
+
if (stringWidth(value) === column.width) {
|
|
15
|
+
return value;
|
|
16
|
+
} else {
|
|
17
|
+
return alignString(value, column.width, column.alignment);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/alignTableData.js"],"names":["rows","config","map","cells","value","index1","column","columns","width","alignment"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;;;;;wBAKgBA,I,EAAMC,M,KAAW;AAC/B,SAAOD,IAAI,CAACE,GAAL,CAAUC,KAAD,IAAW;AACzB,WAAOA,KAAK,CAACD,GAAN,CAAU,CAACE,KAAD,EAAQC,MAAR,KAAmB;AAClC,YAAMC,MAAM,GAAGL,MAAM,CAACM,OAAP,CAAeF,MAAf,CAAf;;AAEA,UAAI,0BAAYD,KAAZ,MAAuBE,MAAM,CAACE,KAAlC,EAAyC;AACvC,eAAOJ,KAAP;AACD,OAFD,MAEO;AACL,eAAO,0BAAYA,KAAZ,EAAmBE,MAAM,CAACE,KAA1B,EAAiCF,MAAM,CAACG,SAAxC,CAAP;AACD;AACF,KARM,CAAP;AASD,GAVM,CAAP;AAWD,C","sourcesContent":["import stringWidth from 'string-width';\nimport alignString from './alignString';\n\n/**\n * @param {table~row[]} rows\n * @param {Object} config\n * @returns {table~row[]}\n */\nexport default (rows, config) => {\n return rows.map((cells) => {\n return cells.map((value, index1) => {\n const column = config.columns[index1];\n\n if (stringWidth(value) === column.width) {\n return value;\n } else {\n return alignString(value, column.width, column.alignment);\n }\n });\n });\n};\n"],"file":"alignTableData.js"}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _lodash = require(
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _stringWidth = _interopRequireDefault(require("string-width"));
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
var _stringWidth2 = _interopRequireDefault(_stringWidth);
|
|
14
|
-
|
|
15
|
-
var _wrapWord = require('./wrapWord');
|
|
16
|
-
|
|
17
|
-
var _wrapWord2 = _interopRequireDefault(_wrapWord);
|
|
12
|
+
var _wrapWord = _interopRequireDefault(require("./wrapWord"));
|
|
18
13
|
|
|
19
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
15
|
|
|
@@ -24,10 +19,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
24
19
|
* @param {boolean} useWrapWord
|
|
25
20
|
* @returns {number}
|
|
26
21
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!_lodash2.default.isString(value)) {
|
|
22
|
+
const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
|
|
23
|
+
if (!_lodash.default.isString(value)) {
|
|
31
24
|
throw new TypeError('Value must be a string.');
|
|
32
25
|
}
|
|
33
26
|
|
|
@@ -40,8 +33,12 @@ exports.default = function (value, columnWidth) {
|
|
|
40
33
|
}
|
|
41
34
|
|
|
42
35
|
if (useWrapWord) {
|
|
43
|
-
return (0,
|
|
36
|
+
return (0, _wrapWord.default)(value, columnWidth).length;
|
|
44
37
|
}
|
|
45
38
|
|
|
46
|
-
return Math.ceil((0,
|
|
47
|
-
};
|
|
39
|
+
return Math.ceil((0, _stringWidth.default)(value) / columnWidth);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var _default = calculateCellHeight;
|
|
43
|
+
exports.default = _default;
|
|
44
|
+
//# sourceMappingURL=calculateCellHeight.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import stringWidth from 'string-width';
|
|
3
|
+
import wrapWord from './wrapWord';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} value
|
|
7
|
+
* @param {number} columnWidth
|
|
8
|
+
* @param {boolean} useWrapWord
|
|
9
|
+
* @returns {number}
|
|
10
|
+
*/
|
|
11
|
+
export default (value, columnWidth, useWrapWord = false) => {
|
|
12
|
+
if (!_.isString(value)) {
|
|
13
|
+
throw new TypeError('Value must be a string.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!Number.isInteger(columnWidth)) {
|
|
17
|
+
throw new TypeError('Column width must be an integer.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (columnWidth < 1) {
|
|
21
|
+
throw new Error('Column width must be greater than 0.');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (useWrapWord) {
|
|
25
|
+
return wrapWord(value, columnWidth).length;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return Math.ceil(stringWidth(value) / columnWidth);
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/calculateCellHeight.js"],"names":["value","columnWidth","useWrapWord","_","isString","TypeError","Number","isInteger","Error","length","Math","ceil"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;;;;;;6BAMgBA,K,EAAOC,W,EAAaC,WAAW,GAAG,K,KAAU;AAC1D,MAAI,CAACC,gBAAEC,QAAF,CAAWJ,KAAX,CAAL,EAAwB;AACtB,UAAM,IAAIK,SAAJ,CAAc,yBAAd,CAAN;AACD;;AAED,MAAI,CAACC,MAAM,CAACC,SAAP,CAAiBN,WAAjB,CAAL,EAAoC;AAClC,UAAM,IAAII,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,MAAIJ,WAAW,GAAG,CAAlB,EAAqB;AACnB,UAAM,IAAIO,KAAJ,CAAU,sCAAV,CAAN;AACD;;AAED,MAAIN,WAAJ,EAAiB;AACf,WAAO,uBAASF,KAAT,EAAgBC,WAAhB,EAA6BQ,MAApC;AACD;;AAED,SAAOC,IAAI,CAACC,IAAL,CAAU,0BAAYX,KAAZ,IAAqBC,WAA/B,CAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport stringWidth from 'string-width';\nimport wrapWord from './wrapWord';\n\n/**\n * @param {string} value\n * @param {number} columnWidth\n * @param {boolean} useWrapWord\n * @returns {number}\n */\nexport default (value, columnWidth, useWrapWord = false) => {\n if (!_.isString(value)) {\n throw new TypeError('Value must be a string.');\n }\n\n if (!Number.isInteger(columnWidth)) {\n throw new TypeError('Column width must be an integer.');\n }\n\n if (columnWidth < 1) {\n throw new Error('Column width must be greater than 0.');\n }\n\n if (useWrapWord) {\n return wrapWord(value, columnWidth).length;\n }\n\n return Math.ceil(stringWidth(value) / columnWidth);\n};\n"],"file":"calculateCellHeight.js"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _stringWidth = require(
|
|
8
|
-
|
|
9
|
-
var _stringWidth2 = _interopRequireDefault(_stringWidth);
|
|
8
|
+
var _stringWidth = _interopRequireDefault(require("string-width"));
|
|
10
9
|
|
|
11
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
11
|
|
|
@@ -16,8 +15,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
16
15
|
* @param {string[]} cells
|
|
17
16
|
* @returns {number[]}
|
|
18
17
|
*/
|
|
19
|
-
|
|
18
|
+
const calculateCellWidthIndex = cells => {
|
|
20
19
|
return cells.map(value => {
|
|
21
|
-
return (0,
|
|
20
|
+
return (0, _stringWidth.default)(value);
|
|
22
21
|
});
|
|
23
|
-
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var _default = calculateCellWidthIndex;
|
|
25
|
+
exports.default = _default;
|
|
26
|
+
//# sourceMappingURL=calculateCellWidthIndex.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import stringWidth from 'string-width';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calculates width of each cell contents.
|
|
5
|
+
*
|
|
6
|
+
* @param {string[]} cells
|
|
7
|
+
* @returns {number[]}
|
|
8
|
+
*/
|
|
9
|
+
export default (cells) => {
|
|
10
|
+
return cells.map((value) => {
|
|
11
|
+
return stringWidth(value);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/calculateCellWidthIndex.js"],"names":["cells","map","value"],"mappings":";;;;;;;AAAA;;;;AAEA;;;;;;gCAMgBA,K,IAAU;AACxB,SAAOA,KAAK,CAACC,GAAN,CAAWC,KAAD,IAAW;AAC1B,WAAO,0BAAYA,KAAZ,CAAP;AACD,GAFM,CAAP;AAGD,C","sourcesContent":["import stringWidth from 'string-width';\n\n/**\n * Calculates width of each cell contents.\n *\n * @param {string[]} cells\n * @returns {number[]}\n */\nexport default (cells) => {\n return cells.map((value) => {\n return stringWidth(value);\n });\n};\n"],"file":"calculateCellWidthIndex.js"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _calculateCellWidthIndex = require(
|
|
8
|
-
|
|
9
|
-
var _calculateCellWidthIndex2 = _interopRequireDefault(_calculateCellWidthIndex);
|
|
8
|
+
var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
|
|
10
9
|
|
|
11
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
11
|
|
|
@@ -16,22 +15,23 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
16
15
|
* @param {Array[]} rows
|
|
17
16
|
* @returns {number[]}
|
|
18
17
|
*/
|
|
19
|
-
|
|
18
|
+
const calculateMaximumColumnWidthIndex = rows => {
|
|
20
19
|
if (!rows[0]) {
|
|
21
20
|
throw new Error('Dataset must have at least one row.');
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
const columns = Array(rows[0].length).fill(0);
|
|
25
|
-
|
|
23
|
+
const columns = new Array(rows[0].length).fill(0);
|
|
26
24
|
rows.forEach(row => {
|
|
27
|
-
const columnWidthIndex = (0,
|
|
28
|
-
|
|
25
|
+
const columnWidthIndex = (0, _calculateCellWidthIndex.default)(row);
|
|
29
26
|
columnWidthIndex.forEach((valueWidth, index0) => {
|
|
30
27
|
if (columns[index0] < valueWidth) {
|
|
31
28
|
columns[index0] = valueWidth;
|
|
32
29
|
}
|
|
33
30
|
});
|
|
34
31
|
});
|
|
35
|
-
|
|
36
32
|
return columns;
|
|
37
|
-
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var _default = calculateMaximumColumnWidthIndex;
|
|
36
|
+
exports.default = _default;
|
|
37
|
+
//# sourceMappingURL=calculateMaximumColumnWidthIndex.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import calculateCellWidthIndex from './calculateCellWidthIndex';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Produces an array of values that describe the largest value length (width) in every column.
|
|
5
|
+
*
|
|
6
|
+
* @param {Array[]} rows
|
|
7
|
+
* @returns {number[]}
|
|
8
|
+
*/
|
|
9
|
+
export default (rows) => {
|
|
10
|
+
if (!rows[0]) {
|
|
11
|
+
throw new Error('Dataset must have at least one row.');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const columns = new Array(rows[0].length).fill(0);
|
|
15
|
+
|
|
16
|
+
rows.forEach((row) => {
|
|
17
|
+
const columnWidthIndex = calculateCellWidthIndex(row);
|
|
18
|
+
|
|
19
|
+
columnWidthIndex.forEach((valueWidth, index0) => {
|
|
20
|
+
if (columns[index0] < valueWidth) {
|
|
21
|
+
columns[index0] = valueWidth;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return columns;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/calculateMaximumColumnWidthIndex.js"],"names":["rows","Error","columns","Array","length","fill","forEach","row","columnWidthIndex","valueWidth","index0"],"mappings":";;;;;;;AAAA;;;;AAEA;;;;;;yCAMgBA,I,IAAS;AACvB,MAAI,CAACA,IAAI,CAAC,CAAD,CAAT,EAAc;AACZ,UAAM,IAAIC,KAAJ,CAAU,qCAAV,CAAN;AACD;;AAED,QAAMC,OAAO,GAAG,IAAIC,KAAJ,CAAUH,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAAlB,EAA0BC,IAA1B,CAA+B,CAA/B,CAAhB;AAEAL,EAAAA,IAAI,CAACM,OAAL,CAAcC,GAAD,IAAS;AACpB,UAAMC,gBAAgB,GAAG,sCAAwBD,GAAxB,CAAzB;AAEAC,IAAAA,gBAAgB,CAACF,OAAjB,CAAyB,CAACG,UAAD,EAAaC,MAAb,KAAwB;AAC/C,UAAIR,OAAO,CAACQ,MAAD,CAAP,GAAkBD,UAAtB,EAAkC;AAChCP,QAAAA,OAAO,CAACQ,MAAD,CAAP,GAAkBD,UAAlB;AACD;AACF,KAJD;AAKD,GARD;AAUA,SAAOP,OAAP;AACD,C","sourcesContent":["import calculateCellWidthIndex from './calculateCellWidthIndex';\n\n/**\n * Produces an array of values that describe the largest value length (width) in every column.\n *\n * @param {Array[]} rows\n * @returns {number[]}\n */\nexport default (rows) => {\n if (!rows[0]) {\n throw new Error('Dataset must have at least one row.');\n }\n\n const columns = new Array(rows[0].length).fill(0);\n\n rows.forEach((row) => {\n const columnWidthIndex = calculateCellWidthIndex(row);\n\n columnWidthIndex.forEach((valueWidth, index0) => {\n if (columns[index0] < valueWidth) {\n columns[index0] = valueWidth;\n }\n });\n });\n\n return columns;\n};\n"],"file":"calculateMaximumColumnWidthIndex.js"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _lodash = require(
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var _calculateCellHeight = require('./calculateCellHeight');
|
|
12
|
-
|
|
13
|
-
var _calculateCellHeight2 = _interopRequireDefault(_calculateCellHeight);
|
|
10
|
+
var _calculateCellHeight = _interopRequireDefault(require("./calculateCellHeight"));
|
|
14
11
|
|
|
15
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
13
|
|
|
@@ -21,28 +18,27 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
18
|
* @param {Object} config
|
|
22
19
|
* @returns {number[]}
|
|
23
20
|
*/
|
|
24
|
-
|
|
21
|
+
const calculateRowHeightIndex = (rows, config) => {
|
|
25
22
|
const tableWidth = rows[0].length;
|
|
26
|
-
|
|
27
23
|
const rowSpanIndex = [];
|
|
28
|
-
|
|
29
24
|
rows.forEach(cells => {
|
|
30
|
-
const cellHeightIndex = Array(tableWidth).fill(1);
|
|
31
|
-
|
|
25
|
+
const cellHeightIndex = new Array(tableWidth).fill(1);
|
|
32
26
|
cells.forEach((value, index1) => {
|
|
33
|
-
if (!
|
|
27
|
+
if (!_lodash.default.isNumber(config.columns[index1].width)) {
|
|
34
28
|
throw new TypeError('column[index].width must be a number.');
|
|
35
29
|
}
|
|
36
30
|
|
|
37
|
-
if (!
|
|
31
|
+
if (!_lodash.default.isBoolean(config.columns[index1].wrapWord)) {
|
|
38
32
|
throw new TypeError('column[index].wrapWord must be a boolean.');
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
cellHeightIndex[index1] = (0,
|
|
35
|
+
cellHeightIndex[index1] = (0, _calculateCellHeight.default)(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
42
36
|
});
|
|
43
|
-
|
|
44
|
-
rowSpanIndex.push(_lodash2.default.max(cellHeightIndex));
|
|
37
|
+
rowSpanIndex.push(_lodash.default.max(cellHeightIndex));
|
|
45
38
|
});
|
|
46
|
-
|
|
47
39
|
return rowSpanIndex;
|
|
48
|
-
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var _default = calculateRowHeightIndex;
|
|
43
|
+
exports.default = _default;
|
|
44
|
+
//# sourceMappingURL=calculateRowHeightIndex.js.map
|