table 6.4.0 → 6.7.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 +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 +28 -27
- package/dist/generated/validators.d.ts +2 -2
- package/dist/generated/validators.js +653 -303
- package/dist/getBorderCharacters.d.ts +1 -2
- package/dist/getBorderCharacters.js +7 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -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 +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 -9
- package/dist/wrapString.d.ts +1 -2
- package/dist/wrapString.js +3 -1
- package/dist/wrapWord.d.ts +1 -2
- package/dist/wrapWord.js +25 -12
- package/package.json +6 -6
- 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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.getBorderCharacters = void 0;
|
|
5
|
+
const getBorderCharacters = (name) => {
|
|
5
6
|
if (name === 'honeywell') {
|
|
6
7
|
return {
|
|
7
8
|
topBody: '═',
|
|
@@ -15,6 +16,7 @@ exports.default = (name) => {
|
|
|
15
16
|
bodyLeft: '║',
|
|
16
17
|
bodyRight: '║',
|
|
17
18
|
bodyJoin: '│',
|
|
19
|
+
headerJoin: '┬',
|
|
18
20
|
joinBody: '─',
|
|
19
21
|
joinLeft: '╟',
|
|
20
22
|
joinRight: '╢',
|
|
@@ -34,6 +36,7 @@ exports.default = (name) => {
|
|
|
34
36
|
bodyLeft: '│',
|
|
35
37
|
bodyRight: '│',
|
|
36
38
|
bodyJoin: '│',
|
|
39
|
+
headerJoin: '┬',
|
|
37
40
|
joinBody: '─',
|
|
38
41
|
joinLeft: '├',
|
|
39
42
|
joinRight: '┤',
|
|
@@ -53,6 +56,7 @@ exports.default = (name) => {
|
|
|
53
56
|
bodyLeft: '|',
|
|
54
57
|
bodyRight: '|',
|
|
55
58
|
bodyJoin: '|',
|
|
59
|
+
headerJoin: '+',
|
|
56
60
|
joinBody: '-',
|
|
57
61
|
joinLeft: '|',
|
|
58
62
|
joinRight: '|',
|
|
@@ -72,6 +76,7 @@ exports.default = (name) => {
|
|
|
72
76
|
bodyLeft: '',
|
|
73
77
|
bodyRight: '',
|
|
74
78
|
bodyJoin: '',
|
|
79
|
+
headerJoin: '',
|
|
75
80
|
joinBody: '',
|
|
76
81
|
joinLeft: '',
|
|
77
82
|
joinRight: '',
|
|
@@ -80,3 +85,4 @@ exports.default = (name) => {
|
|
|
80
85
|
}
|
|
81
86
|
throw new Error('Unknown border template "' + name + '".');
|
|
82
87
|
};
|
|
88
|
+
exports.getBorderCharacters = getBorderCharacters;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import createStream from './createStream';
|
|
2
|
-
import getBorderCharacters from './getBorderCharacters';
|
|
3
|
-
import table from './table';
|
|
1
|
+
import { createStream } from './createStream';
|
|
2
|
+
import { getBorderCharacters } from './getBorderCharacters';
|
|
3
|
+
import { table } from './table';
|
|
4
4
|
export { table, createStream, getBorderCharacters, };
|
|
5
5
|
export * from './types/api';
|
package/dist/index.js
CHANGED
|
@@ -9,15 +9,13 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
9
9
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
13
|
exports.getBorderCharacters = exports.createStream = exports.table = void 0;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
// import chalk from 'chalk';
|
|
15
|
+
const createStream_1 = require("./createStream");
|
|
16
|
+
Object.defineProperty(exports, "createStream", { enumerable: true, get: function () { return createStream_1.createStream; } });
|
|
17
|
+
const getBorderCharacters_1 = require("./getBorderCharacters");
|
|
18
|
+
Object.defineProperty(exports, "getBorderCharacters", { enumerable: true, get: function () { return getBorderCharacters_1.getBorderCharacters; } });
|
|
19
|
+
const table_1 = require("./table");
|
|
20
|
+
Object.defineProperty(exports, "table", { enumerable: true, get: function () { return table_1.table; } });
|
|
23
21
|
__exportStar(require("./types/api"), exports);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { StreamUserConfig } from './types/api';
|
|
2
2
|
import type { StreamConfig } from './types/internal';
|
|
3
|
-
declare const _default: (userConfig: StreamUserConfig) => StreamConfig;
|
|
4
3
|
/**
|
|
5
4
|
* Makes a new configuration object out of the userConfig object
|
|
6
5
|
* using default values for the missing configuration properties.
|
|
7
6
|
*/
|
|
8
|
-
export
|
|
7
|
+
export declare const makeStreamConfig: (userConfig: StreamUserConfig) => StreamConfig;
|
package/dist/makeStreamConfig.js
CHANGED
|
@@ -3,30 +3,22 @@ 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.makeStreamConfig = void 0;
|
|
6
7
|
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
7
|
-
const
|
|
8
|
-
const validateConfig_1 =
|
|
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
|
-
};
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const validateConfig_1 = require("./validateConfig");
|
|
19
10
|
/**
|
|
20
11
|
* Creates a configuration for every column using default
|
|
21
12
|
* values for the missing configuration properties.
|
|
22
13
|
*/
|
|
23
|
-
const
|
|
14
|
+
const makeColumnsConfig = (columnCount, columns = {}, columnDefault) => {
|
|
24
15
|
return Array.from({ length: columnCount }).map((_, index) => {
|
|
25
16
|
return {
|
|
26
17
|
alignment: 'left',
|
|
27
18
|
paddingLeft: 1,
|
|
28
19
|
paddingRight: 1,
|
|
29
20
|
truncate: Number.POSITIVE_INFINITY,
|
|
21
|
+
verticalAlignment: 'top',
|
|
30
22
|
wrapWord: false,
|
|
31
23
|
...columnDefault,
|
|
32
24
|
...columns[index],
|
|
@@ -37,23 +29,19 @@ const makeColumns = (columnCount, columns = {}, columnDefault) => {
|
|
|
37
29
|
* Makes a new configuration object out of the userConfig object
|
|
38
30
|
* using default values for the missing configuration properties.
|
|
39
31
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
validateConfig_1.default('streamConfig.json', userConfig);
|
|
32
|
+
const makeStreamConfig = (userConfig) => {
|
|
33
|
+
validateConfig_1.validateConfig('streamConfig.json', userConfig);
|
|
43
34
|
const config = lodash_clonedeep_1.default(userConfig);
|
|
44
|
-
if (
|
|
35
|
+
if (config.columnDefault.width === undefined) {
|
|
45
36
|
throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
|
46
37
|
}
|
|
47
|
-
if (!config.columnCount) {
|
|
48
|
-
throw new Error('Must provide config.columnCount.');
|
|
49
|
-
}
|
|
50
38
|
return {
|
|
51
|
-
|
|
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 : (() => {
|
|
39
|
+
drawVerticalLine: () => {
|
|
56
40
|
return true;
|
|
57
|
-
}
|
|
41
|
+
},
|
|
42
|
+
...config,
|
|
43
|
+
border: utils_1.makeBorderConfig(config.border),
|
|
44
|
+
columns: makeColumnsConfig(config.columnCount, config.columns, config.columnDefault),
|
|
58
45
|
};
|
|
59
46
|
};
|
|
47
|
+
exports.makeStreamConfig = makeStreamConfig;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { TableUserConfig } from './types/api';
|
|
2
2
|
import type { Row, TableConfig } from './types/internal';
|
|
3
|
-
declare const _default: (rows: Row[], userConfig?: TableUserConfig) => TableConfig;
|
|
4
3
|
/**
|
|
5
4
|
* Makes a new configuration object out of the userConfig object
|
|
6
5
|
* using default values for the missing configuration properties.
|
|
7
6
|
*/
|
|
8
|
-
export
|
|
7
|
+
export declare const makeTableConfig: (rows: Row[], userConfig?: TableUserConfig) => TableConfig;
|
|
@@ -3,56 +3,64 @@ 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.makeTableConfig = void 0;
|
|
6
7
|
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const validateConfig_1 =
|
|
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
|
-
};
|
|
8
|
+
const calculateColumnWidths_1 = __importDefault(require("./calculateColumnWidths"));
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const validateConfig_1 = require("./validateConfig");
|
|
19
11
|
/**
|
|
20
12
|
* Creates a configuration for every column using default
|
|
21
13
|
* values for the missing configuration properties.
|
|
22
14
|
*/
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
return rows[0].map((
|
|
15
|
+
const makeColumnsConfig = (rows, columns, columnDefault) => {
|
|
16
|
+
const columnWidths = calculateColumnWidths_1.default(rows);
|
|
17
|
+
return rows[0].map((_, columnIndex) => {
|
|
26
18
|
return {
|
|
27
19
|
alignment: 'left',
|
|
28
20
|
paddingLeft: 1,
|
|
29
21
|
paddingRight: 1,
|
|
30
22
|
truncate: Number.POSITIVE_INFINITY,
|
|
31
|
-
|
|
23
|
+
verticalAlignment: 'top',
|
|
24
|
+
width: columnWidths[columnIndex],
|
|
32
25
|
wrapWord: false,
|
|
33
26
|
...columnDefault,
|
|
34
|
-
...columns === null || columns === void 0 ? void 0 : columns[
|
|
27
|
+
...columns === null || columns === void 0 ? void 0 : columns[columnIndex],
|
|
35
28
|
};
|
|
36
29
|
});
|
|
37
30
|
};
|
|
31
|
+
const makeHeaderConfig = (config) => {
|
|
32
|
+
if (!config.header) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
alignment: 'center',
|
|
37
|
+
paddingLeft: 1,
|
|
38
|
+
paddingRight: 1,
|
|
39
|
+
truncate: Number.POSITIVE_INFINITY,
|
|
40
|
+
wrapWord: false,
|
|
41
|
+
...config.header,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
38
44
|
/**
|
|
39
45
|
* Makes a new configuration object out of the userConfig object
|
|
40
46
|
* using default values for the missing configuration properties.
|
|
41
47
|
*/
|
|
42
|
-
|
|
48
|
+
const makeTableConfig = (rows, userConfig = {}) => {
|
|
43
49
|
var _a, _b, _c;
|
|
44
|
-
validateConfig_1.
|
|
50
|
+
validateConfig_1.validateConfig('config.json', userConfig);
|
|
45
51
|
const config = lodash_clonedeep_1.default(userConfig);
|
|
46
52
|
return {
|
|
47
53
|
...config,
|
|
48
|
-
border:
|
|
49
|
-
columns:
|
|
54
|
+
border: utils_1.makeBorderConfig(config.border),
|
|
55
|
+
columns: makeColumnsConfig(rows, config.columns, config.columnDefault),
|
|
50
56
|
drawHorizontalLine: (_a = config.drawHorizontalLine) !== null && _a !== void 0 ? _a : (() => {
|
|
51
57
|
return true;
|
|
52
58
|
}),
|
|
53
59
|
drawVerticalLine: (_b = config.drawVerticalLine) !== null && _b !== void 0 ? _b : (() => {
|
|
54
60
|
return true;
|
|
55
61
|
}),
|
|
62
|
+
header: makeHeaderConfig(config),
|
|
56
63
|
singleLine: (_c = config.singleLine) !== null && _c !== void 0 ? _c : false,
|
|
57
64
|
};
|
|
58
65
|
};
|
|
66
|
+
exports.makeTableConfig = makeTableConfig;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapDataUsingRowHeights = void 0;
|
|
4
|
+
const wrapCell_1 = require("./wrapCell");
|
|
5
|
+
const createEmptyStrings = (length) => {
|
|
6
|
+
return new Array(length).fill('');
|
|
7
|
+
};
|
|
8
|
+
const padCellVertically = (lines, rowHeight, columnConfig) => {
|
|
9
|
+
const { verticalAlignment } = columnConfig;
|
|
10
|
+
const availableLines = rowHeight - lines.length;
|
|
11
|
+
if (verticalAlignment === 'top') {
|
|
12
|
+
return [...lines, ...createEmptyStrings(availableLines)];
|
|
13
|
+
}
|
|
14
|
+
if (verticalAlignment === 'bottom') {
|
|
15
|
+
return [...createEmptyStrings(availableLines), ...lines];
|
|
16
|
+
}
|
|
17
|
+
return [
|
|
18
|
+
...createEmptyStrings(Math.floor(availableLines / 2)),
|
|
19
|
+
...lines,
|
|
20
|
+
...createEmptyStrings(Math.ceil(availableLines / 2)),
|
|
21
|
+
];
|
|
22
|
+
};
|
|
23
|
+
const flatten = (array) => {
|
|
24
|
+
return [].concat(...array);
|
|
25
|
+
};
|
|
26
|
+
const mapDataUsingRowHeights = (unmappedRows, rowHeights, config) => {
|
|
27
|
+
const tableWidth = unmappedRows[0].length;
|
|
28
|
+
const mappedRows = unmappedRows.map((unmappedRow, unmappedRowIndex) => {
|
|
29
|
+
const outputRowHeight = rowHeights[unmappedRowIndex];
|
|
30
|
+
const outputRow = Array.from({ length: outputRowHeight }, () => {
|
|
31
|
+
return new Array(tableWidth).fill('');
|
|
32
|
+
});
|
|
33
|
+
unmappedRow.forEach((cell, cellIndex) => {
|
|
34
|
+
const cellLines = wrapCell_1.wrapCell(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
|
|
35
|
+
const paddedCellLines = padCellVertically(cellLines, outputRowHeight, config.columns[cellIndex]);
|
|
36
|
+
paddedCellLines.forEach((cellLine, cellLineIndex) => {
|
|
37
|
+
outputRow[cellLineIndex][cellIndex] = cellLine;
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
return outputRow;
|
|
41
|
+
});
|
|
42
|
+
return flatten(mappedRows);
|
|
43
|
+
};
|
|
44
|
+
exports.mapDataUsingRowHeights = mapDataUsingRowHeights;
|
package/dist/padTableData.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { BaseConfig, Row } from './types/internal';
|
|
2
|
-
declare const
|
|
3
|
-
export
|
|
2
|
+
export declare const padString: (input: string, paddingLeft: number, paddingRight: number) => string;
|
|
3
|
+
export declare const padTableData: (rows: Row[], config: BaseConfig) => Row[];
|
package/dist/padTableData.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.padTableData = exports.padString = void 0;
|
|
4
|
+
const padString = (input, paddingLeft, paddingRight) => {
|
|
5
|
+
return ' '.repeat(paddingLeft) + input + ' '.repeat(paddingRight);
|
|
6
|
+
};
|
|
7
|
+
exports.padString = padString;
|
|
8
|
+
const padTableData = (rows, config) => {
|
|
4
9
|
return rows.map((cells) => {
|
|
5
|
-
return cells.map((
|
|
6
|
-
const
|
|
7
|
-
return
|
|
10
|
+
return cells.map((cell, cellIndex) => {
|
|
11
|
+
const { paddingLeft, paddingRight } = config.columns[cellIndex];
|
|
12
|
+
return exports.padString(cell, paddingLeft, paddingRight);
|
|
8
13
|
});
|
|
9
14
|
});
|
|
10
15
|
};
|
|
16
|
+
exports.padTableData = padTableData;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.stringifyTableData = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const stringifyTableData = (rows) => {
|
|
4
6
|
return rows.map((cells) => {
|
|
5
|
-
return cells.map(
|
|
7
|
+
return cells.map((cell) => {
|
|
8
|
+
return utils_1.normalizeString(String(cell));
|
|
9
|
+
});
|
|
6
10
|
});
|
|
7
11
|
};
|
|
12
|
+
exports.stringifyTableData = stringifyTableData;
|
package/dist/table.d.ts
CHANGED
package/dist/table.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
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
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
rows =
|
|
24
|
-
rows =
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
exports.table = void 0;
|
|
4
|
+
const alignTableData_1 = require("./alignTableData");
|
|
5
|
+
const calculateCellWidths_1 = require("./calculateCellWidths");
|
|
6
|
+
const calculateRowHeights_1 = require("./calculateRowHeights");
|
|
7
|
+
const drawTable_1 = require("./drawTable");
|
|
8
|
+
const makeTableConfig_1 = require("./makeTableConfig");
|
|
9
|
+
const mapDataUsingRowHeights_1 = require("./mapDataUsingRowHeights");
|
|
10
|
+
const padTableData_1 = require("./padTableData");
|
|
11
|
+
const stringifyTableData_1 = require("./stringifyTableData");
|
|
12
|
+
const truncateTableData_1 = require("./truncateTableData");
|
|
13
|
+
const validateTableData_1 = require("./validateTableData");
|
|
14
|
+
const table = (data, userConfig = {}) => {
|
|
15
|
+
validateTableData_1.validateTableData(data);
|
|
16
|
+
let rows = stringifyTableData_1.stringifyTableData(data);
|
|
17
|
+
const config = makeTableConfig_1.makeTableConfig(rows, userConfig);
|
|
18
|
+
rows = truncateTableData_1.truncateTableData(rows, config);
|
|
19
|
+
const rowHeights = calculateRowHeights_1.calculateRowHeights(rows, config);
|
|
20
|
+
rows = mapDataUsingRowHeights_1.mapDataUsingRowHeights(rows, rowHeights, config);
|
|
21
|
+
rows = alignTableData_1.alignTableData(rows, config);
|
|
22
|
+
rows = padTableData_1.padTableData(rows, config);
|
|
23
|
+
const cellWidths = calculateCellWidths_1.calculateCellWidths(rows[0]);
|
|
24
|
+
return drawTable_1.drawTable(rows, cellWidths, rowHeights, config);
|
|
27
25
|
};
|
|
26
|
+
exports.table = table;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BaseConfig, Row } from './types/internal';
|
|
2
|
-
declare const
|
|
2
|
+
export declare const truncateString: (input: string, length: number) => string;
|
|
3
3
|
/**
|
|
4
4
|
* @todo Make it work with ASCII content.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export declare const truncateTableData: (rows: Row[], config: BaseConfig) => Row[];
|
|
@@ -3,17 +3,21 @@ 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.truncateTableData = exports.truncateString = void 0;
|
|
6
7
|
const lodash_truncate_1 = __importDefault(require("lodash.truncate"));
|
|
8
|
+
const truncateString = (input, length) => {
|
|
9
|
+
return lodash_truncate_1.default(input, { length,
|
|
10
|
+
omission: '…' });
|
|
11
|
+
};
|
|
12
|
+
exports.truncateString = truncateString;
|
|
7
13
|
/**
|
|
8
14
|
* @todo Make it work with ASCII content.
|
|
9
15
|
*/
|
|
10
|
-
|
|
16
|
+
const truncateTableData = (rows, config) => {
|
|
11
17
|
return rows.map((cells) => {
|
|
12
|
-
return cells.map((
|
|
13
|
-
return
|
|
14
|
-
length: config.columns[index].truncate,
|
|
15
|
-
omission: '…',
|
|
16
|
-
});
|
|
18
|
+
return cells.map((cell, cellIndex) => {
|
|
19
|
+
return exports.truncateString(cell, config.columns[cellIndex].truncate);
|
|
17
20
|
});
|
|
18
21
|
});
|
|
19
22
|
};
|
|
23
|
+
exports.truncateTableData = truncateTableData;
|
package/dist/types/api.d.ts
CHANGED
|
@@ -10,20 +10,27 @@ export declare type BorderUserConfig = {
|
|
|
10
10
|
readonly bottomRight?: string;
|
|
11
11
|
readonly bottomBody?: string;
|
|
12
12
|
readonly bottomJoin?: string;
|
|
13
|
-
readonly bodyRight?: string;
|
|
14
|
-
readonly bodyLeft?: string;
|
|
15
|
-
readonly bodyJoin?: string;
|
|
16
13
|
readonly joinLeft?: string;
|
|
17
14
|
readonly joinRight?: string;
|
|
18
15
|
readonly joinBody?: string;
|
|
19
16
|
readonly joinJoin?: string;
|
|
17
|
+
readonly headerJoin?: string;
|
|
18
|
+
readonly bodyRight?: string;
|
|
19
|
+
readonly bodyLeft?: string;
|
|
20
|
+
readonly bodyJoin?: string;
|
|
20
21
|
};
|
|
21
22
|
export declare type BorderConfig = Required<BorderUserConfig>;
|
|
23
|
+
export declare type Alignment = 'center' | 'justify' | 'left' | 'right';
|
|
24
|
+
export declare type VerticalAlignment = 'bottom' | 'middle' | 'top';
|
|
22
25
|
export declare type ColumnUserConfig = {
|
|
23
26
|
/**
|
|
24
27
|
* Cell content horizontal alignment (default: left)
|
|
25
28
|
*/
|
|
26
|
-
readonly alignment?:
|
|
29
|
+
readonly alignment?: Alignment;
|
|
30
|
+
/**
|
|
31
|
+
* Cell content vertical alignment (default: top)
|
|
32
|
+
*/
|
|
33
|
+
readonly verticalAlignment?: VerticalAlignment;
|
|
27
34
|
/**
|
|
28
35
|
* Column width (default: auto calculation based on the cell content)
|
|
29
36
|
*/
|
|
@@ -45,6 +52,9 @@ export declare type ColumnUserConfig = {
|
|
|
45
52
|
*/
|
|
46
53
|
readonly wrapWord?: boolean;
|
|
47
54
|
};
|
|
55
|
+
export declare type HeaderUserConfig = Omit<ColumnUserConfig, 'verticalAlignment' | 'width'> & {
|
|
56
|
+
readonly content: string;
|
|
57
|
+
};
|
|
48
58
|
export declare type BaseUserConfig = {
|
|
49
59
|
/**
|
|
50
60
|
* Custom border
|
|
@@ -66,6 +76,10 @@ export declare type BaseUserConfig = {
|
|
|
66
76
|
readonly drawVerticalLine?: DrawVerticalLine;
|
|
67
77
|
};
|
|
68
78
|
export declare type TableUserConfig = BaseUserConfig & {
|
|
79
|
+
/**
|
|
80
|
+
* The header configuration
|
|
81
|
+
*/
|
|
82
|
+
readonly header?: HeaderUserConfig;
|
|
69
83
|
/**
|
|
70
84
|
* Used to tell whether to draw a horizontal line.
|
|
71
85
|
* This callback is called for each non-content line of the table.
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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.distributeUnevenly = exports.countSpaceSequence = exports.groupBySizes = exports.makeBorderConfig = exports.splitAnsi = exports.normalizeString = void 0;
|
|
7
|
+
const slice_ansi_1 = __importDefault(require("slice-ansi"));
|
|
8
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
9
|
+
const getBorderCharacters_1 = require("./getBorderCharacters");
|
|
10
|
+
/**
|
|
11
|
+
* Converts Windows-style newline to Unix-style
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
const normalizeString = (input) => {
|
|
16
|
+
return input.replace(/\r\n/g, '\n');
|
|
17
|
+
};
|
|
18
|
+
exports.normalizeString = normalizeString;
|
|
19
|
+
/**
|
|
20
|
+
* Splits ansi string by newlines
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
const splitAnsi = (input) => {
|
|
25
|
+
const lengths = strip_ansi_1.default(input).split('\n').map(({ length }) => {
|
|
26
|
+
return length;
|
|
27
|
+
});
|
|
28
|
+
const result = [];
|
|
29
|
+
let startIndex = 0;
|
|
30
|
+
lengths.forEach((length) => {
|
|
31
|
+
result.push(length === 0 ? '' : slice_ansi_1.default(input, startIndex, startIndex + length));
|
|
32
|
+
// Plus 1 for the newline character itself
|
|
33
|
+
startIndex += length + 1;
|
|
34
|
+
});
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
exports.splitAnsi = splitAnsi;
|
|
38
|
+
/**
|
|
39
|
+
* Merges user provided border characters with the default border ("honeywell") characters.
|
|
40
|
+
*
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
const makeBorderConfig = (border) => {
|
|
44
|
+
return {
|
|
45
|
+
...getBorderCharacters_1.getBorderCharacters('honeywell'),
|
|
46
|
+
...border,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
exports.makeBorderConfig = makeBorderConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Groups the array into sub-arrays by sizes.
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
* @example
|
|
55
|
+
* groupBySizes(['a', 'b', 'c', 'd', 'e'], [2, 1, 2]) = [ ['a', 'b'], ['c'], ['d', 'e'] ]
|
|
56
|
+
*/
|
|
57
|
+
const groupBySizes = (array, sizes) => {
|
|
58
|
+
let startIndex = 0;
|
|
59
|
+
return sizes.map((size) => {
|
|
60
|
+
const group = array.slice(startIndex, startIndex + size);
|
|
61
|
+
startIndex += size;
|
|
62
|
+
return group;
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
exports.groupBySizes = groupBySizes;
|
|
66
|
+
/**
|
|
67
|
+
* Counts the number of continuous spaces in a string
|
|
68
|
+
*
|
|
69
|
+
* @internal
|
|
70
|
+
* @example
|
|
71
|
+
* countGroupSpaces('a bc de f') = 3
|
|
72
|
+
*/
|
|
73
|
+
const countSpaceSequence = (input) => {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
return (_b = (_a = input.match(/\s+/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
76
|
+
};
|
|
77
|
+
exports.countSpaceSequence = countSpaceSequence;
|
|
78
|
+
/**
|
|
79
|
+
* Creates the non-increasing number array given sum and length
|
|
80
|
+
* whose the difference between maximum and minimum is not greater than 1
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
83
|
+
* @example
|
|
84
|
+
* distributeUnevenly(6, 3) = [2, 2, 2]
|
|
85
|
+
* distributeUnevenly(8, 3) = [3, 3, 2]
|
|
86
|
+
*/
|
|
87
|
+
const distributeUnevenly = (sum, length) => {
|
|
88
|
+
const result = Array.from({ length }).fill(Math.floor(sum / length));
|
|
89
|
+
return result.map((element, index) => {
|
|
90
|
+
return element + (index < sum % length ? 1 : 0);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
exports.distributeUnevenly = distributeUnevenly;
|
package/dist/validateConfig.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import type { TableUserConfig } from './types/api';
|
|
2
|
-
declare const
|
|
3
|
-
export default _default;
|
|
2
|
+
export declare const validateConfig: (schemaId: 'config.json' | 'streamConfig.json', config: TableUserConfig) => void;
|
package/dist/validateConfig.js
CHANGED
|
@@ -3,8 +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.validateConfig = void 0;
|
|
6
7
|
const validators_1 = __importDefault(require("./generated/validators"));
|
|
7
|
-
|
|
8
|
+
const validateConfig = (schemaId, config) => {
|
|
8
9
|
const validate = validators_1.default[schemaId];
|
|
9
10
|
if (!validate(config) && validate.errors) {
|
|
10
11
|
const errors = validate.errors.map((error) => {
|
|
@@ -21,3 +22,4 @@ exports.default = (schemaId, config) => {
|
|
|
21
22
|
throw new Error('Invalid config.');
|
|
22
23
|
}
|
|
23
24
|
};
|
|
25
|
+
exports.validateConfig = validateConfig;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default _default;
|
|
1
|
+
export declare const validateTableData: (rows: unknown[][]) => void;
|