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
package/README.md
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const is_number_object_1 = __importDefault(require("is-number-object"));
|
|
7
|
+
const is_string_1 = __importDefault(require("is-string"));
|
|
8
|
+
const string_width_1 = __importDefault(require("string-width"));
|
|
9
|
+
const alignLeft = (subject, width) => {
|
|
10
|
+
return subject + ' '.repeat(width);
|
|
11
|
+
};
|
|
12
|
+
const alignRight = (subject, width) => {
|
|
13
|
+
return ' '.repeat(width) + subject;
|
|
14
|
+
};
|
|
15
|
+
const alignCenter = (subject, width) => {
|
|
16
|
+
let halfWidth;
|
|
17
|
+
halfWidth = width / 2;
|
|
18
|
+
if (width % 2 === 0) {
|
|
19
|
+
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
halfWidth = Math.floor(halfWidth);
|
|
23
|
+
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const alignments = [
|
|
27
|
+
'left',
|
|
28
|
+
'right',
|
|
29
|
+
'center',
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* Pads a string to the left and/or right to position the subject
|
|
33
|
+
* text in a desired alignment within a container.
|
|
34
|
+
*/
|
|
35
|
+
exports.default = (subject, containerWidth, alignment) => {
|
|
36
|
+
if (!is_string_1.default(subject)) {
|
|
37
|
+
throw new TypeError('Subject parameter value must be a string.');
|
|
38
|
+
}
|
|
39
|
+
if (!is_number_object_1.default(containerWidth)) {
|
|
40
|
+
throw new TypeError('Container width parameter value must be a number.');
|
|
41
|
+
}
|
|
42
|
+
const subjectWidth = string_width_1.default(subject);
|
|
43
|
+
if (subjectWidth > containerWidth) {
|
|
44
|
+
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
|
45
|
+
}
|
|
46
|
+
if (!is_string_1.default(alignment)) {
|
|
47
|
+
throw new TypeError('Alignment parameter value must be a string.');
|
|
48
|
+
}
|
|
49
|
+
if (!alignments.includes(alignment)) {
|
|
50
|
+
throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
|
|
51
|
+
}
|
|
52
|
+
if (subjectWidth === 0) {
|
|
53
|
+
return ' '.repeat(containerWidth);
|
|
54
|
+
}
|
|
55
|
+
const availableWidth = containerWidth - subjectWidth;
|
|
56
|
+
if (alignment === 'left') {
|
|
57
|
+
return alignLeft(subject, availableWidth);
|
|
58
|
+
}
|
|
59
|
+
if (alignment === 'right') {
|
|
60
|
+
return alignRight(subject, availableWidth);
|
|
61
|
+
}
|
|
62
|
+
return alignCenter(subject, availableWidth);
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=alignString.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const string_width_1 = __importDefault(require("string-width"));
|
|
7
|
+
const alignString_1 = __importDefault(require("./alignString"));
|
|
8
|
+
exports.default = (rows, config) => {
|
|
9
|
+
return rows.map((row) => {
|
|
10
|
+
return row.map((cell, index) => {
|
|
11
|
+
const column = config.columns[index];
|
|
12
|
+
if (string_width_1.default(cell) === column.width) {
|
|
13
|
+
return cell;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return alignString_1.default(cell, column.width, column.alignment);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=alignTableData.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const is_string_1 = __importDefault(require("is-string"));
|
|
7
|
+
const wrapCell_1 = __importDefault(require("./wrapCell"));
|
|
8
|
+
exports.default = (value, columnWidth, useWrapWord = false) => {
|
|
9
|
+
if (!is_string_1.default(value)) {
|
|
10
|
+
throw new TypeError('Value must be a string.');
|
|
11
|
+
}
|
|
12
|
+
if (!Number.isInteger(columnWidth) || columnWidth < 1) {
|
|
13
|
+
throw new TypeError('Column width must be an integer greater than 0.');
|
|
14
|
+
}
|
|
15
|
+
return wrapCell_1.default(value, columnWidth, useWrapWord).length;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=calculateCellHeight.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const string_width_1 = __importDefault(require("string-width"));
|
|
7
|
+
/**
|
|
8
|
+
* Calculates width of each cell contents.
|
|
9
|
+
*/
|
|
10
|
+
exports.default = (cells) => {
|
|
11
|
+
return cells.map((value) => {
|
|
12
|
+
return Math.max(...value.split('\n').map((line) => {
|
|
13
|
+
return string_width_1.default(line);
|
|
14
|
+
}));
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=calculateCellWidthIndex.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const calculateCellWidthIndex_1 = __importDefault(require("./calculateCellWidthIndex"));
|
|
7
|
+
/**
|
|
8
|
+
* Produces an array of values that describe the largest value length (width) in every column.
|
|
9
|
+
*/
|
|
10
|
+
exports.default = (rows) => {
|
|
11
|
+
if (!rows[0]) {
|
|
12
|
+
throw new Error('Dataset must have at least one row.');
|
|
13
|
+
}
|
|
14
|
+
const columns = new Array(rows[0].length).fill(0);
|
|
15
|
+
rows.forEach((row) => {
|
|
16
|
+
const columnWidthIndex = calculateCellWidthIndex_1.default(row);
|
|
17
|
+
columnWidthIndex.forEach((valueWidth, index0) => {
|
|
18
|
+
if (columns[index0] < valueWidth) {
|
|
19
|
+
columns[index0] = valueWidth;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
return columns;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=calculateMaximumColumnWidthIndex.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const is_boolean_object_1 = __importDefault(require("is-boolean-object"));
|
|
7
|
+
const is_number_object_1 = __importDefault(require("is-number-object"));
|
|
8
|
+
const calculateCellHeight_1 = __importDefault(require("./calculateCellHeight"));
|
|
9
|
+
/**
|
|
10
|
+
* Calculates the vertical row span index.
|
|
11
|
+
*/
|
|
12
|
+
exports.default = (rows, config) => {
|
|
13
|
+
const tableWidth = rows[0].length;
|
|
14
|
+
const rowSpanIndex = [];
|
|
15
|
+
rows.forEach((cells) => {
|
|
16
|
+
const cellHeightIndex = new Array(tableWidth).fill(1);
|
|
17
|
+
cells.forEach((value, index1) => {
|
|
18
|
+
if (!is_number_object_1.default(config.columns[index1].width)) {
|
|
19
|
+
throw new TypeError('column[index].width must be a number.');
|
|
20
|
+
}
|
|
21
|
+
if (!is_boolean_object_1.default(config.columns[index1].wrapWord)) {
|
|
22
|
+
throw new TypeError('column[index].wrapWord must be a boolean.');
|
|
23
|
+
}
|
|
24
|
+
cellHeightIndex[index1] = calculateCellHeight_1.default(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
25
|
+
});
|
|
26
|
+
rowSpanIndex.push(Math.max(...cellHeightIndex));
|
|
27
|
+
});
|
|
28
|
+
return rowSpanIndex;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=calculateRowHeightIndex.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const alignTableData_1 = __importDefault(require("./alignTableData"));
|
|
7
|
+
const calculateRowHeightIndex_1 = __importDefault(require("./calculateRowHeightIndex"));
|
|
8
|
+
const drawBorder_1 = require("./drawBorder");
|
|
9
|
+
const drawRow_1 = __importDefault(require("./drawRow"));
|
|
10
|
+
const makeStreamConfig_1 = __importDefault(require("./makeStreamConfig"));
|
|
11
|
+
const mapDataUsingRowHeightIndex_1 = __importDefault(require("./mapDataUsingRowHeightIndex"));
|
|
12
|
+
const padTableData_1 = __importDefault(require("./padTableData"));
|
|
13
|
+
const stringifyTableData_1 = __importDefault(require("./stringifyTableData"));
|
|
14
|
+
const truncateTableData_1 = __importDefault(require("./truncateTableData"));
|
|
15
|
+
const prepareData = (data, config) => {
|
|
16
|
+
let rows = stringifyTableData_1.default(data);
|
|
17
|
+
rows = truncateTableData_1.default(rows, config);
|
|
18
|
+
const rowHeightIndex = calculateRowHeightIndex_1.default(rows, config);
|
|
19
|
+
rows = mapDataUsingRowHeightIndex_1.default(rows, rowHeightIndex, config);
|
|
20
|
+
rows = alignTableData_1.default(rows, config);
|
|
21
|
+
rows = padTableData_1.default(rows, config);
|
|
22
|
+
return rows;
|
|
23
|
+
};
|
|
24
|
+
const create = (row, columnWidthIndex, config) => {
|
|
25
|
+
const rows = prepareData([row], config);
|
|
26
|
+
const body = rows.map((literalRow) => {
|
|
27
|
+
return drawRow_1.default(literalRow, config);
|
|
28
|
+
}).join('');
|
|
29
|
+
let output;
|
|
30
|
+
output = '';
|
|
31
|
+
output += drawBorder_1.drawBorderTop(columnWidthIndex, config);
|
|
32
|
+
output += body;
|
|
33
|
+
output += drawBorder_1.drawBorderBottom(columnWidthIndex, config);
|
|
34
|
+
output = output.trimEnd();
|
|
35
|
+
process.stdout.write(output);
|
|
36
|
+
};
|
|
37
|
+
const append = (row, columnWidthIndex, config) => {
|
|
38
|
+
const rows = prepareData([row], config);
|
|
39
|
+
const body = rows.map((literalRow) => {
|
|
40
|
+
return drawRow_1.default(literalRow, config);
|
|
41
|
+
}).join('');
|
|
42
|
+
let output = '';
|
|
43
|
+
const bottom = drawBorder_1.drawBorderBottom(columnWidthIndex, config);
|
|
44
|
+
if (bottom !== '\n') {
|
|
45
|
+
output = '\r\u001B[K';
|
|
46
|
+
}
|
|
47
|
+
output += drawBorder_1.drawBorderJoin(columnWidthIndex, config);
|
|
48
|
+
output += body;
|
|
49
|
+
output += bottom;
|
|
50
|
+
output = output.trimEnd();
|
|
51
|
+
process.stdout.write(output);
|
|
52
|
+
};
|
|
53
|
+
exports.default = (userConfig) => {
|
|
54
|
+
const config = makeStreamConfig_1.default(userConfig);
|
|
55
|
+
const columnWidthIndex = Object.values(config.columns).map((column) => {
|
|
56
|
+
return column.width + column.paddingLeft + column.paddingRight;
|
|
57
|
+
});
|
|
58
|
+
let empty = true;
|
|
59
|
+
return {
|
|
60
|
+
write: (row) => {
|
|
61
|
+
if (row.length !== config.columnCount) {
|
|
62
|
+
throw new Error('Row cell count does not match the config.columnCount.');
|
|
63
|
+
}
|
|
64
|
+
if (empty) {
|
|
65
|
+
empty = false;
|
|
66
|
+
create(row, columnWidthIndex, config);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
append(row, columnWidthIndex, config);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=createStream.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = void 0;
|
|
7
|
+
const drawHorizontalContent_1 = __importDefault(require("./drawHorizontalContent"));
|
|
8
|
+
const drawBorder = (columnSizeIndex, config) => {
|
|
9
|
+
const columns = columnSizeIndex.map((size) => {
|
|
10
|
+
return config.separator.body.repeat(size);
|
|
11
|
+
});
|
|
12
|
+
return drawHorizontalContent_1.default(columns, config);
|
|
13
|
+
};
|
|
14
|
+
exports.drawBorder = drawBorder;
|
|
15
|
+
const drawBorderTop = (columnSizeIndex, config) => {
|
|
16
|
+
const result = drawBorder(columnSizeIndex, {
|
|
17
|
+
...config,
|
|
18
|
+
separator: {
|
|
19
|
+
body: config.border.topBody,
|
|
20
|
+
join: config.border.topJoin,
|
|
21
|
+
left: config.border.topLeft,
|
|
22
|
+
right: config.border.topRight,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
if (result === '\n') {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
exports.drawBorderTop = drawBorderTop;
|
|
31
|
+
const drawBorderJoin = (columnSizeIndex, config) => {
|
|
32
|
+
return drawBorder(columnSizeIndex, {
|
|
33
|
+
...config,
|
|
34
|
+
separator: {
|
|
35
|
+
body: config.border.joinBody,
|
|
36
|
+
join: config.border.joinJoin,
|
|
37
|
+
left: config.border.joinLeft,
|
|
38
|
+
right: config.border.joinRight,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
exports.drawBorderJoin = drawBorderJoin;
|
|
43
|
+
const drawBorderBottom = (columnSizeIndex, config) => {
|
|
44
|
+
return drawBorder(columnSizeIndex, {
|
|
45
|
+
...config,
|
|
46
|
+
separator: {
|
|
47
|
+
body: config.border.bottomBody,
|
|
48
|
+
join: config.border.bottomJoin,
|
|
49
|
+
left: config.border.bottomLeft,
|
|
50
|
+
right: config.border.bottomRight,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
exports.drawBorderBottom = drawBorderBottom;
|
|
55
|
+
//# sourceMappingURL=drawBorder.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function drawHorizontalContent(contents, config) {
|
|
4
|
+
const { separator, drawVerticalLine } = config;
|
|
5
|
+
const contentSize = contents.length;
|
|
6
|
+
const result = [];
|
|
7
|
+
result.push(drawVerticalLine(0, contentSize) ? separator.left : '');
|
|
8
|
+
contents.forEach((content, index) => {
|
|
9
|
+
result.push(content);
|
|
10
|
+
// Only append the join separator if it is not the last content
|
|
11
|
+
if (index + 1 < contentSize) {
|
|
12
|
+
result.push(drawVerticalLine(index + 1, contentSize) ? separator.join : '');
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
result.push(drawVerticalLine(contentSize, contentSize) ? separator.right : '');
|
|
16
|
+
return result.join('') + '\n';
|
|
17
|
+
}
|
|
18
|
+
exports.default = drawHorizontalContent;
|
|
19
|
+
//# sourceMappingURL=drawHorizontalContent.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const drawHorizontalContent_1 = __importDefault(require("./drawHorizontalContent"));
|
|
7
|
+
exports.default = (row, config) => {
|
|
8
|
+
return drawHorizontalContent_1.default(row, {
|
|
9
|
+
...config,
|
|
10
|
+
separator: {
|
|
11
|
+
join: config.border.bodyJoin,
|
|
12
|
+
left: config.border.bodyLeft,
|
|
13
|
+
right: config.border.bodyRight,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=drawRow.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const drawBorder_1 = require("./drawBorder");
|
|
7
|
+
const drawRow_1 = __importDefault(require("./drawRow"));
|
|
8
|
+
exports.default = (rows, columnSizeIndex, rowSpanIndex, config) => {
|
|
9
|
+
const { drawHorizontalLine, singleLine, } = config;
|
|
10
|
+
let output;
|
|
11
|
+
let realRowIndex;
|
|
12
|
+
let rowHeight;
|
|
13
|
+
const rowCount = rows.length;
|
|
14
|
+
realRowIndex = 0;
|
|
15
|
+
output = '';
|
|
16
|
+
if (drawHorizontalLine(realRowIndex, rowCount)) {
|
|
17
|
+
output += drawBorder_1.drawBorderTop(columnSizeIndex, config);
|
|
18
|
+
}
|
|
19
|
+
rows.forEach((row, index0) => {
|
|
20
|
+
output += drawRow_1.default(row, config);
|
|
21
|
+
if (!rowHeight) {
|
|
22
|
+
rowHeight = rowSpanIndex[realRowIndex];
|
|
23
|
+
realRowIndex++;
|
|
24
|
+
}
|
|
25
|
+
rowHeight--;
|
|
26
|
+
if (!singleLine &&
|
|
27
|
+
rowHeight === 0 &&
|
|
28
|
+
index0 !== rowCount - 1 &&
|
|
29
|
+
drawHorizontalLine(realRowIndex, rowCount)) {
|
|
30
|
+
output += drawBorder_1.drawBorderJoin(columnSizeIndex, config);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (drawHorizontalLine(realRowIndex, rowCount)) {
|
|
34
|
+
output += drawBorder_1.drawBorderBottom(columnSizeIndex, config);
|
|
35
|
+
}
|
|
36
|
+
return output;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=drawTable.js.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = (name) => {
|
|
5
|
+
if (name === 'honeywell') {
|
|
6
|
+
return {
|
|
7
|
+
topBody: '═',
|
|
8
|
+
topJoin: '╤',
|
|
9
|
+
topLeft: '╔',
|
|
10
|
+
topRight: '╗',
|
|
11
|
+
bottomBody: '═',
|
|
12
|
+
bottomJoin: '╧',
|
|
13
|
+
bottomLeft: '╚',
|
|
14
|
+
bottomRight: '╝',
|
|
15
|
+
bodyLeft: '║',
|
|
16
|
+
bodyRight: '║',
|
|
17
|
+
bodyJoin: '│',
|
|
18
|
+
joinBody: '─',
|
|
19
|
+
joinLeft: '╟',
|
|
20
|
+
joinRight: '╢',
|
|
21
|
+
joinJoin: '┼',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (name === 'norc') {
|
|
25
|
+
return {
|
|
26
|
+
topBody: '─',
|
|
27
|
+
topJoin: '┬',
|
|
28
|
+
topLeft: '┌',
|
|
29
|
+
topRight: '┐',
|
|
30
|
+
bottomBody: '─',
|
|
31
|
+
bottomJoin: '┴',
|
|
32
|
+
bottomLeft: '└',
|
|
33
|
+
bottomRight: '┘',
|
|
34
|
+
bodyLeft: '│',
|
|
35
|
+
bodyRight: '│',
|
|
36
|
+
bodyJoin: '│',
|
|
37
|
+
joinBody: '─',
|
|
38
|
+
joinLeft: '├',
|
|
39
|
+
joinRight: '┤',
|
|
40
|
+
joinJoin: '┼',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (name === 'ramac') {
|
|
44
|
+
return {
|
|
45
|
+
topBody: '-',
|
|
46
|
+
topJoin: '+',
|
|
47
|
+
topLeft: '+',
|
|
48
|
+
topRight: '+',
|
|
49
|
+
bottomBody: '-',
|
|
50
|
+
bottomJoin: '+',
|
|
51
|
+
bottomLeft: '+',
|
|
52
|
+
bottomRight: '+',
|
|
53
|
+
bodyLeft: '|',
|
|
54
|
+
bodyRight: '|',
|
|
55
|
+
bodyJoin: '|',
|
|
56
|
+
joinBody: '-',
|
|
57
|
+
joinLeft: '|',
|
|
58
|
+
joinRight: '|',
|
|
59
|
+
joinJoin: '|',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (name === 'void') {
|
|
63
|
+
return {
|
|
64
|
+
topBody: '',
|
|
65
|
+
topJoin: '',
|
|
66
|
+
topLeft: '',
|
|
67
|
+
topRight: '',
|
|
68
|
+
bottomBody: '',
|
|
69
|
+
bottomJoin: '',
|
|
70
|
+
bottomLeft: '',
|
|
71
|
+
bottomRight: '',
|
|
72
|
+
bodyLeft: '',
|
|
73
|
+
bodyRight: '',
|
|
74
|
+
bodyJoin: '',
|
|
75
|
+
joinBody: '',
|
|
76
|
+
joinLeft: '',
|
|
77
|
+
joinRight: '',
|
|
78
|
+
joinJoin: '',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
throw new Error('Unknown border template "' + name + '".');
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=getBorderCharacters.js.map
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import createStream from './createStream';
|
|
2
2
|
import getBorderCharacters from './getBorderCharacters';
|
|
3
3
|
import table from './table';
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
table,
|
|
7
|
-
createStream,
|
|
8
|
-
getBorderCharacters,
|
|
9
|
-
};
|
|
4
|
+
export { table, createStream, getBorderCharacters, };
|
|
5
|
+
export * from './types/api';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.getBorderCharacters = exports.createStream = exports.table = void 0;
|
|
17
|
+
const createStream_1 = __importDefault(require("./createStream"));
|
|
18
|
+
exports.createStream = createStream_1.default;
|
|
19
|
+
const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters"));
|
|
20
|
+
exports.getBorderCharacters = getBorderCharacters_1.default;
|
|
21
|
+
const table_1 = __importDefault(require("./table"));
|
|
22
|
+
exports.table = table_1.default;
|
|
23
|
+
__exportStar(require("./types/api"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
7
|
+
const calculateMaximumColumnWidthIndex_1 = __importDefault(require("./calculateMaximumColumnWidthIndex"));
|
|
8
|
+
const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters"));
|
|
9
|
+
const validateConfig_1 = __importDefault(require("./validateConfig"));
|
|
10
|
+
/**
|
|
11
|
+
* Merges user provided border characters with the default border ("honeywell") characters.
|
|
12
|
+
*/
|
|
13
|
+
const makeBorder = (border) => {
|
|
14
|
+
return {
|
|
15
|
+
...getBorderCharacters_1.default('honeywell'),
|
|
16
|
+
...border,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Creates a configuration for every column using default
|
|
21
|
+
* values for the missing configuration properties.
|
|
22
|
+
*/
|
|
23
|
+
const makeColumns = (rows, columns, columnDefault) => {
|
|
24
|
+
const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex_1.default(rows);
|
|
25
|
+
return rows[0].map((_cell, index) => {
|
|
26
|
+
return {
|
|
27
|
+
alignment: 'left',
|
|
28
|
+
paddingLeft: 1,
|
|
29
|
+
paddingRight: 1,
|
|
30
|
+
truncate: Number.POSITIVE_INFINITY,
|
|
31
|
+
width: maximumColumnWidthIndex[index],
|
|
32
|
+
wrapWord: false,
|
|
33
|
+
...columnDefault,
|
|
34
|
+
...columns === null || columns === void 0 ? void 0 : columns[index],
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Makes a new configuration object out of the userConfig object
|
|
40
|
+
* using default values for the missing configuration properties.
|
|
41
|
+
*/
|
|
42
|
+
exports.default = (rows, userConfig = {}) => {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
validateConfig_1.default('config.json', userConfig);
|
|
45
|
+
const config = lodash_clonedeep_1.default(userConfig);
|
|
46
|
+
return {
|
|
47
|
+
...config,
|
|
48
|
+
border: makeBorder(config.border),
|
|
49
|
+
columns: makeColumns(rows, config.columns, config.columnDefault),
|
|
50
|
+
drawHorizontalLine: (_a = config.drawHorizontalLine) !== null && _a !== void 0 ? _a : (() => {
|
|
51
|
+
return true;
|
|
52
|
+
}),
|
|
53
|
+
drawVerticalLine: (_b = config.drawVerticalLine) !== null && _b !== void 0 ? _b : (() => {
|
|
54
|
+
return true;
|
|
55
|
+
}),
|
|
56
|
+
singleLine: (_c = config.singleLine) !== null && _c !== void 0 ? _c : false,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=makeConfig.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
7
|
+
const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters"));
|
|
8
|
+
const validateConfig_1 = __importDefault(require("./validateConfig"));
|
|
9
|
+
/**
|
|
10
|
+
* Merges user provided border characters with the default border ("honeywell") characters.
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
const makeBorder = (border) => {
|
|
14
|
+
return {
|
|
15
|
+
...getBorderCharacters_1.default('honeywell'),
|
|
16
|
+
...border,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Creates a configuration for every column using default
|
|
21
|
+
* values for the missing configuration properties.
|
|
22
|
+
*/
|
|
23
|
+
const makeColumns = (columnCount, columns = {}, columnDefault) => {
|
|
24
|
+
return Array.from({ length: columnCount }).map((_, index) => {
|
|
25
|
+
return {
|
|
26
|
+
alignment: 'left',
|
|
27
|
+
paddingLeft: 1,
|
|
28
|
+
paddingRight: 1,
|
|
29
|
+
truncate: Number.POSITIVE_INFINITY,
|
|
30
|
+
wrapWord: false,
|
|
31
|
+
...columnDefault,
|
|
32
|
+
...columns[index],
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Makes a new configuration object out of the userConfig object
|
|
38
|
+
* using default values for the missing configuration properties.
|
|
39
|
+
*/
|
|
40
|
+
exports.default = (userConfig) => {
|
|
41
|
+
var _a;
|
|
42
|
+
validateConfig_1.default('streamConfig.json', userConfig);
|
|
43
|
+
const config = lodash_clonedeep_1.default(userConfig);
|
|
44
|
+
if (!config.columnDefault || !config.columnDefault.width) {
|
|
45
|
+
throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
|
46
|
+
}
|
|
47
|
+
if (!config.columnCount) {
|
|
48
|
+
throw new Error('Must provide config.columnCount.');
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...config,
|
|
52
|
+
border: makeBorder(config.border),
|
|
53
|
+
columnCount: config.columnCount,
|
|
54
|
+
columns: makeColumns(config.columnCount, config.columns, config.columnDefault),
|
|
55
|
+
drawVerticalLine: (_a = config.drawVerticalLine) !== null && _a !== void 0 ? _a : (() => {
|
|
56
|
+
return true;
|
|
57
|
+
}),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=makeStreamConfig.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const lodash_flatten_1 = __importDefault(require("lodash.flatten"));
|
|
7
|
+
const wrapCell_1 = __importDefault(require("./wrapCell"));
|
|
8
|
+
exports.default = (unmappedRows, rowHeightIndex, config) => {
|
|
9
|
+
const tableWidth = unmappedRows[0].length;
|
|
10
|
+
const mappedRows = unmappedRows.map((row, index0) => {
|
|
11
|
+
const rowHeight = Array.from({ length: rowHeightIndex[index0] }, () => {
|
|
12
|
+
return new Array(tableWidth).fill('');
|
|
13
|
+
});
|
|
14
|
+
// rowHeight
|
|
15
|
+
// [{row index within rowSaw; index2}]
|
|
16
|
+
// [{cell index within a virtual row; index1}]
|
|
17
|
+
row.forEach((cell, index1) => {
|
|
18
|
+
const cellLines = wrapCell_1.default(cell, config.columns[index1].width, config.columns[index1].wrapWord);
|
|
19
|
+
cellLines.forEach((cellLine, index2) => {
|
|
20
|
+
rowHeight[index2][index1] = cellLine;
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
return rowHeight;
|
|
24
|
+
});
|
|
25
|
+
return lodash_flatten_1.default(mappedRows);
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=mapDataUsingRowHeightIndex.js.map
|