table 6.2.0 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/src/alignString.js +64 -0
- package/dist/src/alignTableData.js +21 -0
- package/dist/src/calculateCellHeight.js +17 -0
- package/dist/src/calculateCellWidthIndex.js +17 -0
- package/dist/src/calculateMaximumColumnWidthIndex.js +25 -0
- package/dist/src/calculateRowHeightIndex.js +30 -0
- package/dist/src/createStream.js +74 -0
- package/dist/src/drawBorder.js +55 -0
- package/dist/src/drawHorizontalContent.js +19 -0
- package/dist/src/drawRow.js +17 -0
- package/dist/src/drawTable.js +38 -0
- package/dist/src/getBorderCharacters.js +83 -0
- package/dist/{index.js.flow → src/index.d.ts} +2 -6
- package/dist/src/index.js +24 -0
- package/dist/src/makeConfig.js +59 -0
- package/dist/src/makeStreamConfig.js +60 -0
- package/dist/src/mapDataUsingRowHeightIndex.js +27 -0
- package/dist/src/padTableData.js +11 -0
- package/dist/src/stringifyTableData.js +8 -0
- package/dist/src/table.js +28 -0
- package/dist/src/truncateTableData.js +20 -0
- package/dist/src/types/api.d.ts +99 -0
- package/dist/src/types/api.js +3 -0
- package/dist/src/types/internal.js +3 -0
- package/dist/src/validateConfig.js +27 -0
- package/dist/src/validateTableData.js +29 -0
- package/dist/{validators.js → src/validators.js} +0 -0
- package/dist/src/wrapCell.js +33 -0
- package/dist/src/wrapString.js +25 -0
- package/dist/src/wrapWord.js +29 -0
- package/package.json +33 -25
- package/dist/alignString.js +0 -107
- package/dist/alignString.js.flow +0 -97
- package/dist/alignTableData.js +0 -34
- package/dist/alignTableData.js.flow +0 -21
- package/dist/calculateCellHeight.js +0 -37
- package/dist/calculateCellHeight.js.flow +0 -24
- package/dist/calculateCellWidthIndex.js +0 -27
- package/dist/calculateCellWidthIndex.js.flow +0 -17
- package/dist/calculateMaximumColumnWidthIndex.js +0 -36
- package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
- package/dist/calculateRowHeightIndex.js +0 -45
- package/dist/calculateRowHeightIndex.js.flow +0 -36
- package/dist/createStream.js +0 -124
- package/dist/createStream.js.flow +0 -125
- package/dist/drawBorder.js +0 -115
- package/dist/drawBorder.js.flow +0 -89
- package/dist/drawHorizontalContent.js +0 -41
- package/dist/drawHorizontalContent.js.flow +0 -31
- package/dist/drawRow.js +0 -41
- package/dist/drawRow.js.flow +0 -29
- package/dist/drawTable.js +0 -60
- package/dist/drawTable.js.flow +0 -64
- package/dist/getBorderCharacters.js +0 -118
- package/dist/getBorderCharacters.js.flow +0 -120
- package/dist/index.js +0 -31
- package/dist/makeConfig.js +0 -100
- package/dist/makeConfig.js.flow +0 -85
- package/dist/makeStreamConfig.js +0 -107
- package/dist/makeStreamConfig.js.flow +0 -92
- package/dist/mapDataUsingRowHeightIndex.js +0 -41
- package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
- package/dist/padTableData.js +0 -23
- package/dist/padTableData.js.flow +0 -14
- package/dist/schemas/config.json +0 -26
- package/dist/schemas/shared.json +0 -98
- package/dist/schemas/streamConfig.json +0 -23
- package/dist/stringifyTableData.js +0 -21
- package/dist/stringifyTableData.js.flow +0 -11
- package/dist/table.js +0 -121
- package/dist/table.js.flow +0 -108
- package/dist/truncateTableData.js +0 -30
- package/dist/truncateTableData.js.flow +0 -18
- package/dist/validateConfig.js +0 -40
- package/dist/validateConfig.js.flow +0 -27
- package/dist/validateTableData.js +0 -54
- package/dist/validateTableData.js.flow +0 -44
- package/dist/wrapCell.js +0 -47
- package/dist/wrapCell.js.flow +0 -35
- package/dist/wrapString.js +0 -39
- package/dist/wrapString.js.flow +0 -29
- package/dist/wrapWord.js +0 -46
- package/dist/wrapWord.js.flow +0 -39
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _isString = _interopRequireDefault(require("is-string"));
|
|
9
|
-
|
|
10
|
-
var _wrapCell = _interopRequireDefault(require("./wrapCell"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param {string} value
|
|
16
|
-
* @param {number} columnWidth
|
|
17
|
-
* @param {boolean} useWrapWord
|
|
18
|
-
* @returns {number}
|
|
19
|
-
*/
|
|
20
|
-
const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
|
|
21
|
-
if (!(0, _isString.default)(value)) {
|
|
22
|
-
throw new TypeError('Value must be a string.');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!Number.isInteger(columnWidth)) {
|
|
26
|
-
throw new TypeError('Column width must be an integer.');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (columnWidth < 1) {
|
|
30
|
-
throw new Error('Column width must be greater than 0.');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return (0, _wrapCell.default)(value, columnWidth, useWrapWord).length;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
var _default = calculateCellHeight;
|
|
37
|
-
exports.default = _default;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import isString from 'is-string';
|
|
2
|
-
import wrapCell from './wrapCell';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {string} value
|
|
6
|
-
* @param {number} columnWidth
|
|
7
|
-
* @param {boolean} useWrapWord
|
|
8
|
-
* @returns {number}
|
|
9
|
-
*/
|
|
10
|
-
export default (value, columnWidth, useWrapWord = false) => {
|
|
11
|
-
if (!isString(value)) {
|
|
12
|
-
throw new TypeError('Value must be a string.');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (!Number.isInteger(columnWidth)) {
|
|
16
|
-
throw new TypeError('Column width must be an integer.');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (columnWidth < 1) {
|
|
20
|
-
throw new Error('Column width must be greater than 0.');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return wrapCell(value, columnWidth, useWrapWord).length;
|
|
24
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _stringWidth = _interopRequireDefault(require("string-width"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Calculates width of each cell contents.
|
|
14
|
-
*
|
|
15
|
-
* @param {string[]} cells
|
|
16
|
-
* @returns {number[]}
|
|
17
|
-
*/
|
|
18
|
-
const calculateCellWidthIndex = cells => {
|
|
19
|
-
return cells.map(value => {
|
|
20
|
-
return Math.max(...value.split('\n').map(line => {
|
|
21
|
-
return (0, _stringWidth.default)(line);
|
|
22
|
-
}));
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
var _default = calculateCellWidthIndex;
|
|
27
|
-
exports.default = _default;
|
|
@@ -1,17 +0,0 @@
|
|
|
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 Math.max(
|
|
12
|
-
...value.split('\n').map((line) => {
|
|
13
|
-
return stringWidth(line);
|
|
14
|
-
}),
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Produces an array of values that describe the largest value length (width) in every column.
|
|
14
|
-
*
|
|
15
|
-
* @param {Array[]} rows
|
|
16
|
-
* @returns {number[]}
|
|
17
|
-
*/
|
|
18
|
-
const calculateMaximumColumnWidthIndex = rows => {
|
|
19
|
-
if (!rows[0]) {
|
|
20
|
-
throw new Error('Dataset must have at least one row.');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const columns = new Array(rows[0].length).fill(0);
|
|
24
|
-
rows.forEach(row => {
|
|
25
|
-
const columnWidthIndex = (0, _calculateCellWidthIndex.default)(row);
|
|
26
|
-
columnWidthIndex.forEach((valueWidth, index0) => {
|
|
27
|
-
if (columns[index0] < valueWidth) {
|
|
28
|
-
columns[index0] = valueWidth;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
return columns;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
var _default = calculateMaximumColumnWidthIndex;
|
|
36
|
-
exports.default = _default;
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _isBooleanObject = _interopRequireDefault(require("is-boolean-object"));
|
|
9
|
-
|
|
10
|
-
var _isNumberObject = _interopRequireDefault(require("is-number-object"));
|
|
11
|
-
|
|
12
|
-
var _calculateCellHeight = _interopRequireDefault(require("./calculateCellHeight"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Calculates the vertical row span index.
|
|
18
|
-
*
|
|
19
|
-
* @param {Array[]} rows
|
|
20
|
-
* @param {object} config
|
|
21
|
-
* @returns {number[]}
|
|
22
|
-
*/
|
|
23
|
-
const calculateRowHeightIndex = (rows, config) => {
|
|
24
|
-
const tableWidth = rows[0].length;
|
|
25
|
-
const rowSpanIndex = [];
|
|
26
|
-
rows.forEach(cells => {
|
|
27
|
-
const cellHeightIndex = new Array(tableWidth).fill(1);
|
|
28
|
-
cells.forEach((value, index1) => {
|
|
29
|
-
if (!(0, _isNumberObject.default)(config.columns[index1].width)) {
|
|
30
|
-
throw new TypeError('column[index].width must be a number.');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!(0, _isBooleanObject.default)(config.columns[index1].wrapWord)) {
|
|
34
|
-
throw new TypeError('column[index].wrapWord must be a boolean.');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
cellHeightIndex[index1] = (0, _calculateCellHeight.default)(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
38
|
-
});
|
|
39
|
-
rowSpanIndex.push(Math.max(...cellHeightIndex));
|
|
40
|
-
});
|
|
41
|
-
return rowSpanIndex;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
var _default = calculateRowHeightIndex;
|
|
45
|
-
exports.default = _default;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import isBoolean from 'is-boolean-object';
|
|
2
|
-
import isNumber from 'is-number-object';
|
|
3
|
-
import calculateCellHeight from './calculateCellHeight';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Calculates the vertical row span index.
|
|
7
|
-
*
|
|
8
|
-
* @param {Array[]} rows
|
|
9
|
-
* @param {object} config
|
|
10
|
-
* @returns {number[]}
|
|
11
|
-
*/
|
|
12
|
-
export default (rows, config) => {
|
|
13
|
-
const tableWidth = rows[0].length;
|
|
14
|
-
|
|
15
|
-
const rowSpanIndex = [];
|
|
16
|
-
|
|
17
|
-
rows.forEach((cells) => {
|
|
18
|
-
const cellHeightIndex = new Array(tableWidth).fill(1);
|
|
19
|
-
|
|
20
|
-
cells.forEach((value, index1) => {
|
|
21
|
-
if (!isNumber(config.columns[index1].width)) {
|
|
22
|
-
throw new TypeError('column[index].width must be a number.');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!isBoolean(config.columns[index1].wrapWord)) {
|
|
26
|
-
throw new TypeError('column[index].wrapWord must be a boolean.');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
rowSpanIndex.push(Math.max(...cellHeightIndex));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
return rowSpanIndex;
|
|
36
|
-
};
|
package/dist/createStream.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _alignTableData = _interopRequireDefault(require("./alignTableData"));
|
|
9
|
-
|
|
10
|
-
var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex"));
|
|
11
|
-
|
|
12
|
-
var _drawBorder = require("./drawBorder");
|
|
13
|
-
|
|
14
|
-
var _drawRow = _interopRequireDefault(require("./drawRow"));
|
|
15
|
-
|
|
16
|
-
var _makeStreamConfig = _interopRequireDefault(require("./makeStreamConfig"));
|
|
17
|
-
|
|
18
|
-
var _mapDataUsingRowHeightIndex = _interopRequireDefault(require("./mapDataUsingRowHeightIndex"));
|
|
19
|
-
|
|
20
|
-
var _padTableData = _interopRequireDefault(require("./padTableData"));
|
|
21
|
-
|
|
22
|
-
var _stringifyTableData = _interopRequireDefault(require("./stringifyTableData"));
|
|
23
|
-
|
|
24
|
-
var _truncateTableData = _interopRequireDefault(require("./truncateTableData"));
|
|
25
|
-
|
|
26
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @param {Array} data
|
|
30
|
-
* @param {streamConfig} config
|
|
31
|
-
* @returns {Array}
|
|
32
|
-
*/
|
|
33
|
-
const prepareData = (data, config) => {
|
|
34
|
-
let rows;
|
|
35
|
-
rows = (0, _stringifyTableData.default)(data);
|
|
36
|
-
rows = (0, _truncateTableData.default)(rows, config);
|
|
37
|
-
const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config);
|
|
38
|
-
rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config);
|
|
39
|
-
rows = (0, _alignTableData.default)(rows, config);
|
|
40
|
-
rows = (0, _padTableData.default)(rows, config);
|
|
41
|
-
return rows;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* @param {string[]} row
|
|
45
|
-
* @param {number[]} columnWidthIndex
|
|
46
|
-
* @param {streamConfig} config
|
|
47
|
-
* @returns {undefined}
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const create = (row, columnWidthIndex, config) => {
|
|
52
|
-
const rows = prepareData([row], config);
|
|
53
|
-
const body = rows.map(literalRow => {
|
|
54
|
-
return (0, _drawRow.default)(literalRow, config);
|
|
55
|
-
}).join('');
|
|
56
|
-
let output;
|
|
57
|
-
output = '';
|
|
58
|
-
output += (0, _drawBorder.drawBorderTop)(columnWidthIndex, config);
|
|
59
|
-
output += body;
|
|
60
|
-
output += (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config);
|
|
61
|
-
output = output.trimEnd();
|
|
62
|
-
process.stdout.write(output);
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* @param {string[]} row
|
|
66
|
-
* @param {number[]} columnWidthIndex
|
|
67
|
-
* @param {streamConfig} config
|
|
68
|
-
* @returns {undefined}
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const append = (row, columnWidthIndex, config) => {
|
|
73
|
-
const rows = prepareData([row], config);
|
|
74
|
-
const body = rows.map(literalRow => {
|
|
75
|
-
return (0, _drawRow.default)(literalRow, config);
|
|
76
|
-
}).join('');
|
|
77
|
-
let output = '';
|
|
78
|
-
const bottom = (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config);
|
|
79
|
-
|
|
80
|
-
if (bottom !== '\n') {
|
|
81
|
-
output = '\r\u001B[K';
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
output += (0, _drawBorder.drawBorderJoin)(columnWidthIndex, config);
|
|
85
|
-
output += body;
|
|
86
|
-
output += bottom;
|
|
87
|
-
output = output.trimEnd();
|
|
88
|
-
process.stdout.write(output);
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* @param {object} userConfig
|
|
92
|
-
* @returns {object}
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const createStream = (userConfig = {}) => {
|
|
97
|
-
const config = (0, _makeStreamConfig.default)(userConfig);
|
|
98
|
-
const columnWidthIndex = Object.values(config.columns).map(column => {
|
|
99
|
-
return column.width + column.paddingLeft + column.paddingRight;
|
|
100
|
-
});
|
|
101
|
-
let empty;
|
|
102
|
-
empty = true;
|
|
103
|
-
return {
|
|
104
|
-
/**
|
|
105
|
-
* @param {string[]} row
|
|
106
|
-
* @returns {undefined}
|
|
107
|
-
*/
|
|
108
|
-
write: row => {
|
|
109
|
-
if (row.length !== config.columnCount) {
|
|
110
|
-
throw new Error('Row cell count does not match the config.columnCount.');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (empty) {
|
|
114
|
-
empty = false;
|
|
115
|
-
return create(row, columnWidthIndex, config);
|
|
116
|
-
} else {
|
|
117
|
-
return append(row, columnWidthIndex, config);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
var _default = createStream;
|
|
124
|
-
exports.default = _default;
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import alignTableData from './alignTableData';
|
|
2
|
-
import calculateRowHeightIndex from './calculateRowHeightIndex';
|
|
3
|
-
import {
|
|
4
|
-
drawBorderBottom,
|
|
5
|
-
drawBorderJoin,
|
|
6
|
-
drawBorderTop,
|
|
7
|
-
} from './drawBorder';
|
|
8
|
-
import drawRow from './drawRow';
|
|
9
|
-
import makeStreamConfig from './makeStreamConfig';
|
|
10
|
-
import mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';
|
|
11
|
-
import padTableData from './padTableData';
|
|
12
|
-
import stringifyTableData from './stringifyTableData';
|
|
13
|
-
import truncateTableData from './truncateTableData';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {Array} data
|
|
17
|
-
* @param {streamConfig} config
|
|
18
|
-
* @returns {Array}
|
|
19
|
-
*/
|
|
20
|
-
const prepareData = (data, config) => {
|
|
21
|
-
let rows;
|
|
22
|
-
|
|
23
|
-
rows = stringifyTableData(data);
|
|
24
|
-
|
|
25
|
-
rows = truncateTableData(rows, config);
|
|
26
|
-
|
|
27
|
-
const rowHeightIndex = calculateRowHeightIndex(rows, config);
|
|
28
|
-
|
|
29
|
-
rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);
|
|
30
|
-
rows = alignTableData(rows, config);
|
|
31
|
-
rows = padTableData(rows, config);
|
|
32
|
-
|
|
33
|
-
return rows;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @param {string[]} row
|
|
38
|
-
* @param {number[]} columnWidthIndex
|
|
39
|
-
* @param {streamConfig} config
|
|
40
|
-
* @returns {undefined}
|
|
41
|
-
*/
|
|
42
|
-
const create = (row, columnWidthIndex, config) => {
|
|
43
|
-
const rows = prepareData([row], config);
|
|
44
|
-
|
|
45
|
-
const body = rows.map((literalRow) => {
|
|
46
|
-
return drawRow(literalRow, config);
|
|
47
|
-
}).join('');
|
|
48
|
-
|
|
49
|
-
let output;
|
|
50
|
-
|
|
51
|
-
output = '';
|
|
52
|
-
|
|
53
|
-
output += drawBorderTop(columnWidthIndex, config);
|
|
54
|
-
output += body;
|
|
55
|
-
output += drawBorderBottom(columnWidthIndex, config);
|
|
56
|
-
|
|
57
|
-
output = output.trimEnd();
|
|
58
|
-
|
|
59
|
-
process.stdout.write(output);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @param {string[]} row
|
|
64
|
-
* @param {number[]} columnWidthIndex
|
|
65
|
-
* @param {streamConfig} config
|
|
66
|
-
* @returns {undefined}
|
|
67
|
-
*/
|
|
68
|
-
const append = (row, columnWidthIndex, config) => {
|
|
69
|
-
const rows = prepareData([row], config);
|
|
70
|
-
|
|
71
|
-
const body = rows.map((literalRow) => {
|
|
72
|
-
return drawRow(literalRow, config);
|
|
73
|
-
}).join('');
|
|
74
|
-
|
|
75
|
-
let output = '';
|
|
76
|
-
const bottom = drawBorderBottom(columnWidthIndex, config);
|
|
77
|
-
|
|
78
|
-
if (bottom !== '\n') {
|
|
79
|
-
output = '\r\u001B[K';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
output += drawBorderJoin(columnWidthIndex, config);
|
|
83
|
-
output += body;
|
|
84
|
-
output += bottom;
|
|
85
|
-
|
|
86
|
-
output = output.trimEnd();
|
|
87
|
-
|
|
88
|
-
process.stdout.write(output);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @param {object} userConfig
|
|
93
|
-
* @returns {object}
|
|
94
|
-
*/
|
|
95
|
-
export default (userConfig = {}) => {
|
|
96
|
-
const config = makeStreamConfig(userConfig);
|
|
97
|
-
|
|
98
|
-
const columnWidthIndex = Object.values(config.columns).map((column) => {
|
|
99
|
-
return column.width + column.paddingLeft + column.paddingRight;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
let empty;
|
|
103
|
-
|
|
104
|
-
empty = true;
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
/**
|
|
108
|
-
* @param {string[]} row
|
|
109
|
-
* @returns {undefined}
|
|
110
|
-
*/
|
|
111
|
-
write: (row) => {
|
|
112
|
-
if (row.length !== config.columnCount) {
|
|
113
|
-
throw new Error('Row cell count does not match the config.columnCount.');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (empty) {
|
|
117
|
-
empty = false;
|
|
118
|
-
|
|
119
|
-
return create(row, columnWidthIndex, config);
|
|
120
|
-
} else {
|
|
121
|
-
return append(row, columnWidthIndex, config);
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
};
|
package/dist/drawBorder.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = void 0;
|
|
7
|
-
|
|
8
|
-
var _drawHorizontalContent = _interopRequireDefault(require("./drawHorizontalContent"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef drawBorder~border
|
|
14
|
-
* @property {string} left
|
|
15
|
-
* @property {string} right
|
|
16
|
-
* @property {string} body
|
|
17
|
-
* @property {string} join
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @param {number[]} columnSizeIndex
|
|
22
|
-
* @param {object} config
|
|
23
|
-
* @param {drawBorder~border} config.border
|
|
24
|
-
* @param {Function} config.drawVerticalLine
|
|
25
|
-
* @returns {string}
|
|
26
|
-
*/
|
|
27
|
-
const drawBorder = (columnSizeIndex, {
|
|
28
|
-
border,
|
|
29
|
-
drawVerticalLine
|
|
30
|
-
}) => {
|
|
31
|
-
const columns = columnSizeIndex.map(size => {
|
|
32
|
-
return border.body.repeat(size);
|
|
33
|
-
});
|
|
34
|
-
return (0, _drawHorizontalContent.default)(columns, {
|
|
35
|
-
drawVerticalLine,
|
|
36
|
-
separator: border
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* @param {number[]} columnSizeIndex
|
|
41
|
-
* @param {table~config} config
|
|
42
|
-
* @returns {string}
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
exports.drawBorder = drawBorder;
|
|
47
|
-
|
|
48
|
-
const drawBorderTop = (columnSizeIndex, {
|
|
49
|
-
border,
|
|
50
|
-
drawVerticalLine
|
|
51
|
-
}) => {
|
|
52
|
-
const result = drawBorder(columnSizeIndex, {
|
|
53
|
-
border: {
|
|
54
|
-
body: border.topBody,
|
|
55
|
-
join: border.topJoin,
|
|
56
|
-
left: border.topLeft,
|
|
57
|
-
right: border.topRight
|
|
58
|
-
},
|
|
59
|
-
drawVerticalLine
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (result === '\n') {
|
|
63
|
-
return '';
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return result;
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* @param {number[]} columnSizeIndex
|
|
70
|
-
* @param {table~config} config
|
|
71
|
-
* @returns {string}
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
exports.drawBorderTop = drawBorderTop;
|
|
76
|
-
|
|
77
|
-
const drawBorderJoin = (columnSizeIndex, {
|
|
78
|
-
border,
|
|
79
|
-
drawVerticalLine
|
|
80
|
-
}) => {
|
|
81
|
-
return drawBorder(columnSizeIndex, {
|
|
82
|
-
border: {
|
|
83
|
-
body: border.joinBody,
|
|
84
|
-
join: border.joinJoin,
|
|
85
|
-
left: border.joinLeft,
|
|
86
|
-
right: border.joinRight
|
|
87
|
-
},
|
|
88
|
-
drawVerticalLine
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* @param {number[]} columnSizeIndex
|
|
93
|
-
* @param {table~config} config
|
|
94
|
-
* @returns {string}
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
exports.drawBorderJoin = drawBorderJoin;
|
|
99
|
-
|
|
100
|
-
const drawBorderBottom = (columnSizeIndex, {
|
|
101
|
-
border,
|
|
102
|
-
drawVerticalLine
|
|
103
|
-
}) => {
|
|
104
|
-
return drawBorder(columnSizeIndex, {
|
|
105
|
-
border: {
|
|
106
|
-
body: border.bottomBody,
|
|
107
|
-
join: border.bottomJoin,
|
|
108
|
-
left: border.bottomLeft,
|
|
109
|
-
right: border.bottomRight
|
|
110
|
-
},
|
|
111
|
-
drawVerticalLine
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
exports.drawBorderBottom = drawBorderBottom;
|