table 6.0.2 → 6.0.3
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/dist/alignString.js +7 -3
- package/dist/alignString.js.flow +4 -3
- package/dist/alignString.js.map +1 -1
- package/dist/calculateCellHeight.js +3 -1
- package/dist/calculateCellHeight.js.flow +2 -1
- package/dist/calculateCellHeight.js.map +1 -1
- package/dist/calculateRowHeightIndex.js +9 -3
- package/dist/calculateRowHeightIndex.js.flow +4 -3
- package/dist/calculateRowHeightIndex.js.map +1 -1
- package/dist/createStream.js +12 -5
- package/dist/createStream.js.flow +6 -4
- package/dist/createStream.js.map +1 -1
- package/dist/makeConfig.js +10 -14
- package/dist/makeConfig.js.flow +5 -4
- package/dist/makeConfig.js.map +1 -1
- package/dist/makeStreamConfig.js +10 -14
- package/dist/makeStreamConfig.js.flow +5 -6
- package/dist/makeStreamConfig.js.map +1 -1
- package/dist/mapDataUsingRowHeightIndex.js +7 -6
- package/dist/mapDataUsingRowHeightIndex.js.flow +3 -3
- package/dist/mapDataUsingRowHeightIndex.js.map +1 -1
- package/dist/truncateTableData.js +7 -6
- package/dist/truncateTableData.js.flow +4 -4
- package/dist/truncateTableData.js.map +1 -1
- package/package.json +3 -1
package/dist/alignString.js
CHANGED
|
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _isNumber2 = _interopRequireDefault(require("lodash/isNumber"));
|
|
9
|
+
|
|
10
|
+
var _isString2 = _interopRequireDefault(require("lodash/isString"));
|
|
11
|
+
|
|
8
12
|
var _stringWidth = _interopRequireDefault(require("string-width"));
|
|
9
13
|
|
|
10
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -59,11 +63,11 @@ const alignCenter = (subject, width) => {
|
|
|
59
63
|
|
|
60
64
|
|
|
61
65
|
const alignString = (subject, containerWidth, alignment) => {
|
|
62
|
-
if (
|
|
66
|
+
if (!(0, _isString2.default)(subject)) {
|
|
63
67
|
throw new TypeError('Subject parameter value must be a string.');
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
if (
|
|
70
|
+
if (!(0, _isNumber2.default)(containerWidth)) {
|
|
67
71
|
throw new TypeError('Container width parameter value must be a number.');
|
|
68
72
|
}
|
|
69
73
|
|
|
@@ -74,7 +78,7 @@ const alignString = (subject, containerWidth, alignment) => {
|
|
|
74
78
|
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
if (
|
|
81
|
+
if (!(0, _isString2.default)(alignment)) {
|
|
78
82
|
throw new TypeError('Alignment parameter value must be a string.');
|
|
79
83
|
}
|
|
80
84
|
|
package/dist/alignString.js.flow
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import stringWidth from 'string-width';
|
|
2
3
|
|
|
3
4
|
const alignments = [
|
|
@@ -53,11 +54,11 @@ const alignCenter = (subject, width) => {
|
|
|
53
54
|
* @returns {string}
|
|
54
55
|
*/
|
|
55
56
|
export default (subject, containerWidth, alignment) => {
|
|
56
|
-
if (
|
|
57
|
+
if (!_.isString(subject)) {
|
|
57
58
|
throw new TypeError('Subject parameter value must be a string.');
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
if (
|
|
61
|
+
if (!_.isNumber(containerWidth)) {
|
|
61
62
|
throw new TypeError('Container width parameter value must be a number.');
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -69,7 +70,7 @@ export default (subject, containerWidth, alignment) => {
|
|
|
69
70
|
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
if (
|
|
73
|
+
if (!_.isString(alignment)) {
|
|
73
74
|
throw new TypeError('Alignment parameter value must be a string.');
|
|
74
75
|
}
|
|
75
76
|
|
package/dist/alignString.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/alignString.js"],"names":["alignments","alignLeft","subject","width","repeat","alignRight","alignCenter","halfWidth","Math","floor","containerWidth","alignment","TypeError","subjectWidth","Error","includes","availableWidth"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/alignString.js"],"names":["alignments","alignLeft","subject","width","repeat","alignRight","alignCenter","halfWidth","Math","floor","containerWidth","alignment","TypeError","subjectWidth","Error","includes","availableWidth"],"mappings":";;;;;;;;;;;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,MAAIA,KAAK,GAAG,CAAR,KAAc,CAAlB,EAAqB;AACnB,WAAO,IAAIC,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,CAAC,wBAAWT,OAAX,CAAL,EAA0B;AACxB,UAAM,IAAIU,SAAJ,CAAc,2CAAd,CAAN;AACD;;AAED,MAAI,CAAC,wBAAWF,cAAX,CAAL,EAAiC;AAC/B,UAAM,IAAIE,SAAJ,CAAc,mDAAd,CAAN;AACD;;AAED,QAAMC,YAAY,GAAG,0BAAYX,OAAZ,CAArB;;AAEA,MAAIW,YAAY,GAAGH,cAAnB,EAAmC;AACjC;AAEA,UAAM,IAAII,KAAJ,CAAU,2EAAV,CAAN;AACD;;AAED,MAAI,CAAC,wBAAWH,SAAX,CAAL,EAA4B;AAC1B,UAAM,IAAIC,SAAJ,CAAc,6CAAd,CAAN;AACD;;AAED,MAAI,CAACZ,UAAU,CAACe,QAAX,CAAoBJ,SAApB,CAAL,EAAqC;AACnC,UAAM,IAAIG,KAAJ,CAAU,4FAAV,CAAN;AACD;;AAED,MAAID,YAAY,KAAK,CAArB,EAAwB;AACtB,WAAO,IAAIT,MAAJ,CAAWM,cAAX,CAAP;AACD;;AAED,QAAMM,cAAc,GAAGN,cAAc,GAAGG,YAAxC;;AAEA,MAAIF,SAAS,KAAK,MAAlB,EAA0B;AACxB,WAAOV,SAAS,CAACC,OAAD,EAAUc,cAAV,CAAhB;AACD;;AAED,MAAIL,SAAS,KAAK,OAAlB,EAA2B;AACzB,WAAON,UAAU,CAACH,OAAD,EAAUc,cAAV,CAAjB;AACD;;AAED,SAAOV,WAAW,CAACJ,OAAD,EAAUc,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 (width % 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.includes(alignment)) {\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"}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _isString2 = _interopRequireDefault(require("lodash/isString"));
|
|
9
|
+
|
|
8
10
|
var _wrapCell = _interopRequireDefault(require("./wrapCell"));
|
|
9
11
|
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -16,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
16
18
|
* @returns {number}
|
|
17
19
|
*/
|
|
18
20
|
const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
|
|
19
|
-
if (
|
|
21
|
+
if (!(0, _isString2.default)(value)) {
|
|
20
22
|
throw new TypeError('Value must be a string.');
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import wrapCell from './wrapCell';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -7,7 +8,7 @@ import wrapCell from './wrapCell';
|
|
|
7
8
|
* @returns {number}
|
|
8
9
|
*/
|
|
9
10
|
export default (value, columnWidth, useWrapWord = false) => {
|
|
10
|
-
if (
|
|
11
|
+
if (!_.isString(value)) {
|
|
11
12
|
throw new TypeError('Value must be a string.');
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/calculateCellHeight.js"],"names":["value","columnWidth","useWrapWord","TypeError","Number","isInteger","Error","length"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/calculateCellHeight.js"],"names":["value","columnWidth","useWrapWord","TypeError","Number","isInteger","Error","length"],"mappings":";;;;;;;;;AACA;;;;AAEA;;;;;;6BAMgBA,K,EAAOC,W,EAAaC,WAAW,GAAG,K,KAAU;AAC1D,MAAI,CAAC,wBAAWF,KAAX,CAAL,EAAwB;AACtB,UAAM,IAAIG,SAAJ,CAAc,yBAAd,CAAN;AACD;;AAED,MAAI,CAACC,MAAM,CAACC,SAAP,CAAiBJ,WAAjB,CAAL,EAAoC;AAClC,UAAM,IAAIE,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,MAAIF,WAAW,GAAG,CAAlB,EAAqB;AACnB,UAAM,IAAIK,KAAJ,CAAU,sCAAV,CAAN;AACD;;AAED,SAAO,uBAASN,KAAT,EAAgBC,WAAhB,EAA6BC,WAA7B,EAA0CK,MAAjD;AACD,C","sourcesContent":["import _ from 'lodash';\nimport wrapCell from './wrapCell';\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 return wrapCell(value, columnWidth, useWrapWord).length;\n};\n"],"file":"calculateCellHeight.js"}
|
|
@@ -5,6 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _max2 = _interopRequireDefault(require("lodash/max"));
|
|
9
|
+
|
|
10
|
+
var _isBoolean2 = _interopRequireDefault(require("lodash/isBoolean"));
|
|
11
|
+
|
|
12
|
+
var _isNumber2 = _interopRequireDefault(require("lodash/isNumber"));
|
|
13
|
+
|
|
8
14
|
var _calculateCellHeight = _interopRequireDefault(require("./calculateCellHeight"));
|
|
9
15
|
|
|
10
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -22,17 +28,17 @@ const calculateRowHeightIndex = (rows, config) => {
|
|
|
22
28
|
rows.forEach(cells => {
|
|
23
29
|
const cellHeightIndex = new Array(tableWidth).fill(1);
|
|
24
30
|
cells.forEach((value, index1) => {
|
|
25
|
-
if (
|
|
31
|
+
if (!(0, _isNumber2.default)(config.columns[index1].width)) {
|
|
26
32
|
throw new TypeError('column[index].width must be a number.');
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
if (
|
|
35
|
+
if (!(0, _isBoolean2.default)(config.columns[index1].wrapWord)) {
|
|
30
36
|
throw new TypeError('column[index].wrapWord must be a boolean.');
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
cellHeightIndex[index1] = (0, _calculateCellHeight.default)(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
34
40
|
});
|
|
35
|
-
rowSpanIndex.push(
|
|
41
|
+
rowSpanIndex.push((0, _max2.default)(cellHeightIndex));
|
|
36
42
|
});
|
|
37
43
|
return rowSpanIndex;
|
|
38
44
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import calculateCellHeight from './calculateCellHeight';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -16,18 +17,18 @@ export default (rows, config) => {
|
|
|
16
17
|
const cellHeightIndex = new Array(tableWidth).fill(1);
|
|
17
18
|
|
|
18
19
|
cells.forEach((value, index1) => {
|
|
19
|
-
if (
|
|
20
|
+
if (!_.isNumber(config.columns[index1].width)) {
|
|
20
21
|
throw new TypeError('column[index].width must be a number.');
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
if (
|
|
24
|
+
if (!_.isBoolean(config.columns[index1].wrapWord)) {
|
|
24
25
|
throw new TypeError('column[index].wrapWord must be a boolean.');
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
28
29
|
});
|
|
29
30
|
|
|
30
|
-
rowSpanIndex.push(
|
|
31
|
+
rowSpanIndex.push(_.max(cellHeightIndex));
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
return rowSpanIndex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/calculateRowHeightIndex.js"],"names":["rows","config","tableWidth","length","rowSpanIndex","forEach","cells","cellHeightIndex","Array","fill","value","index1","columns","width","TypeError","wrapWord","push"
|
|
1
|
+
{"version":3,"sources":["../src/calculateRowHeightIndex.js"],"names":["rows","config","tableWidth","length","rowSpanIndex","forEach","cells","cellHeightIndex","Array","fill","value","index1","columns","width","TypeError","wrapWord","push"],"mappings":";;;;;;;;;;;;;AACA;;;;AAEA;;;;;;;iCAOgBA,I,EAAMC,M,KAAW;AAC/B,QAAMC,UAAU,GAAGF,IAAI,CAAC,CAAD,CAAJ,CAAQG,MAA3B;AAEA,QAAMC,YAAY,GAAG,EAArB;AAEAJ,EAAAA,IAAI,CAACK,OAAL,CAAcC,KAAD,IAAW;AACtB,UAAMC,eAAe,GAAG,IAAIC,KAAJ,CAAUN,UAAV,EAAsBO,IAAtB,CAA2B,CAA3B,CAAxB;AAEAH,IAAAA,KAAK,CAACD,OAAN,CAAc,CAACK,KAAD,EAAQC,MAAR,KAAmB;AAC/B,UAAI,CAAC,wBAAWV,MAAM,CAACW,OAAP,CAAeD,MAAf,EAAuBE,KAAlC,CAAL,EAA+C;AAC7C,cAAM,IAAIC,SAAJ,CAAc,uCAAd,CAAN;AACD;;AAED,UAAI,CAAC,yBAAYb,MAAM,CAACW,OAAP,CAAeD,MAAf,EAAuBI,QAAnC,CAAL,EAAmD;AACjD,cAAM,IAAID,SAAJ,CAAc,2CAAd,CAAN;AACD;;AAEDP,MAAAA,eAAe,CAACI,MAAD,CAAf,GAA0B,kCAAoBD,KAApB,EAA2BT,MAAM,CAACW,OAAP,CAAeD,MAAf,EAAuBE,KAAlD,EAAyDZ,MAAM,CAACW,OAAP,CAAeD,MAAf,EAAuBI,QAAhF,CAA1B;AACD,KAVD;AAYAX,IAAAA,YAAY,CAACY,IAAb,CAAkB,mBAAMT,eAAN,CAAlB;AACD,GAhBD;AAkBA,SAAOH,YAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport calculateCellHeight from './calculateCellHeight';\n\n/**\n * Calculates the vertical row span index.\n *\n * @param {Array[]} rows\n * @param {object} config\n * @returns {number[]}\n */\nexport default (rows, config) => {\n const tableWidth = rows[0].length;\n\n const rowSpanIndex = [];\n\n rows.forEach((cells) => {\n const cellHeightIndex = new Array(tableWidth).fill(1);\n\n cells.forEach((value, index1) => {\n if (!_.isNumber(config.columns[index1].width)) {\n throw new TypeError('column[index].width must be a number.');\n }\n\n if (!_.isBoolean(config.columns[index1].wrapWord)) {\n throw new TypeError('column[index].wrapWord must be a boolean.');\n }\n\n cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);\n });\n\n rowSpanIndex.push(_.max(cellHeightIndex));\n });\n\n return rowSpanIndex;\n};\n"],"file":"calculateRowHeightIndex.js"}
|
package/dist/createStream.js
CHANGED
|
@@ -5,6 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _mapValues2 = _interopRequireDefault(require("lodash/mapValues"));
|
|
9
|
+
|
|
10
|
+
var _values2 = _interopRequireDefault(require("lodash/values"));
|
|
11
|
+
|
|
12
|
+
var _trimEnd2 = _interopRequireDefault(require("lodash/trimEnd"));
|
|
13
|
+
|
|
8
14
|
var _alignTableData = _interopRequireDefault(require("./alignTableData"));
|
|
9
15
|
|
|
10
16
|
var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex"));
|
|
@@ -58,7 +64,7 @@ const create = (row, columnWidthIndex, config) => {
|
|
|
58
64
|
output += (0, _drawBorder.drawBorderTop)(columnWidthIndex, config.border);
|
|
59
65
|
output += body;
|
|
60
66
|
output += (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config.border);
|
|
61
|
-
output =
|
|
67
|
+
output = (0, _trimEnd2.default)(output);
|
|
62
68
|
process.stdout.write(output);
|
|
63
69
|
};
|
|
64
70
|
/**
|
|
@@ -84,7 +90,7 @@ const append = (row, columnWidthIndex, config) => {
|
|
|
84
90
|
output += (0, _drawBorder.drawBorderJoin)(columnWidthIndex, config.border);
|
|
85
91
|
output += body;
|
|
86
92
|
output += bottom;
|
|
87
|
-
output =
|
|
93
|
+
output = (0, _trimEnd2.default)(output);
|
|
88
94
|
process.stdout.write(output);
|
|
89
95
|
};
|
|
90
96
|
/**
|
|
@@ -94,10 +100,11 @@ const append = (row, columnWidthIndex, config) => {
|
|
|
94
100
|
|
|
95
101
|
|
|
96
102
|
const createStream = (userConfig = {}) => {
|
|
97
|
-
const config = (0, _makeStreamConfig.default)(userConfig);
|
|
98
|
-
|
|
103
|
+
const config = (0, _makeStreamConfig.default)(userConfig); // @todo Use 'Object.values' when Node.js v6 support is dropped.
|
|
104
|
+
|
|
105
|
+
const columnWidthIndex = (0, _values2.default)((0, _mapValues2.default)(config.columns, column => {
|
|
99
106
|
return column.width + column.paddingLeft + column.paddingRight;
|
|
100
|
-
});
|
|
107
|
+
}));
|
|
101
108
|
let empty;
|
|
102
109
|
empty = true;
|
|
103
110
|
return {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import alignTableData from './alignTableData';
|
|
2
3
|
import calculateRowHeightIndex from './calculateRowHeightIndex';
|
|
3
4
|
import {
|
|
@@ -54,7 +55,7 @@ const create = (row, columnWidthIndex, config) => {
|
|
|
54
55
|
output += body;
|
|
55
56
|
output += drawBorderBottom(columnWidthIndex, config.border);
|
|
56
57
|
|
|
57
|
-
output =
|
|
58
|
+
output = _.trimEnd(output);
|
|
58
59
|
|
|
59
60
|
process.stdout.write(output);
|
|
60
61
|
};
|
|
@@ -83,7 +84,7 @@ const append = (row, columnWidthIndex, config) => {
|
|
|
83
84
|
output += body;
|
|
84
85
|
output += bottom;
|
|
85
86
|
|
|
86
|
-
output =
|
|
87
|
+
output = _.trimEnd(output);
|
|
87
88
|
|
|
88
89
|
process.stdout.write(output);
|
|
89
90
|
};
|
|
@@ -95,9 +96,10 @@ const append = (row, columnWidthIndex, config) => {
|
|
|
95
96
|
export default (userConfig = {}) => {
|
|
96
97
|
const config = makeStreamConfig(userConfig);
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
// @todo Use 'Object.values' when Node.js v6 support is dropped.
|
|
100
|
+
const columnWidthIndex = _.values(_.mapValues(config.columns, (column) => {
|
|
99
101
|
return column.width + column.paddingLeft + column.paddingRight;
|
|
100
|
-
});
|
|
102
|
+
}));
|
|
101
103
|
|
|
102
104
|
let empty;
|
|
103
105
|
|
package/dist/createStream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createStream.js"],"names":["prepareData","data","config","rows","rowHeightIndex","create","row","columnWidthIndex","body","map","literalRow","border","join","output","
|
|
1
|
+
{"version":3,"sources":["../src/createStream.js"],"names":["prepareData","data","config","rows","rowHeightIndex","create","row","columnWidthIndex","body","map","literalRow","border","join","output","process","stdout","write","append","bottom","userConfig","columns","column","width","paddingLeft","paddingRight","empty","length","columnCount","Error"],"mappings":"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","sourcesContent":["import _ from 'lodash';\nimport alignTableData from './alignTableData';\nimport calculateRowHeightIndex from './calculateRowHeightIndex';\nimport {\n drawBorderBottom,\n drawBorderJoin,\n drawBorderTop,\n} from './drawBorder';\nimport drawRow from './drawRow';\nimport makeStreamConfig from './makeStreamConfig';\nimport mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';\nimport padTableData from './padTableData';\nimport stringifyTableData from './stringifyTableData';\nimport truncateTableData from './truncateTableData';\n\n/**\n * @param {Array} data\n * @param {object} config\n * @returns {Array}\n */\nconst prepareData = (data, config) => {\n let rows;\n\n rows = stringifyTableData(data);\n\n rows = truncateTableData(data, config);\n\n const rowHeightIndex = calculateRowHeightIndex(rows, config);\n\n rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);\n rows = alignTableData(rows, config);\n rows = padTableData(rows, config);\n\n return rows;\n};\n\n/**\n * @param {string[]} row\n * @param {number[]} columnWidthIndex\n * @param {object} config\n * @returns {undefined}\n */\nconst create = (row, columnWidthIndex, config) => {\n const rows = prepareData([row], config);\n\n const body = rows.map((literalRow) => {\n return drawRow(literalRow, config.border);\n }).join('');\n\n let output;\n\n output = '';\n\n output += drawBorderTop(columnWidthIndex, config.border);\n output += body;\n output += drawBorderBottom(columnWidthIndex, config.border);\n\n output = _.trimEnd(output);\n\n process.stdout.write(output);\n};\n\n/**\n * @param {string[]} row\n * @param {number[]} columnWidthIndex\n * @param {object} config\n * @returns {undefined}\n */\nconst append = (row, columnWidthIndex, config) => {\n const rows = prepareData([row], config);\n\n const body = rows.map((literalRow) => {\n return drawRow(literalRow, config.border);\n }).join('');\n\n let output = '';\n const bottom = drawBorderBottom(columnWidthIndex, config.border);\n\n if (bottom !== '\\n') {\n output = '\\r\\u001B[K';\n }\n\n output += drawBorderJoin(columnWidthIndex, config.border);\n output += body;\n output += bottom;\n\n output = _.trimEnd(output);\n\n process.stdout.write(output);\n};\n\n/**\n * @param {object} userConfig\n * @returns {object}\n */\nexport default (userConfig = {}) => {\n const config = makeStreamConfig(userConfig);\n\n // @todo Use 'Object.values' when Node.js v6 support is dropped.\n const columnWidthIndex = _.values(_.mapValues(config.columns, (column) => {\n return column.width + column.paddingLeft + column.paddingRight;\n }));\n\n let empty;\n\n empty = true;\n\n return {\n /**\n * @param {string[]} row\n * @returns {undefined}\n */\n write: (row) => {\n if (row.length !== config.columnCount) {\n throw new Error('Row cell count does not match the config.columnCount.');\n }\n\n if (empty) {\n empty = false;\n\n return create(row, columnWidthIndex, config);\n } else {\n return append(row, columnWidthIndex, config);\n }\n },\n };\n};\n"],"file":"createStream.js"}
|
package/dist/makeConfig.js
CHANGED
|
@@ -5,6 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
9
|
+
|
|
10
|
+
var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
|
|
11
|
+
|
|
12
|
+
var _times2 = _interopRequireDefault(require("lodash/times"));
|
|
13
|
+
|
|
8
14
|
var _calculateMaximumColumnWidthIndex = _interopRequireDefault(require("./calculateMaximumColumnWidthIndex"));
|
|
9
15
|
|
|
10
16
|
var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters"));
|
|
@@ -13,12 +19,6 @@ var _validateConfig = _interopRequireDefault(require("./validateConfig"));
|
|
|
13
19
|
|
|
14
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
21
|
|
|
16
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
-
|
|
20
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
-
|
|
22
22
|
/**
|
|
23
23
|
* Merges user provided border characters with the default border ("honeywell") characters.
|
|
24
24
|
*
|
|
@@ -41,9 +41,8 @@ const makeBorder = (border = {}) => {
|
|
|
41
41
|
|
|
42
42
|
const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
43
43
|
const maximumColumnWidthIndex = (0, _calculateMaximumColumnWidthIndex.default)(rows);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (!columns[index]) {
|
|
44
|
+
(0, _times2.default)(rows[0].length, index => {
|
|
45
|
+
if ((0, _isUndefined2.default)(columns[index])) {
|
|
47
46
|
columns[index] = {};
|
|
48
47
|
}
|
|
49
48
|
|
|
@@ -55,8 +54,7 @@ const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
|
55
54
|
width: maximumColumnWidthIndex[index],
|
|
56
55
|
wrapWord: false
|
|
57
56
|
}, columnDefault, columns[index]);
|
|
58
|
-
}
|
|
59
|
-
|
|
57
|
+
});
|
|
60
58
|
return columns;
|
|
61
59
|
};
|
|
62
60
|
/**
|
|
@@ -71,9 +69,7 @@ const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
|
71
69
|
|
|
72
70
|
const makeConfig = (rows, userConfig = {}) => {
|
|
73
71
|
(0, _validateConfig.default)('config.json', userConfig);
|
|
74
|
-
|
|
75
|
-
const config = _objectSpread({}, userConfig);
|
|
76
|
-
|
|
72
|
+
const config = (0, _cloneDeep2.default)(userConfig);
|
|
77
73
|
config.border = makeBorder(config.border);
|
|
78
74
|
config.columns = makeColumns(rows, config.columns, config.columnDefault);
|
|
79
75
|
|
package/dist/makeConfig.js.flow
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import calculateMaximumColumnWidthIndex from './calculateMaximumColumnWidthIndex';
|
|
2
3
|
import getBorderCharacters from './getBorderCharacters';
|
|
3
4
|
import validateConfig from './validateConfig';
|
|
@@ -24,8 +25,8 @@ const makeBorder = (border = {}) => {
|
|
|
24
25
|
const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
25
26
|
const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex(rows);
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
if (
|
|
28
|
+
_.times(rows[0].length, (index) => {
|
|
29
|
+
if (_.isUndefined(columns[index])) {
|
|
29
30
|
columns[index] = {};
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -37,7 +38,7 @@ const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
|
37
38
|
width: maximumColumnWidthIndex[index],
|
|
38
39
|
wrapWord: false,
|
|
39
40
|
}, columnDefault, columns[index]);
|
|
40
|
-
}
|
|
41
|
+
});
|
|
41
42
|
|
|
42
43
|
return columns;
|
|
43
44
|
};
|
|
@@ -53,7 +54,7 @@ const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
|
|
53
54
|
export default (rows, userConfig = {}) => {
|
|
54
55
|
validateConfig('config.json', userConfig);
|
|
55
56
|
|
|
56
|
-
const config =
|
|
57
|
+
const config = _.cloneDeep(userConfig);
|
|
57
58
|
|
|
58
59
|
config.border = makeBorder(config.border);
|
|
59
60
|
config.columns = makeColumns(rows, config.columns, config.columnDefault);
|
package/dist/makeConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/makeConfig.js"],"names":["makeBorder","border","Object","assign","makeColumns","rows","columns","columnDefault","maximumColumnWidthIndex","
|
|
1
|
+
{"version":3,"sources":["../src/makeConfig.js"],"names":["makeBorder","border","Object","assign","makeColumns","rows","columns","columnDefault","maximumColumnWidthIndex","length","index","alignment","paddingLeft","paddingRight","truncate","Infinity","width","wrapWord","userConfig","config","drawHorizontalLine","singleLine","undefined"],"mappings":";;;;;;;;;;;;;AACA;;AACA;;AACA;;;;AAEA;;;;;;AAMA,MAAMA,UAAU,GAAG,CAACC,MAAM,GAAG,EAAV,KAAiB;AAClC,SAAOC,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkB,kCAAoB,WAApB,CAAlB,EAAoDF,MAApD,CAAP;AACD,CAFD;AAIA;;;;;;;;;;;AASA,MAAMG,WAAW,GAAG,CAACC,IAAD,EAAOC,OAAO,GAAG,EAAjB,EAAqBC,aAAa,GAAG,EAArC,KAA4C;AAC9D,QAAMC,uBAAuB,GAAG,+CAAiCH,IAAjC,CAAhC;AAEA,uBAAQA,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAAhB,EAAyBC,KAAD,IAAW;AACjC,QAAI,2BAAcJ,OAAO,CAACI,KAAD,CAArB,CAAJ,EAAmC;AACjCJ,MAAAA,OAAO,CAACI,KAAD,CAAP,GAAiB,EAAjB;AACD;;AAEDJ,IAAAA,OAAO,CAACI,KAAD,CAAP,GAAiBR,MAAM,CAACC,MAAP,CAAc;AAC7BQ,MAAAA,SAAS,EAAE,MADkB;AAE7BC,MAAAA,WAAW,EAAE,CAFgB;AAG7BC,MAAAA,YAAY,EAAE,CAHe;AAI7BC,MAAAA,QAAQ,EAAEC,QAJmB;AAK7BC,MAAAA,KAAK,EAAER,uBAAuB,CAACE,KAAD,CALD;AAM7BO,MAAAA,QAAQ,EAAE;AANmB,KAAd,EAOdV,aAPc,EAOCD,OAAO,CAACI,KAAD,CAPR,CAAjB;AAQD,GAbD;AAeA,SAAOJ,OAAP;AACD,CAnBD;AAqBA;;;;;;;;;;oBAQgBD,I,EAAMa,UAAU,GAAG,E,KAAO;AACxC,+BAAe,aAAf,EAA8BA,UAA9B;AAEA,QAAMC,MAAM,GAAG,yBAAYD,UAAZ,CAAf;AAEAC,EAAAA,MAAM,CAAClB,MAAP,GAAgBD,UAAU,CAACmB,MAAM,CAAClB,MAAR,CAA1B;AACAkB,EAAAA,MAAM,CAACb,OAAP,GAAiBF,WAAW,CAACC,IAAD,EAAOc,MAAM,CAACb,OAAd,EAAuBa,MAAM,CAACZ,aAA9B,CAA5B;;AAEA,MAAI,CAACY,MAAM,CAACC,kBAAZ,EAAgC;AAC9B;;;AAGAD,IAAAA,MAAM,CAACC,kBAAP,GAA4B,MAAM;AAChC,aAAO,IAAP;AACD,KAFD;AAGD;;AAED,MAAID,MAAM,CAACE,UAAP,KAAsBC,SAA1B,EAAqC;AACnCH,IAAAA,MAAM,CAACE,UAAP,GAAoB,KAApB;AACD;;AAED,SAAOF,MAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport calculateMaximumColumnWidthIndex from './calculateMaximumColumnWidthIndex';\nimport getBorderCharacters from './getBorderCharacters';\nimport validateConfig from './validateConfig';\n\n/**\n * Merges user provided border characters with the default border (\"honeywell\") characters.\n *\n * @param {object} border\n * @returns {object}\n */\nconst makeBorder = (border = {}) => {\n return Object.assign({}, getBorderCharacters('honeywell'), border);\n};\n\n/**\n * Creates a configuration for every column using default\n * values for the missing configuration properties.\n *\n * @param {Array[]} rows\n * @param {object} columns\n * @param {object} columnDefault\n * @returns {object}\n */\nconst makeColumns = (rows, columns = {}, columnDefault = {}) => {\n const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex(rows);\n\n _.times(rows[0].length, (index) => {\n if (_.isUndefined(columns[index])) {\n columns[index] = {};\n }\n\n columns[index] = Object.assign({\n alignment: 'left',\n paddingLeft: 1,\n paddingRight: 1,\n truncate: Infinity,\n width: maximumColumnWidthIndex[index],\n wrapWord: false,\n }, columnDefault, columns[index]);\n });\n\n return columns;\n};\n\n/**\n * Makes a new configuration object out of the userConfig object\n * using default values for the missing configuration properties.\n *\n * @param {Array[]} rows\n * @param {object} userConfig\n * @returns {object}\n */\nexport default (rows, userConfig = {}) => {\n validateConfig('config.json', userConfig);\n\n const config = _.cloneDeep(userConfig);\n\n config.border = makeBorder(config.border);\n config.columns = makeColumns(rows, config.columns, config.columnDefault);\n\n if (!config.drawHorizontalLine) {\n /**\n * @returns {boolean}\n */\n config.drawHorizontalLine = () => {\n return true;\n };\n }\n\n if (config.singleLine === undefined) {\n config.singleLine = false;\n }\n\n return config;\n};\n"],"file":"makeConfig.js"}
|
package/dist/makeStreamConfig.js
CHANGED
|
@@ -5,17 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
var _times2 = _interopRequireDefault(require("lodash/times"));
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters"));
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
var _validateConfig = _interopRequireDefault(require("./validateConfig"));
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Merges user provided border characters with the default border ("honeywell") characters.
|
|
@@ -38,10 +38,8 @@ const makeBorder = (border = {}) => {
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
while (index--) {
|
|
44
|
-
if (!columns[index]) {
|
|
41
|
+
(0, _times2.default)(columnCount, index => {
|
|
42
|
+
if ((0, _isUndefined2.default)(columns[index])) {
|
|
45
43
|
columns[index] = {};
|
|
46
44
|
}
|
|
47
45
|
|
|
@@ -52,8 +50,7 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
52
50
|
truncate: Infinity,
|
|
53
51
|
wrapWord: false
|
|
54
52
|
}, columnDefault, columns[index]);
|
|
55
|
-
}
|
|
56
|
-
|
|
53
|
+
});
|
|
57
54
|
return columns;
|
|
58
55
|
};
|
|
59
56
|
/**
|
|
@@ -84,8 +81,7 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
84
81
|
|
|
85
82
|
const makeStreamConfig = (userConfig = {}) => {
|
|
86
83
|
(0, _validateConfig.default)('streamConfig.json', userConfig);
|
|
87
|
-
|
|
88
|
-
const config = _objectSpread({}, userConfig);
|
|
84
|
+
const config = (0, _cloneDeep2.default)(userConfig);
|
|
89
85
|
|
|
90
86
|
if (!config.columnDefault || !config.columnDefault.width) {
|
|
91
87
|
throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import getBorderCharacters from './getBorderCharacters';
|
|
2
3
|
import validateConfig from './validateConfig';
|
|
3
4
|
|
|
@@ -21,10 +22,8 @@ const makeBorder = (border = {}) => {
|
|
|
21
22
|
* @returns {object}
|
|
22
23
|
*/
|
|
23
24
|
const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
while (index--) {
|
|
27
|
-
if (!columns[index]) {
|
|
25
|
+
_.times(columnCount, (index) => {
|
|
26
|
+
if (_.isUndefined(columns[index])) {
|
|
28
27
|
columns[index] = {};
|
|
29
28
|
}
|
|
30
29
|
|
|
@@ -35,7 +34,7 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
35
34
|
truncate: Infinity,
|
|
36
35
|
wrapWord: false,
|
|
37
36
|
}, columnDefault, columns[index]);
|
|
38
|
-
}
|
|
37
|
+
});
|
|
39
38
|
|
|
40
39
|
return columns;
|
|
41
40
|
};
|
|
@@ -67,7 +66,7 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
67
66
|
export default (userConfig = {}) => {
|
|
68
67
|
validateConfig('streamConfig.json', userConfig);
|
|
69
68
|
|
|
70
|
-
const config =
|
|
69
|
+
const config = _.cloneDeep(userConfig);
|
|
71
70
|
|
|
72
71
|
if (!config.columnDefault || !config.columnDefault.width) {
|
|
73
72
|
throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/makeStreamConfig.js"],"names":["makeBorder","border","Object","assign","makeColumns","columnCount","columns","columnDefault","index","alignment","paddingLeft","paddingRight","truncate","Infinity","wrapWord","userConfig","config","width","Error"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/makeStreamConfig.js"],"names":["makeBorder","border","Object","assign","makeColumns","columnCount","columns","columnDefault","index","alignment","paddingLeft","paddingRight","truncate","Infinity","wrapWord","userConfig","config","width","Error"],"mappings":";;;;;;;;;;;;;AACA;;AACA;;;;AAEA;;;;;;AAMA,MAAMA,UAAU,GAAG,CAACC,MAAM,GAAG,EAAV,KAAiB;AAClC,SAAOC,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkB,kCAAoB,WAApB,CAAlB,EAAoDF,MAApD,CAAP;AACD,CAFD;AAIA;;;;;;;;;;;AASA,MAAMG,WAAW,GAAG,CAACC,WAAD,EAAcC,OAAO,GAAG,EAAxB,EAA4BC,aAAa,GAAG,EAA5C,KAAmD;AACrE,uBAAQF,WAAR,EAAsBG,KAAD,IAAW;AAC9B,QAAI,2BAAcF,OAAO,CAACE,KAAD,CAArB,CAAJ,EAAmC;AACjCF,MAAAA,OAAO,CAACE,KAAD,CAAP,GAAiB,EAAjB;AACD;;AAEDF,IAAAA,OAAO,CAACE,KAAD,CAAP,GAAiBN,MAAM,CAACC,MAAP,CAAc;AAC7BM,MAAAA,SAAS,EAAE,MADkB;AAE7BC,MAAAA,WAAW,EAAE,CAFgB;AAG7BC,MAAAA,YAAY,EAAE,CAHe;AAI7BC,MAAAA,QAAQ,EAAEC,QAJmB;AAK7BC,MAAAA,QAAQ,EAAE;AALmB,KAAd,EAMdP,aANc,EAMCD,OAAO,CAACE,KAAD,CANR,CAAjB;AAOD,GAZD;AAcA,SAAOF,OAAP;AACD,CAhBD;AAkBA;;;;;;;;;AASA;;;;;;;;AAQA;;;;;;;;;0BAOgBS,UAAU,GAAG,E,KAAO;AAClC,+BAAe,mBAAf,EAAoCA,UAApC;AAEA,QAAMC,MAAM,GAAG,yBAAYD,UAAZ,CAAf;;AAEA,MAAI,CAACC,MAAM,CAACT,aAAR,IAAyB,CAACS,MAAM,CAACT,aAAP,CAAqBU,KAAnD,EAA0D;AACxD,UAAM,IAAIC,KAAJ,CAAU,iEAAV,CAAN;AACD;;AAED,MAAI,CAACF,MAAM,CAACX,WAAZ,EAAyB;AACvB,UAAM,IAAIa,KAAJ,CAAU,kCAAV,CAAN;AACD;;AAEDF,EAAAA,MAAM,CAACf,MAAP,GAAgBD,UAAU,CAACgB,MAAM,CAACf,MAAR,CAA1B;AACAe,EAAAA,MAAM,CAACV,OAAP,GAAiBF,WAAW,CAACY,MAAM,CAACX,WAAR,EAAqBW,MAAM,CAACV,OAA5B,EAAqCU,MAAM,CAACT,aAA5C,CAA5B;AAEA,SAAOS,MAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport getBorderCharacters from './getBorderCharacters';\nimport validateConfig from './validateConfig';\n\n/**\n * Merges user provided border characters with the default border (\"honeywell\") characters.\n *\n * @param {object} border\n * @returns {object}\n */\nconst makeBorder = (border = {}) => {\n return Object.assign({}, getBorderCharacters('honeywell'), border);\n};\n\n/**\n * Creates a configuration for every column using default\n * values for the missing configuration properties.\n *\n * @param {number} columnCount\n * @param {object} columns\n * @param {object} columnDefault\n * @returns {object}\n */\nconst makeColumns = (columnCount, columns = {}, columnDefault = {}) => {\n _.times(columnCount, (index) => {\n if (_.isUndefined(columns[index])) {\n columns[index] = {};\n }\n\n columns[index] = Object.assign({\n alignment: 'left',\n paddingLeft: 1,\n paddingRight: 1,\n truncate: Infinity,\n wrapWord: false,\n }, columnDefault, columns[index]);\n });\n\n return columns;\n};\n\n/**\n * @typedef {object} columnConfig\n * @property {string} alignment\n * @property {number} width\n * @property {number} truncate\n * @property {number} paddingLeft\n * @property {number} paddingRight\n */\n\n/**\n * @typedef {object} streamConfig\n * @property {columnConfig} columnDefault\n * @property {object} border\n * @property {columnConfig[]}\n * @property {number} columnCount Number of columns in the table (required).\n */\n\n/**\n * Makes a new configuration object out of the userConfig object\n * using default values for the missing configuration properties.\n *\n * @param {streamConfig} userConfig\n * @returns {object}\n */\nexport default (userConfig = {}) => {\n validateConfig('streamConfig.json', userConfig);\n\n const config = _.cloneDeep(userConfig);\n\n if (!config.columnDefault || !config.columnDefault.width) {\n throw new Error('Must provide config.columnDefault.width when creating a stream.');\n }\n\n if (!config.columnCount) {\n throw new Error('Must provide config.columnCount.');\n }\n\n config.border = makeBorder(config.border);\n config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault);\n\n return config;\n};\n"],"file":"makeStreamConfig.js"}
|
|
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _flatten2 = _interopRequireDefault(require("lodash/flatten"));
|
|
9
|
+
|
|
10
|
+
var _times2 = _interopRequireDefault(require("lodash/times"));
|
|
11
|
+
|
|
8
12
|
var _wrapCell = _interopRequireDefault(require("./wrapCell"));
|
|
9
13
|
|
|
10
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -18,9 +22,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
22
|
const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
|
|
19
23
|
const tableWidth = unmappedRows[0].length;
|
|
20
24
|
const mappedRows = unmappedRows.map((cells, index0) => {
|
|
21
|
-
const rowHeight =
|
|
22
|
-
length: rowHeightIndex[index0]
|
|
23
|
-
}, () => {
|
|
25
|
+
const rowHeight = (0, _times2.default)(rowHeightIndex[index0], () => {
|
|
24
26
|
return new Array(tableWidth).fill('');
|
|
25
27
|
}); // rowHeight
|
|
26
28
|
// [{row index within rowSaw; index2}]
|
|
@@ -33,9 +35,8 @@ const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
|
|
|
33
35
|
});
|
|
34
36
|
});
|
|
35
37
|
return rowHeight;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
return [].concat(...mappedRows);
|
|
38
|
+
});
|
|
39
|
+
return (0, _flatten2.default)(mappedRows);
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
var _default = mapDataUsingRowHeightIndex;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import wrapCell from './wrapCell';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -10,7 +11,7 @@ export default (unmappedRows, rowHeightIndex, config) => {
|
|
|
10
11
|
const tableWidth = unmappedRows[0].length;
|
|
11
12
|
|
|
12
13
|
const mappedRows = unmappedRows.map((cells, index0) => {
|
|
13
|
-
const rowHeight =
|
|
14
|
+
const rowHeight = _.times(rowHeightIndex[index0], () => {
|
|
14
15
|
return new Array(tableWidth).fill('');
|
|
15
16
|
});
|
|
16
17
|
|
|
@@ -29,6 +30,5 @@ export default (unmappedRows, rowHeightIndex, config) => {
|
|
|
29
30
|
return rowHeight;
|
|
30
31
|
});
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
return [].concat(...mappedRows);
|
|
33
|
+
return _.flatten(mappedRows);
|
|
34
34
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mapDataUsingRowHeightIndex.js"],"names":["unmappedRows","rowHeightIndex","config","tableWidth","length","mappedRows","map","cells","index0","rowHeight","Array","
|
|
1
|
+
{"version":3,"sources":["../src/mapDataUsingRowHeightIndex.js"],"names":["unmappedRows","rowHeightIndex","config","tableWidth","length","mappedRows","map","cells","index0","rowHeight","Array","fill","forEach","value","index1","cellLines","columns","width","wrapWord","cellLine","index2"],"mappings":";;;;;;;;;;;AACA;;;;AAEA;;;;;;oCAMgBA,Y,EAAcC,c,EAAgBC,M,KAAW;AACvD,QAAMC,UAAU,GAAGH,YAAY,CAAC,CAAD,CAAZ,CAAgBI,MAAnC;AAEA,QAAMC,UAAU,GAAGL,YAAY,CAACM,GAAb,CAAiB,CAACC,KAAD,EAAQC,MAAR,KAAmB;AACrD,UAAMC,SAAS,GAAG,qBAAQR,cAAc,CAACO,MAAD,CAAtB,EAAgC,MAAM;AACtD,aAAO,IAAIE,KAAJ,CAAUP,UAAV,EAAsBQ,IAAtB,CAA2B,EAA3B,CAAP;AACD,KAFiB,CAAlB,CADqD,CAKrD;AACA;AACA;;AAEAJ,IAAAA,KAAK,CAACK,OAAN,CAAc,CAACC,KAAD,EAAQC,MAAR,KAAmB;AAC/B,YAAMC,SAAS,GAAG,uBAASF,KAAT,EAAgBX,MAAM,CAACc,OAAP,CAAeF,MAAf,EAAuBG,KAAvC,EAA8Cf,MAAM,CAACc,OAAP,CAAeF,MAAf,EAAuBI,QAArE,CAAlB;AAEAH,MAAAA,SAAS,CAACH,OAAV,CAAkB,CAACO,QAAD,EAAWC,MAAX,KAAsB;AACtCX,QAAAA,SAAS,CAACW,MAAD,CAAT,CAAkBN,MAAlB,IAA4BK,QAA5B;AACD,OAFD;AAGD,KAND;AAQA,WAAOV,SAAP;AACD,GAlBkB,CAAnB;AAoBA,SAAO,uBAAUJ,UAAV,CAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport wrapCell from './wrapCell';\n\n/**\n * @param {Array} unmappedRows\n * @param {number[]} rowHeightIndex\n * @param {object} config\n * @returns {Array}\n */\nexport default (unmappedRows, rowHeightIndex, config) => {\n const tableWidth = unmappedRows[0].length;\n\n const mappedRows = unmappedRows.map((cells, index0) => {\n const rowHeight = _.times(rowHeightIndex[index0], () => {\n return new Array(tableWidth).fill('');\n });\n\n // rowHeight\n // [{row index within rowSaw; index2}]\n // [{cell index within a virtual row; index1}]\n\n cells.forEach((value, index1) => {\n const cellLines = wrapCell(value, config.columns[index1].width, config.columns[index1].wrapWord);\n\n cellLines.forEach((cellLine, index2) => {\n rowHeight[index2][index1] = cellLine;\n });\n });\n\n return rowHeight;\n });\n\n return _.flatten(mappedRows);\n};\n"],"file":"mapDataUsingRowHeightIndex.js"}
|
|
@@ -5,21 +5,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
8
|
+
var _truncate2 = _interopRequireDefault(require("lodash/truncate"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* @todo Make it work with ASCII content.
|
|
13
14
|
* @param {table~row[]} rows
|
|
14
15
|
* @param {object} config
|
|
15
16
|
* @returns {table~row[]}
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
18
|
const truncateTableData = (rows, config) => {
|
|
20
19
|
return rows.map(cells => {
|
|
21
20
|
return cells.map((content, index) => {
|
|
22
|
-
return
|
|
21
|
+
return (0, _truncate2.default)(content, {
|
|
22
|
+
length: config.columns[index].truncate
|
|
23
|
+
});
|
|
23
24
|
});
|
|
24
25
|
});
|
|
25
26
|
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
return string.length > length ? string.slice(0, Math.max(0, length - 3)) + '...' : string;
|
|
3
|
-
};
|
|
1
|
+
import _ from 'lodash';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* @todo Make it work with ASCII content.
|
|
@@ -11,7 +9,9 @@ const truncate = (string, length) => {
|
|
|
11
9
|
export default (rows, config) => {
|
|
12
10
|
return rows.map((cells) => {
|
|
13
11
|
return cells.map((content, index) => {
|
|
14
|
-
return truncate(content,
|
|
12
|
+
return _.truncate(content, {
|
|
13
|
+
length: config.columns[index].truncate,
|
|
14
|
+
});
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/truncateTableData.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["../src/truncateTableData.js"],"names":["rows","config","map","cells","content","index","length","columns","truncate"],"mappings":";;;;;;;;;;;AAEA;;;;;;2BAMgBA,I,EAAMC,M,KAAW;AAC/B,SAAOD,IAAI,CAACE,GAAL,CAAUC,KAAD,IAAW;AACzB,WAAOA,KAAK,CAACD,GAAN,CAAU,CAACE,OAAD,EAAUC,KAAV,KAAoB;AACnC,aAAO,wBAAWD,OAAX,EAAoB;AACzBE,QAAAA,MAAM,EAAEL,MAAM,CAACM,OAAP,CAAeF,KAAf,EAAsBG;AADL,OAApB,CAAP;AAGD,KAJM,CAAP;AAKD,GANM,CAAP;AAOD,C","sourcesContent":["import _ from 'lodash';\n\n/**\n * @todo Make it work with ASCII content.\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((content, index) => {\n return _.truncate(content, {\n length: config.columns[index].truncate,\n });\n });\n });\n};\n"],"file":"truncateTableData.js"}
|
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"ajv": "^6.12.4",
|
|
9
|
+
"lodash": "^4.17.20",
|
|
9
10
|
"slice-ansi": "^4.0.0",
|
|
10
11
|
"string-width": "^4.2.0"
|
|
11
12
|
},
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
"ajv-cli": "^3.2.1",
|
|
21
22
|
"ajv-keywords": "^3.5.2",
|
|
22
23
|
"babel-plugin-istanbul": "^6.0.0",
|
|
24
|
+
"babel-plugin-lodash": "^3.3.4",
|
|
23
25
|
"babel-plugin-transform-export-default-name": "^2.0.4",
|
|
24
26
|
"chai": "^4.2.0",
|
|
25
27
|
"chalk": "^4.1.0",
|
|
@@ -78,5 +80,5 @@
|
|
|
78
80
|
"lint": "npm run build && eslint ./src ./test && flow",
|
|
79
81
|
"test": "mocha --require @babel/register"
|
|
80
82
|
},
|
|
81
|
-
"version": "6.0.
|
|
83
|
+
"version": "6.0.3"
|
|
82
84
|
}
|