table 6.5.1 → 6.6.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 +20 -25
- package/dist/alignString.d.ts +2 -3
- package/dist/alignString.js +21 -4
- package/dist/alignTableData.d.ts +1 -2
- package/dist/alignTableData.js +7 -5
- 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 +4 -4
- package/dist/drawBorder.js +16 -13
- package/dist/drawContent.d.ts +11 -0
- package/dist/drawContent.js +26 -0
- package/dist/drawRow.d.ts +1 -2
- package/dist/drawRow.js +11 -13
- package/dist/drawTable.d.ts +1 -2
- package/dist/drawTable.js +20 -40
- package/dist/generated/validators.d.ts +2 -2
- package/dist/generated/validators.js +282 -274
- package/dist/getBorderCharacters.d.ts +1 -2
- package/dist/getBorderCharacters.js +3 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -9
- package/dist/makeConfig.d.ts +1 -2
- package/dist/makeConfig.js +12 -19
- package/dist/makeStreamConfig.d.ts +1 -2
- package/dist/makeStreamConfig.js +8 -19
- package/dist/mapDataUsingRowHeights.d.ts +2 -0
- package/dist/mapDataUsingRowHeights.js +29 -0
- package/dist/padTableData.d.ts +1 -2
- package/dist/padTableData.js +6 -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 +1 -2
- package/dist/truncateTableData.js +6 -4
- package/dist/types/api.d.ts +2 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +93 -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 +1 -1
- 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/README.md
CHANGED
|
@@ -155,7 +155,7 @@ console.log(output);
|
|
|
155
155
|
|
|
156
156
|
`{string} config.columns[{number}].alignment` property controls content horizontal alignment within a cell.
|
|
157
157
|
|
|
158
|
-
Valid values are: "left", "right" and "
|
|
158
|
+
Valid values are: "left", "right", "center" and "justify".
|
|
159
159
|
|
|
160
160
|
```js
|
|
161
161
|
let config,
|
|
@@ -163,26 +163,21 @@ let config,
|
|
|
163
163
|
output;
|
|
164
164
|
|
|
165
165
|
data = [
|
|
166
|
-
['0A', '0B', '0C'],
|
|
167
|
-
['1A', '1B', '1C'],
|
|
168
|
-
['2A', '2B', '2C']
|
|
166
|
+
['0A', '0B', '0C', '0D 0E 0F'],
|
|
167
|
+
['1A', '1B', '1C', '1D 1E 1F'],
|
|
168
|
+
['2A', '2B', '2C', '2D 2E 2F'],
|
|
169
169
|
];
|
|
170
170
|
|
|
171
171
|
config = {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
},
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
2: {
|
|
182
|
-
alignment: 'right',
|
|
183
|
-
width: 10
|
|
184
|
-
}
|
|
185
|
-
}
|
|
172
|
+
columnDefault: {
|
|
173
|
+
width: 10,
|
|
174
|
+
},
|
|
175
|
+
columns: [
|
|
176
|
+
{alignment: 'left'},
|
|
177
|
+
{alignment: 'center'},
|
|
178
|
+
{alignment: 'right'},
|
|
179
|
+
{alignment: 'justify'},
|
|
180
|
+
],
|
|
186
181
|
};
|
|
187
182
|
|
|
188
183
|
output = table(data, config);
|
|
@@ -191,13 +186,13 @@ console.log(output);
|
|
|
191
186
|
```
|
|
192
187
|
|
|
193
188
|
```
|
|
194
|
-
|
|
195
|
-
║ 0A │ 0B │ 0C ║
|
|
196
|
-
|
|
197
|
-
║ 1A │ 1B │ 1C ║
|
|
198
|
-
|
|
199
|
-
║ 2A │ 2B │ 2C ║
|
|
200
|
-
|
|
189
|
+
╔════════════╤════════════╤════════════╤════════════╗
|
|
190
|
+
║ 0A │ 0B │ 0C │ 0D 0E 0F ║
|
|
191
|
+
╟────────────┼────────────┼────────────┼────────────╢
|
|
192
|
+
║ 1A │ 1B │ 1C │ 1D 1E 1F ║
|
|
193
|
+
╟────────────┼────────────┼────────────┼────────────╢
|
|
194
|
+
║ 2A │ 2B │ 2C │ 2D 2E 2F ║
|
|
195
|
+
╚════════════╧════════════╧════════════╧════════════╝
|
|
201
196
|
```
|
|
202
197
|
|
|
203
198
|
<a name="table-usage-column-width"></a>
|
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
|
};
|
|
@@ -21,14 +23,25 @@ const alignCenter = (subject, width) => {
|
|
|
21
23
|
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
|
|
22
24
|
}
|
|
23
25
|
};
|
|
26
|
+
const alignJustify = (subject, width) => {
|
|
27
|
+
const spaceSequenceCount = utils_1.countSpaceSequence(subject);
|
|
28
|
+
if (spaceSequenceCount === 0) {
|
|
29
|
+
return alignLeft(subject, width);
|
|
30
|
+
}
|
|
31
|
+
const addingSpaces = utils_1.distributeUnevenly(width, spaceSequenceCount);
|
|
32
|
+
if (Math.max(...addingSpaces) > 3) {
|
|
33
|
+
return alignLeft(subject, width);
|
|
34
|
+
}
|
|
35
|
+
let spaceSequenceIndex = 0;
|
|
36
|
+
return subject.replace(/\s+/g, (groupSpace) => {
|
|
37
|
+
return groupSpace + ' '.repeat(addingSpaces[spaceSequenceIndex++]);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
24
40
|
/**
|
|
25
41
|
* Pads a string to the left and/or right to position the subject
|
|
26
42
|
* text in a desired alignment within a container.
|
|
27
43
|
*/
|
|
28
|
-
|
|
29
|
-
if (typeof subject !== 'string') {
|
|
30
|
-
throw new TypeError('Subject parameter value must be a string.');
|
|
31
|
-
}
|
|
44
|
+
const alignString = (subject, containerWidth, alignment) => {
|
|
32
45
|
const subjectWidth = string_width_1.default(subject);
|
|
33
46
|
if (subjectWidth > containerWidth) {
|
|
34
47
|
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
|
@@ -43,5 +56,9 @@ exports.default = (subject, containerWidth, alignment) => {
|
|
|
43
56
|
if (alignment === 'right') {
|
|
44
57
|
return alignRight(subject, availableWidth);
|
|
45
58
|
}
|
|
59
|
+
if (alignment === 'justify') {
|
|
60
|
+
return alignJustify(subject, availableWidth);
|
|
61
|
+
}
|
|
46
62
|
return alignCenter(subject, availableWidth);
|
|
47
63
|
};
|
|
64
|
+
exports.alignString = alignString;
|
package/dist/alignTableData.d.ts
CHANGED
package/dist/alignTableData.js
CHANGED
|
@@ -3,18 +3,20 @@ 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.alignTableData = void 0;
|
|
6
7
|
const string_width_1 = __importDefault(require("string-width"));
|
|
7
|
-
const alignString_1 =
|
|
8
|
-
|
|
8
|
+
const alignString_1 = require("./alignString");
|
|
9
|
+
const alignTableData = (rows, config) => {
|
|
9
10
|
return rows.map((row) => {
|
|
10
|
-
return row.map((cell,
|
|
11
|
-
const column = config.columns[
|
|
11
|
+
return row.map((cell, cellIndex) => {
|
|
12
|
+
const column = config.columns[cellIndex];
|
|
12
13
|
if (string_width_1.default(cell) === column.width) {
|
|
13
14
|
return cell;
|
|
14
15
|
}
|
|
15
16
|
else {
|
|
16
|
-
return alignString_1.
|
|
17
|
+
return alignString_1.alignString(cell, column.width, column.alignment);
|
|
17
18
|
}
|
|
18
19
|
});
|
|
19
20
|
});
|
|
20
21
|
};
|
|
22
|
+
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
|
@@ -6,19 +6,19 @@ declare type Separator = {
|
|
|
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;
|
package/dist/drawBorder.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
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
3
|
exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = void 0;
|
|
7
|
-
const
|
|
8
|
-
const drawBorder = (
|
|
9
|
-
const
|
|
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
|
+
endSeparator: separator.right,
|
|
13
|
+
middleSeparator: separator.join,
|
|
14
|
+
startSeparator: separator.left,
|
|
15
|
+
}) + '\n';
|
|
13
16
|
};
|
|
14
17
|
exports.drawBorder = drawBorder;
|
|
15
|
-
const drawBorderTop = (
|
|
16
|
-
const result = drawBorder(
|
|
18
|
+
const drawBorderTop = (columnWidths, config) => {
|
|
19
|
+
const result = drawBorder(columnWidths, {
|
|
17
20
|
...config,
|
|
18
21
|
separator: {
|
|
19
22
|
body: config.border.topBody,
|
|
@@ -28,8 +31,8 @@ const drawBorderTop = (columnSizeIndex, config) => {
|
|
|
28
31
|
return result;
|
|
29
32
|
};
|
|
30
33
|
exports.drawBorderTop = drawBorderTop;
|
|
31
|
-
const drawBorderJoin = (
|
|
32
|
-
return drawBorder(
|
|
34
|
+
const drawBorderJoin = (columnWidths, config) => {
|
|
35
|
+
return drawBorder(columnWidths, {
|
|
33
36
|
...config,
|
|
34
37
|
separator: {
|
|
35
38
|
body: config.border.joinBody,
|
|
@@ -40,8 +43,8 @@ const drawBorderJoin = (columnSizeIndex, config) => {
|
|
|
40
43
|
});
|
|
41
44
|
};
|
|
42
45
|
exports.drawBorderJoin = drawBorderJoin;
|
|
43
|
-
const drawBorderBottom = (
|
|
44
|
-
return drawBorder(
|
|
46
|
+
const drawBorderBottom = (columnWidths, config) => {
|
|
47
|
+
return drawBorder(columnWidths, {
|
|
45
48
|
...config,
|
|
46
49
|
separator: {
|
|
47
50
|
body: config.border.bottomBody,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare type SeparatorConfig = {
|
|
2
|
+
drawSeparator: (index: number, size: number) => boolean;
|
|
3
|
+
startSeparator: string;
|
|
4
|
+
middleSeparator: string;
|
|
5
|
+
endSeparator: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Shared function to draw horizontal borders, rows or the entire table
|
|
9
|
+
*/
|
|
10
|
+
export declare const drawContent: (contents: string[], separatorConfig: SeparatorConfig) => string;
|
|
11
|
+
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 { startSeparator, middleSeparator, endSeparator, drawSeparator } = separatorConfig;
|
|
9
|
+
const contentSize = contents.length;
|
|
10
|
+
const result = [];
|
|
11
|
+
if (drawSeparator(0, contentSize)) {
|
|
12
|
+
result.push(startSeparator);
|
|
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(middleSeparator);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (drawSeparator(contentSize, contentSize)) {
|
|
22
|
+
result.push(endSeparator);
|
|
23
|
+
}
|
|
24
|
+
return result.join('');
|
|
25
|
+
};
|
|
26
|
+
exports.drawContent = drawContent;
|
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,14 @@
|
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
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
|
+
endSeparator: border.bodyRight,
|
|
10
|
+
middleSeparator: border.bodyJoin,
|
|
11
|
+
startSeparator: border.bodyLeft,
|
|
12
|
+
}) + '\n';
|
|
16
13
|
};
|
|
14
|
+
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;
|
package/dist/drawTable.js
CHANGED
|
@@ -1,48 +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 });
|
|
3
|
+
exports.drawTable = void 0;
|
|
6
4
|
const drawBorder_1 = require("./drawBorder");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
const groupBySizes = (array, sizes) => {
|
|
15
|
-
let startIndex = 0;
|
|
16
|
-
return sizes.map((rowHeight) => {
|
|
17
|
-
const chunk = array.slice(startIndex, startIndex + rowHeight);
|
|
18
|
-
startIndex += rowHeight;
|
|
19
|
-
return chunk;
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
const shouldDrawBorderJoin = (rowIndex, rowCount, config) => {
|
|
23
|
-
const { singleLine, drawHorizontalLine } = config;
|
|
24
|
-
return !singleLine && rowIndex + 1 < rowCount && drawHorizontalLine(rowIndex + 1, rowCount);
|
|
25
|
-
};
|
|
26
|
-
exports.default = (rows, columnWidths, rowHeights, config) => {
|
|
27
|
-
const { drawHorizontalLine, } = config;
|
|
28
|
-
const groupedRows = groupBySizes(rows, rowHeights).map((group) => {
|
|
5
|
+
const drawContent_1 = require("./drawContent");
|
|
6
|
+
const drawRow_1 = require("./drawRow");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const drawTable = (rows, columnWidths, rowHeights, config) => {
|
|
9
|
+
const { drawHorizontalLine, singleLine, } = config;
|
|
10
|
+
const contents = utils_1.groupBySizes(rows, rowHeights).map((group) => {
|
|
29
11
|
return group.map((row) => {
|
|
30
|
-
return drawRow_1.
|
|
12
|
+
return drawRow_1.drawRow(row, config);
|
|
31
13
|
}).join('');
|
|
32
14
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
15
|
+
return drawContent_1.drawContent(contents, {
|
|
16
|
+
drawSeparator: (index, size) => {
|
|
17
|
+
// Top/bottom border
|
|
18
|
+
if (index === 0 || index === size) {
|
|
19
|
+
return drawHorizontalLine(index, size);
|
|
20
|
+
}
|
|
21
|
+
return !singleLine && drawHorizontalLine(index, size);
|
|
22
|
+
},
|
|
23
|
+
endSeparator: drawBorder_1.drawBorderBottom(columnWidths, config),
|
|
24
|
+
middleSeparator: drawBorder_1.drawBorderJoin(columnWidths, config),
|
|
25
|
+
startSeparator: drawBorder_1.drawBorderTop(columnWidths, config),
|
|
43
26
|
});
|
|
44
|
-
if (drawHorizontalLine(rowCount, rowCount)) {
|
|
45
|
-
output += drawBorder_1.drawBorderBottom(columnWidths, config);
|
|
46
|
-
}
|
|
47
|
-
return output;
|
|
48
27
|
};
|
|
28
|
+
exports.drawTable = drawTable;
|
|
@@ -4,10 +4,10 @@ declare function validate43(data: any, { instancePath, parentData, parentDataPro
|
|
|
4
4
|
parentDataProperty: any;
|
|
5
5
|
rootData?: any;
|
|
6
6
|
}): boolean;
|
|
7
|
-
declare function
|
|
7
|
+
declare function validate73(data: any, { instancePath, parentData, parentDataProperty, rootData }?: {
|
|
8
8
|
instancePath?: string | undefined;
|
|
9
9
|
parentData: any;
|
|
10
10
|
parentDataProperty: any;
|
|
11
11
|
rootData?: any;
|
|
12
12
|
}): boolean;
|
|
13
|
-
export { validate43 as _config_json,
|
|
13
|
+
export { validate43 as _config_json, validate73 as _streamConfig_json };
|