table 6.5.1 → 6.7.2
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 +407 -434
- package/dist/alignString.d.ts +2 -3
- package/dist/alignString.js +23 -11
- package/dist/alignTableData.d.ts +1 -2
- package/dist/alignTableData.js +7 -14
- package/dist/calculateCellHeight.d.ts +4 -2
- package/dist/calculateCellHeight.js +8 -9
- package/dist/calculateCellWidths.d.ts +5 -0
- package/dist/{calculateCellWidthIndex.js → calculateCellWidths.js} +6 -6
- package/dist/{calculateMaximumColumnWidthIndex.d.ts → calculateColumnWidths.d.ts} +0 -0
- package/dist/calculateColumnWidths.js +16 -0
- package/dist/calculateRowHeights.d.ts +5 -0
- package/dist/calculateRowHeights.js +18 -0
- package/dist/createStream.d.ts +1 -2
- package/dist/createStream.js +29 -30
- package/dist/drawBorder.d.ts +6 -5
- package/dist/drawBorder.js +60 -14
- package/dist/drawContent.d.ts +9 -0
- package/dist/drawContent.js +26 -0
- package/dist/drawHeader.d.ts +2 -0
- package/dist/drawHeader.js +29 -0
- package/dist/drawRow.d.ts +1 -2
- package/dist/drawRow.js +16 -12
- package/dist/drawTable.d.ts +1 -2
- package/dist/drawTable.js +26 -36
- package/dist/generated/validators.d.ts +2 -2
- package/dist/generated/validators.js +657 -307
- package/dist/getBorderCharacters.d.ts +1 -2
- package/dist/getBorderCharacters.js +7 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -9
- package/dist/makeStreamConfig.d.ts +1 -2
- package/dist/makeStreamConfig.js +14 -26
- package/dist/{makeConfig.d.ts → makeTableConfig.d.ts} +1 -2
- package/dist/{makeConfig.js → makeTableConfig.js} +29 -21
- package/dist/mapDataUsingRowHeights.d.ts +2 -0
- package/dist/mapDataUsingRowHeights.js +44 -0
- package/dist/padTableData.d.ts +2 -2
- package/dist/padTableData.js +10 -4
- package/dist/stringifyTableData.d.ts +1 -2
- package/dist/stringifyTableData.js +7 -2
- package/dist/table.d.ts +1 -2
- package/dist/table.js +23 -24
- package/dist/truncateTableData.d.ts +2 -2
- package/dist/truncateTableData.js +10 -6
- package/dist/types/api.d.ts +18 -4
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +92 -0
- package/dist/validateConfig.d.ts +1 -2
- package/dist/validateConfig.js +3 -1
- package/dist/validateTableData.d.ts +1 -2
- package/dist/validateTableData.js +5 -2
- package/dist/wrapCell.d.ts +1 -2
- package/dist/wrapCell.js +9 -24
- package/dist/wrapString.d.ts +1 -2
- package/dist/wrapString.js +3 -1
- package/dist/wrapWord.d.ts +1 -2
- package/dist/wrapWord.js +3 -1
- package/package.json +6 -7
- package/dist/calculateCellWidthIndex.d.ts +0 -6
- package/dist/calculateMaximumColumnWidthIndex.js +0 -24
- package/dist/calculateRowHeightIndex.d.ts +0 -6
- package/dist/calculateRowHeightIndex.js +0 -21
- package/dist/drawHorizontalContent.d.ts +0 -11
- package/dist/drawHorizontalContent.js +0 -18
- package/dist/mapDataUsingRowHeightIndex.d.ts +0 -3
- package/dist/mapDataUsingRowHeightIndex.js +0 -26
package/dist/alignString.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare const _default: (subject: string, containerWidth: number, alignment: ColumnUserConfig['alignment']) => string;
|
|
1
|
+
import type { Alignment } from './types/api';
|
|
3
2
|
/**
|
|
4
3
|
* Pads a string to the left and/or right to position the subject
|
|
5
4
|
* text in a desired alignment within a container.
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
6
|
+
export declare const alignString: (subject: string, containerWidth: number, alignment: Alignment) => string;
|
package/dist/alignString.js
CHANGED
|
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.alignString = void 0;
|
|
6
7
|
const string_width_1 = __importDefault(require("string-width"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
7
9
|
const alignLeft = (subject, width) => {
|
|
8
10
|
return subject + ' '.repeat(width);
|
|
9
11
|
};
|
|
@@ -11,25 +13,31 @@ const alignRight = (subject, width) => {
|
|
|
11
13
|
return ' '.repeat(width) + subject;
|
|
12
14
|
};
|
|
13
15
|
const alignCenter = (subject, width) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
return ' '.repeat(Math.floor(width / 2)) + subject + ' '.repeat(Math.ceil(width / 2));
|
|
17
|
+
};
|
|
18
|
+
const alignJustify = (subject, width) => {
|
|
19
|
+
const spaceSequenceCount = utils_1.countSpaceSequence(subject);
|
|
20
|
+
if (spaceSequenceCount === 0) {
|
|
21
|
+
return alignLeft(subject, width);
|
|
18
22
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return
|
|
23
|
+
const addingSpaces = utils_1.distributeUnevenly(width, spaceSequenceCount);
|
|
24
|
+
if (Math.max(...addingSpaces) > 3) {
|
|
25
|
+
return alignLeft(subject, width);
|
|
22
26
|
}
|
|
27
|
+
let spaceSequenceIndex = 0;
|
|
28
|
+
return subject.replace(/\s+/g, (groupSpace) => {
|
|
29
|
+
return groupSpace + ' '.repeat(addingSpaces[spaceSequenceIndex++]);
|
|
30
|
+
});
|
|
23
31
|
};
|
|
24
32
|
/**
|
|
25
33
|
* Pads a string to the left and/or right to position the subject
|
|
26
34
|
* text in a desired alignment within a container.
|
|
27
35
|
*/
|
|
28
|
-
|
|
29
|
-
if (typeof subject !== 'string') {
|
|
30
|
-
throw new TypeError('Subject parameter value must be a string.');
|
|
31
|
-
}
|
|
36
|
+
const alignString = (subject, containerWidth, alignment) => {
|
|
32
37
|
const subjectWidth = string_width_1.default(subject);
|
|
38
|
+
if (subjectWidth === containerWidth) {
|
|
39
|
+
return subject;
|
|
40
|
+
}
|
|
33
41
|
if (subjectWidth > containerWidth) {
|
|
34
42
|
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
|
35
43
|
}
|
|
@@ -43,5 +51,9 @@ exports.default = (subject, containerWidth, alignment) => {
|
|
|
43
51
|
if (alignment === 'right') {
|
|
44
52
|
return alignRight(subject, availableWidth);
|
|
45
53
|
}
|
|
54
|
+
if (alignment === 'justify') {
|
|
55
|
+
return alignJustify(subject, availableWidth);
|
|
56
|
+
}
|
|
46
57
|
return alignCenter(subject, availableWidth);
|
|
47
58
|
};
|
|
59
|
+
exports.alignString = alignString;
|
package/dist/alignTableData.d.ts
CHANGED
package/dist/alignTableData.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
const alignString_1 =
|
|
8
|
-
|
|
3
|
+
exports.alignTableData = void 0;
|
|
4
|
+
const alignString_1 = require("./alignString");
|
|
5
|
+
const alignTableData = (rows, config) => {
|
|
9
6
|
return rows.map((row) => {
|
|
10
|
-
return row.map((cell,
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
return cell;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
return alignString_1.default(cell, column.width, column.alignment);
|
|
17
|
-
}
|
|
7
|
+
return row.map((cell, cellIndex) => {
|
|
8
|
+
const { width, alignment } = config.columns[cellIndex];
|
|
9
|
+
return alignString_1.alignString(cell, width, alignment);
|
|
18
10
|
});
|
|
19
11
|
});
|
|
20
12
|
};
|
|
13
|
+
exports.alignTableData = alignTableData;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Calculates height of cell content in regard to its width and word wrapping.
|
|
3
|
+
*/
|
|
4
|
+
export declare const calculateCellHeight: (value: string, columnWidth: number, useWrapWord?: boolean) => number;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
exports.calculateCellHeight = void 0;
|
|
4
|
+
const wrapCell_1 = require("./wrapCell");
|
|
5
|
+
/**
|
|
6
|
+
* Calculates height of cell content in regard to its width and word wrapping.
|
|
7
|
+
*/
|
|
8
|
+
const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
|
|
9
|
+
return wrapCell_1.wrapCell(value, columnWidth, useWrapWord).length;
|
|
12
10
|
};
|
|
11
|
+
exports.calculateCellHeight = calculateCellHeight;
|
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.calculateCellWidths = void 0;
|
|
6
7
|
const string_width_1 = __importDefault(require("string-width"));
|
|
7
8
|
/**
|
|
8
|
-
* Calculates width of each cell contents.
|
|
9
|
+
* Calculates width of each cell contents in a row.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
return cells.map((
|
|
12
|
-
return Math.max(...
|
|
13
|
-
return string_width_1.default(line);
|
|
14
|
-
}));
|
|
11
|
+
const calculateCellWidths = (cells) => {
|
|
12
|
+
return cells.map((cell) => {
|
|
13
|
+
return Math.max(...cell.split('\n').map(string_width_1.default));
|
|
15
14
|
});
|
|
16
15
|
};
|
|
16
|
+
exports.calculateCellWidths = calculateCellWidths;
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const calculateCellWidths_1 = require("./calculateCellWidths");
|
|
4
|
+
/**
|
|
5
|
+
* Produces an array of values that describe the largest value length (width) in every column.
|
|
6
|
+
*/
|
|
7
|
+
exports.default = (rows) => {
|
|
8
|
+
const columnWidths = new Array(rows[0].length).fill(0);
|
|
9
|
+
rows.forEach((row) => {
|
|
10
|
+
const cellWidths = calculateCellWidths_1.calculateCellWidths(row);
|
|
11
|
+
cellWidths.forEach((cellWidth, cellIndex) => {
|
|
12
|
+
columnWidths[cellIndex] = Math.max(columnWidths[cellIndex], cellWidth);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
return columnWidths;
|
|
16
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateRowHeights = void 0;
|
|
4
|
+
const calculateCellHeight_1 = require("./calculateCellHeight");
|
|
5
|
+
/**
|
|
6
|
+
* Produces an array of values that describe the largest value length (height) in every row.
|
|
7
|
+
*/
|
|
8
|
+
const calculateRowHeights = (rows, config) => {
|
|
9
|
+
return rows.map((row) => {
|
|
10
|
+
let rowHeight = 1;
|
|
11
|
+
row.forEach((cell, cellIndex) => {
|
|
12
|
+
const cellHeight = calculateCellHeight_1.calculateCellHeight(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
|
|
13
|
+
rowHeight = Math.max(rowHeight, cellHeight);
|
|
14
|
+
});
|
|
15
|
+
return rowHeight;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.calculateRowHeights = calculateRowHeights;
|
package/dist/createStream.d.ts
CHANGED
package/dist/createStream.js
CHANGED
|
@@ -1,58 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
const
|
|
3
|
+
exports.createStream = void 0;
|
|
4
|
+
const alignTableData_1 = require("./alignTableData");
|
|
5
|
+
const calculateRowHeights_1 = require("./calculateRowHeights");
|
|
8
6
|
const drawBorder_1 = require("./drawBorder");
|
|
9
|
-
const drawRow_1 =
|
|
10
|
-
const makeStreamConfig_1 =
|
|
11
|
-
const
|
|
12
|
-
const padTableData_1 =
|
|
13
|
-
const stringifyTableData_1 =
|
|
14
|
-
const truncateTableData_1 =
|
|
7
|
+
const drawRow_1 = require("./drawRow");
|
|
8
|
+
const makeStreamConfig_1 = require("./makeStreamConfig");
|
|
9
|
+
const mapDataUsingRowHeights_1 = require("./mapDataUsingRowHeights");
|
|
10
|
+
const padTableData_1 = require("./padTableData");
|
|
11
|
+
const stringifyTableData_1 = require("./stringifyTableData");
|
|
12
|
+
const truncateTableData_1 = require("./truncateTableData");
|
|
15
13
|
const prepareData = (data, config) => {
|
|
16
|
-
let rows = stringifyTableData_1.
|
|
17
|
-
rows = truncateTableData_1.
|
|
18
|
-
const
|
|
19
|
-
rows =
|
|
20
|
-
rows = alignTableData_1.
|
|
21
|
-
rows = padTableData_1.
|
|
14
|
+
let rows = stringifyTableData_1.stringifyTableData(data);
|
|
15
|
+
rows = truncateTableData_1.truncateTableData(rows, config);
|
|
16
|
+
const rowHeights = calculateRowHeights_1.calculateRowHeights(rows, config);
|
|
17
|
+
rows = mapDataUsingRowHeights_1.mapDataUsingRowHeights(rows, rowHeights, config);
|
|
18
|
+
rows = alignTableData_1.alignTableData(rows, config);
|
|
19
|
+
rows = padTableData_1.padTableData(rows, config);
|
|
22
20
|
return rows;
|
|
23
21
|
};
|
|
24
|
-
const create = (row,
|
|
22
|
+
const create = (row, columnWidths, config) => {
|
|
25
23
|
const rows = prepareData([row], config);
|
|
26
24
|
const body = rows.map((literalRow) => {
|
|
27
|
-
return drawRow_1.
|
|
25
|
+
return drawRow_1.drawRow(literalRow, config);
|
|
28
26
|
}).join('');
|
|
29
27
|
let output;
|
|
30
28
|
output = '';
|
|
31
|
-
output += drawBorder_1.drawBorderTop(
|
|
29
|
+
output += drawBorder_1.drawBorderTop(columnWidths, config);
|
|
32
30
|
output += body;
|
|
33
|
-
output += drawBorder_1.drawBorderBottom(
|
|
31
|
+
output += drawBorder_1.drawBorderBottom(columnWidths, config);
|
|
34
32
|
output = output.trimEnd();
|
|
35
33
|
process.stdout.write(output);
|
|
36
34
|
};
|
|
37
|
-
const append = (row,
|
|
35
|
+
const append = (row, columnWidths, config) => {
|
|
38
36
|
const rows = prepareData([row], config);
|
|
39
37
|
const body = rows.map((literalRow) => {
|
|
40
|
-
return drawRow_1.
|
|
38
|
+
return drawRow_1.drawRow(literalRow, config);
|
|
41
39
|
}).join('');
|
|
42
40
|
let output = '';
|
|
43
|
-
const bottom = drawBorder_1.drawBorderBottom(
|
|
41
|
+
const bottom = drawBorder_1.drawBorderBottom(columnWidths, config);
|
|
44
42
|
if (bottom !== '\n') {
|
|
45
43
|
output = '\r\u001B[K';
|
|
46
44
|
}
|
|
47
|
-
output += drawBorder_1.drawBorderJoin(
|
|
45
|
+
output += drawBorder_1.drawBorderJoin(columnWidths, config);
|
|
48
46
|
output += body;
|
|
49
47
|
output += bottom;
|
|
50
48
|
output = output.trimEnd();
|
|
51
49
|
process.stdout.write(output);
|
|
52
50
|
};
|
|
53
|
-
|
|
54
|
-
const config = makeStreamConfig_1.
|
|
55
|
-
const
|
|
51
|
+
const createStream = (userConfig) => {
|
|
52
|
+
const config = makeStreamConfig_1.makeStreamConfig(userConfig);
|
|
53
|
+
const columnWidths = Object.values(config.columns).map((column) => {
|
|
56
54
|
return column.width + column.paddingLeft + column.paddingRight;
|
|
57
55
|
});
|
|
58
56
|
let empty = true;
|
|
@@ -63,11 +61,12 @@ exports.default = (userConfig) => {
|
|
|
63
61
|
}
|
|
64
62
|
if (empty) {
|
|
65
63
|
empty = false;
|
|
66
|
-
create(row,
|
|
64
|
+
create(row, columnWidths, config);
|
|
67
65
|
}
|
|
68
66
|
else {
|
|
69
|
-
append(row,
|
|
67
|
+
append(row, columnWidths, config);
|
|
70
68
|
}
|
|
71
69
|
},
|
|
72
70
|
};
|
|
73
71
|
};
|
|
72
|
+
exports.createStream = createStream;
|
package/dist/drawBorder.d.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import type { DrawVerticalLine } from './types/api';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TableConfig, SeparatorGetter, TopBorderConfig, JoinBorderConfig, BottomBorderConfig } from './types/internal';
|
|
3
3
|
declare type Separator = {
|
|
4
4
|
readonly left: string;
|
|
5
5
|
readonly right: string;
|
|
6
6
|
readonly body: string;
|
|
7
7
|
readonly join: string;
|
|
8
8
|
};
|
|
9
|
-
declare const drawBorder: (
|
|
9
|
+
declare const drawBorder: (columnWidths: number[], config: {
|
|
10
10
|
separator: Separator;
|
|
11
11
|
drawVerticalLine: DrawVerticalLine;
|
|
12
12
|
}) => string;
|
|
13
|
-
declare const drawBorderTop: (
|
|
13
|
+
declare const drawBorderTop: (columnWidths: number[], config: {
|
|
14
14
|
border: TopBorderConfig;
|
|
15
15
|
drawVerticalLine: DrawVerticalLine;
|
|
16
16
|
}) => string;
|
|
17
|
-
declare const drawBorderJoin: (
|
|
17
|
+
declare const drawBorderJoin: (columnWidths: number[], config: {
|
|
18
18
|
border: JoinBorderConfig;
|
|
19
19
|
drawVerticalLine: DrawVerticalLine;
|
|
20
20
|
}) => string;
|
|
21
|
-
declare const drawBorderBottom: (
|
|
21
|
+
declare const drawBorderBottom: (columnWidths: number[], config: {
|
|
22
22
|
border: BottomBorderConfig;
|
|
23
23
|
drawVerticalLine: DrawVerticalLine;
|
|
24
24
|
}) => string;
|
|
25
|
+
export declare const createTableBorderGetter: (columnWidths: number[], config: TableConfig) => SeparatorGetter;
|
|
25
26
|
export { drawBorder, drawBorderBottom, drawBorderJoin, drawBorderTop, };
|
package/dist/drawBorder.js
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = void 0;
|
|
7
|
-
const
|
|
8
|
-
const drawBorder = (
|
|
9
|
-
const
|
|
3
|
+
exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = exports.createTableBorderGetter = void 0;
|
|
4
|
+
const drawContent_1 = require("./drawContent");
|
|
5
|
+
const drawBorder = (columnWidths, config) => {
|
|
6
|
+
const { separator, drawVerticalLine } = config;
|
|
7
|
+
const columns = columnWidths.map((size) => {
|
|
10
8
|
return config.separator.body.repeat(size);
|
|
11
9
|
});
|
|
12
|
-
return
|
|
10
|
+
return drawContent_1.drawContent(columns, {
|
|
11
|
+
drawSeparator: drawVerticalLine,
|
|
12
|
+
separatorGetter: (index, columnCount) => {
|
|
13
|
+
if (index === 0) {
|
|
14
|
+
return separator.left;
|
|
15
|
+
}
|
|
16
|
+
if (index === columnCount) {
|
|
17
|
+
return separator.right;
|
|
18
|
+
}
|
|
19
|
+
return separator.join;
|
|
20
|
+
},
|
|
21
|
+
}) + '\n';
|
|
13
22
|
};
|
|
14
23
|
exports.drawBorder = drawBorder;
|
|
15
|
-
const drawBorderTop = (
|
|
16
|
-
const result = drawBorder(
|
|
24
|
+
const drawBorderTop = (columnWidths, config) => {
|
|
25
|
+
const result = drawBorder(columnWidths, {
|
|
17
26
|
...config,
|
|
18
27
|
separator: {
|
|
19
28
|
body: config.border.topBody,
|
|
@@ -28,8 +37,8 @@ const drawBorderTop = (columnSizeIndex, config) => {
|
|
|
28
37
|
return result;
|
|
29
38
|
};
|
|
30
39
|
exports.drawBorderTop = drawBorderTop;
|
|
31
|
-
const drawBorderJoin = (
|
|
32
|
-
return drawBorder(
|
|
40
|
+
const drawBorderJoin = (columnWidths, config) => {
|
|
41
|
+
return drawBorder(columnWidths, {
|
|
33
42
|
...config,
|
|
34
43
|
separator: {
|
|
35
44
|
body: config.border.joinBody,
|
|
@@ -40,8 +49,8 @@ const drawBorderJoin = (columnSizeIndex, config) => {
|
|
|
40
49
|
});
|
|
41
50
|
};
|
|
42
51
|
exports.drawBorderJoin = drawBorderJoin;
|
|
43
|
-
const drawBorderBottom = (
|
|
44
|
-
return drawBorder(
|
|
52
|
+
const drawBorderBottom = (columnWidths, config) => {
|
|
53
|
+
return drawBorder(columnWidths, {
|
|
45
54
|
...config,
|
|
46
55
|
separator: {
|
|
47
56
|
body: config.border.bottomBody,
|
|
@@ -52,3 +61,40 @@ const drawBorderBottom = (columnSizeIndex, config) => {
|
|
|
52
61
|
});
|
|
53
62
|
};
|
|
54
63
|
exports.drawBorderBottom = drawBorderBottom;
|
|
64
|
+
const createTableBorderGetter = (columnWidths, config) => {
|
|
65
|
+
return (index, size) => {
|
|
66
|
+
if (!config.header) {
|
|
67
|
+
if (index === 0) {
|
|
68
|
+
return drawBorderTop(columnWidths, config);
|
|
69
|
+
}
|
|
70
|
+
if (index === size) {
|
|
71
|
+
return drawBorderBottom(columnWidths, config);
|
|
72
|
+
}
|
|
73
|
+
return drawBorderJoin(columnWidths, config);
|
|
74
|
+
}
|
|
75
|
+
// Deal with the header
|
|
76
|
+
if (index === 0) {
|
|
77
|
+
return drawBorderTop(columnWidths, {
|
|
78
|
+
...config,
|
|
79
|
+
border: {
|
|
80
|
+
...config.border,
|
|
81
|
+
topJoin: config.border.topBody,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (index === 1) {
|
|
86
|
+
return drawBorderJoin(columnWidths, {
|
|
87
|
+
...config,
|
|
88
|
+
border: {
|
|
89
|
+
...config.border,
|
|
90
|
+
joinJoin: config.border.headerJoin,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (index === size) {
|
|
95
|
+
return drawBorderBottom(columnWidths, config);
|
|
96
|
+
}
|
|
97
|
+
return drawBorderJoin(columnWidths, config);
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
exports.createTableBorderGetter = createTableBorderGetter;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare type SeparatorConfig = {
|
|
2
|
+
drawSeparator: (index: number, size: number) => boolean;
|
|
3
|
+
separatorGetter: (index: number, size: number) => string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Shared function to draw horizontal borders, rows or the entire table
|
|
7
|
+
*/
|
|
8
|
+
export declare const drawContent: (contents: string[], separatorConfig: SeparatorConfig) => string;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.drawContent = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Shared function to draw horizontal borders, rows or the entire table
|
|
6
|
+
*/
|
|
7
|
+
const drawContent = (contents, separatorConfig) => {
|
|
8
|
+
const { separatorGetter, drawSeparator } = separatorConfig;
|
|
9
|
+
const contentSize = contents.length;
|
|
10
|
+
const result = [];
|
|
11
|
+
if (drawSeparator(0, contentSize)) {
|
|
12
|
+
result.push(separatorGetter(0, contentSize));
|
|
13
|
+
}
|
|
14
|
+
contents.forEach((content, contentIndex) => {
|
|
15
|
+
result.push(content);
|
|
16
|
+
// Only append the middle separator if the content is not the last
|
|
17
|
+
if (contentIndex + 1 < contentSize && drawSeparator(contentIndex + 1, contentSize)) {
|
|
18
|
+
result.push(separatorGetter(contentIndex + 1, contentSize));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (drawSeparator(contentSize, contentSize)) {
|
|
22
|
+
result.push(separatorGetter(contentSize, contentSize));
|
|
23
|
+
}
|
|
24
|
+
return result.join('');
|
|
25
|
+
};
|
|
26
|
+
exports.drawContent = drawContent;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.drawHeader = void 0;
|
|
4
|
+
const alignString_1 = require("./alignString");
|
|
5
|
+
const drawRow_1 = require("./drawRow");
|
|
6
|
+
const padTableData_1 = require("./padTableData");
|
|
7
|
+
const truncateTableData_1 = require("./truncateTableData");
|
|
8
|
+
const wrapCell_1 = require("./wrapCell");
|
|
9
|
+
const drawHeader = (width, config) => {
|
|
10
|
+
if (!config.header) {
|
|
11
|
+
throw new Error('Can not draw header without header configuration');
|
|
12
|
+
}
|
|
13
|
+
const { alignment, paddingRight, paddingLeft, wrapWord } = config.header;
|
|
14
|
+
let content = config.header.content;
|
|
15
|
+
content = truncateTableData_1.truncateString(content, config.header.truncate);
|
|
16
|
+
const headerLines = wrapCell_1.wrapCell(content, width, wrapWord);
|
|
17
|
+
return headerLines.map((headerLine) => {
|
|
18
|
+
let line = alignString_1.alignString(headerLine, width, alignment);
|
|
19
|
+
line = padTableData_1.padString(line, paddingLeft, paddingRight);
|
|
20
|
+
return drawRow_1.drawRow([line], {
|
|
21
|
+
...config,
|
|
22
|
+
drawVerticalLine: (index) => {
|
|
23
|
+
const columnCount = config.columns.length;
|
|
24
|
+
return config.drawVerticalLine(index === 0 ? 0 : columnCount, columnCount);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}).join('');
|
|
28
|
+
};
|
|
29
|
+
exports.drawHeader = drawHeader;
|
package/dist/drawRow.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { DrawVerticalLine } from './types/api';
|
|
2
2
|
import type { BodyBorderConfig, Row } from './types/internal';
|
|
3
|
-
declare const
|
|
3
|
+
export declare const drawRow: (row: Row, config: {
|
|
4
4
|
border: BodyBorderConfig;
|
|
5
5
|
drawVerticalLine: DrawVerticalLine;
|
|
6
6
|
}) => string;
|
|
7
|
-
export default _default;
|
package/dist/drawRow.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
exports.drawRow = void 0;
|
|
4
|
+
const drawContent_1 = require("./drawContent");
|
|
5
|
+
const drawRow = (row, config) => {
|
|
6
|
+
const { border, drawVerticalLine } = config;
|
|
7
|
+
return drawContent_1.drawContent(row, {
|
|
8
|
+
drawSeparator: drawVerticalLine,
|
|
9
|
+
separatorGetter: (index, columnCount) => {
|
|
10
|
+
if (index === 0) {
|
|
11
|
+
return border.bodyLeft;
|
|
12
|
+
}
|
|
13
|
+
if (index === columnCount) {
|
|
14
|
+
return border.bodyRight;
|
|
15
|
+
}
|
|
16
|
+
return border.bodyJoin;
|
|
14
17
|
},
|
|
15
|
-
});
|
|
18
|
+
}) + '\n';
|
|
16
19
|
};
|
|
20
|
+
exports.drawRow = drawRow;
|
package/dist/drawTable.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import type { TableConfig, Row } from './types/internal';
|
|
2
|
-
declare const
|
|
3
|
-
export default _default;
|
|
2
|
+
export declare const drawTable: (rows: Row[], columnWidths: number[], rowHeights: number[], config: TableConfig) => string;
|