table 6.3.4 → 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 -7
- 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 -12
- 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 +22 -31
- package/dist/generated/validators.d.ts +2 -2
- package/dist/generated/validators.js +464 -163
- 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 -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 +3 -2
- 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 -24
- 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: '═',
|
|
@@ -80,3 +81,4 @@ exports.default = (name) => {
|
|
|
80
81
|
}
|
|
81
82
|
throw new Error('Unknown border template "' + name + '".');
|
|
82
83
|
};
|
|
84
|
+
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,12 @@ 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
|
-
const createStream_1 =
|
|
18
|
-
exports
|
|
19
|
-
const getBorderCharacters_1 =
|
|
20
|
-
exports
|
|
21
|
-
const table_1 =
|
|
22
|
-
exports
|
|
14
|
+
const createStream_1 = require("./createStream");
|
|
15
|
+
Object.defineProperty(exports, "createStream", { enumerable: true, get: function () { return createStream_1.createStream; } });
|
|
16
|
+
const getBorderCharacters_1 = require("./getBorderCharacters");
|
|
17
|
+
Object.defineProperty(exports, "getBorderCharacters", { enumerable: true, get: function () { return getBorderCharacters_1.getBorderCharacters; } });
|
|
18
|
+
const table_1 = require("./table");
|
|
19
|
+
Object.defineProperty(exports, "table", { enumerable: true, get: function () { return table_1.table; } });
|
|
23
20
|
__exportStar(require("./types/api"), exports);
|
package/dist/makeConfig.d.ts
CHANGED
|
@@ -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 makeConfig: (rows: Row[], userConfig?: TableUserConfig) => TableConfig;
|
package/dist/makeConfig.js
CHANGED
|
@@ -3,35 +3,27 @@ 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.makeConfig = 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
15
|
const makeColumns = (rows, columns, columnDefault) => {
|
|
24
|
-
const
|
|
25
|
-
return rows[0].map((
|
|
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
|
-
width:
|
|
23
|
+
width: columnWidths[columnIndex],
|
|
32
24
|
wrapWord: false,
|
|
33
25
|
...columnDefault,
|
|
34
|
-
...columns === null || columns === void 0 ? void 0 : columns[
|
|
26
|
+
...columns === null || columns === void 0 ? void 0 : columns[columnIndex],
|
|
35
27
|
};
|
|
36
28
|
});
|
|
37
29
|
};
|
|
@@ -39,13 +31,13 @@ const makeColumns = (rows, columns, columnDefault) => {
|
|
|
39
31
|
* Makes a new configuration object out of the userConfig object
|
|
40
32
|
* using default values for the missing configuration properties.
|
|
41
33
|
*/
|
|
42
|
-
|
|
34
|
+
const makeConfig = (rows, userConfig = {}) => {
|
|
43
35
|
var _a, _b, _c;
|
|
44
|
-
validateConfig_1.
|
|
36
|
+
validateConfig_1.validateConfig('config.json', userConfig);
|
|
45
37
|
const config = lodash_clonedeep_1.default(userConfig);
|
|
46
38
|
return {
|
|
47
39
|
...config,
|
|
48
|
-
border: makeBorder(config.border),
|
|
40
|
+
border: utils_1.makeBorder(config.border),
|
|
49
41
|
columns: makeColumns(rows, config.columns, config.columnDefault),
|
|
50
42
|
drawHorizontalLine: (_a = config.drawHorizontalLine) !== null && _a !== void 0 ? _a : (() => {
|
|
51
43
|
return true;
|
|
@@ -56,3 +48,4 @@ exports.default = (rows, userConfig = {}) => {
|
|
|
56
48
|
singleLine: (_c = config.singleLine) !== null && _c !== void 0 ? _c : false,
|
|
57
49
|
};
|
|
58
50
|
};
|
|
51
|
+
exports.makeConfig = makeConfig;
|
|
@@ -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,19 +3,10 @@ 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.
|
|
@@ -37,19 +28,16 @@ const makeColumns = (columnCount, columns = {}, columnDefault) => {
|
|
|
37
28
|
* Makes a new configuration object out of the userConfig object
|
|
38
29
|
* using default values for the missing configuration properties.
|
|
39
30
|
*/
|
|
40
|
-
|
|
31
|
+
const makeStreamConfig = (userConfig) => {
|
|
41
32
|
var _a;
|
|
42
|
-
validateConfig_1.
|
|
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
39
|
...config,
|
|
52
|
-
border: makeBorder(config.border),
|
|
40
|
+
border: utils_1.makeBorder(config.border),
|
|
53
41
|
columnCount: config.columnCount,
|
|
54
42
|
columns: makeColumns(config.columnCount, config.columns, config.columnDefault),
|
|
55
43
|
drawVerticalLine: (_a = config.drawVerticalLine) !== null && _a !== void 0 ? _a : (() => {
|
|
@@ -57,3 +45,4 @@ exports.default = (userConfig) => {
|
|
|
57
45
|
}),
|
|
58
46
|
};
|
|
59
47
|
};
|
|
48
|
+
exports.makeStreamConfig = makeStreamConfig;
|
|
@@ -0,0 +1,29 @@
|
|
|
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.mapDataUsingRowHeights = void 0;
|
|
7
|
+
const lodash_flatten_1 = __importDefault(require("lodash.flatten"));
|
|
8
|
+
const wrapCell_1 = require("./wrapCell");
|
|
9
|
+
const mapDataUsingRowHeights = (unmappedRows, rowHeights, config) => {
|
|
10
|
+
const tableWidth = unmappedRows[0].length;
|
|
11
|
+
const mappedRows = unmappedRows.map((unmappedRow, unmappedRowIndex) => {
|
|
12
|
+
const outputRowHeight = rowHeights[unmappedRowIndex];
|
|
13
|
+
const outputRow = Array.from({ length: outputRowHeight }, () => {
|
|
14
|
+
return new Array(tableWidth).fill('');
|
|
15
|
+
});
|
|
16
|
+
// rowHeight
|
|
17
|
+
// [{row index within rowSaw; index2}]
|
|
18
|
+
// [{cell index within a virtual row; index1}]
|
|
19
|
+
unmappedRow.forEach((cell, cellIndex) => {
|
|
20
|
+
const cellLines = wrapCell_1.wrapCell(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
|
|
21
|
+
cellLines.forEach((cellLine, cellLineIndex) => {
|
|
22
|
+
outputRow[cellLineIndex][cellIndex] = cellLine;
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
return outputRow;
|
|
26
|
+
});
|
|
27
|
+
return lodash_flatten_1.default(mappedRows);
|
|
28
|
+
};
|
|
29
|
+
exports.mapDataUsingRowHeights = mapDataUsingRowHeights;
|
package/dist/padTableData.d.ts
CHANGED
package/dist/padTableData.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.padTableData = void 0;
|
|
4
|
+
const padTableData = (rows, config) => {
|
|
4
5
|
return rows.map((cells) => {
|
|
5
|
-
return cells.map((
|
|
6
|
-
const column = config.columns[
|
|
7
|
-
return ' '.repeat(column.paddingLeft) +
|
|
6
|
+
return cells.map((cell, cellIndex) => {
|
|
7
|
+
const column = config.columns[cellIndex];
|
|
8
|
+
return ' '.repeat(column.paddingLeft) + cell + ' '.repeat(column.paddingRight);
|
|
8
9
|
});
|
|
9
10
|
});
|
|
10
11
|
};
|
|
12
|
+
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 makeConfig_1 = require("./makeConfig");
|
|
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 = makeConfig_1.makeConfig(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,5 @@
|
|
|
1
1
|
import type { BaseConfig, Row } from './types/internal';
|
|
2
|
-
declare const _default: (rows: Row[], config: BaseConfig) => Row[];
|
|
3
2
|
/**
|
|
4
3
|
* @todo Make it work with ASCII content.
|
|
5
4
|
*/
|
|
6
|
-
export
|
|
5
|
+
export declare const truncateTableData: (rows: Row[], config: BaseConfig) => Row[];
|
|
@@ -3,17 +3,19 @@ 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 = void 0;
|
|
6
7
|
const lodash_truncate_1 = __importDefault(require("lodash.truncate"));
|
|
7
8
|
/**
|
|
8
9
|
* @todo Make it work with ASCII content.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
const truncateTableData = (rows, config) => {
|
|
11
12
|
return rows.map((cells) => {
|
|
12
|
-
return cells.map((
|
|
13
|
-
return lodash_truncate_1.default(
|
|
14
|
-
length: config.columns[
|
|
13
|
+
return cells.map((cell, cellIndex) => {
|
|
14
|
+
return lodash_truncate_1.default(cell, {
|
|
15
|
+
length: config.columns[cellIndex].truncate,
|
|
15
16
|
omission: '…',
|
|
16
17
|
});
|
|
17
18
|
});
|
|
18
19
|
});
|
|
19
20
|
};
|
|
21
|
+
exports.truncateTableData = truncateTableData;
|
package/dist/types/api.d.ts
CHANGED
|
@@ -19,11 +19,12 @@ export declare type BorderUserConfig = {
|
|
|
19
19
|
readonly joinJoin?: string;
|
|
20
20
|
};
|
|
21
21
|
export declare type BorderConfig = Required<BorderUserConfig>;
|
|
22
|
+
export declare type Alignment = 'center' | 'justify' | 'left' | 'right';
|
|
22
23
|
export declare type ColumnUserConfig = {
|
|
23
24
|
/**
|
|
24
25
|
* Cell content horizontal alignment (default: left)
|
|
25
26
|
*/
|
|
26
|
-
readonly alignment?:
|
|
27
|
+
readonly alignment?: Alignment;
|
|
27
28
|
/**
|
|
28
29
|
* Column width (default: auto calculation based on the cell content)
|
|
29
30
|
*/
|
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.makeBorder = 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 makeBorder = (border) => {
|
|
44
|
+
return {
|
|
45
|
+
...getBorderCharacters_1.getBorderCharacters('honeywell'),
|
|
46
|
+
...border,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
exports.makeBorder = makeBorder;
|
|
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;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateTableData = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const validateTableData = (rows) => {
|
|
4
6
|
if (!Array.isArray(rows)) {
|
|
5
7
|
throw new TypeError('Table data must be an array.');
|
|
6
8
|
}
|
|
@@ -20,9 +22,10 @@ exports.default = (rows) => {
|
|
|
20
22
|
}
|
|
21
23
|
for (const cell of row) {
|
|
22
24
|
// eslint-disable-next-line no-control-regex
|
|
23
|
-
if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) {
|
|
25
|
+
if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(utils_1.normalizeString(String(cell)))) {
|
|
24
26
|
throw new Error('Table data must not contain control characters.');
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
};
|
|
31
|
+
exports.validateTableData = validateTableData;
|
package/dist/wrapCell.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
declare const _default: (cellValue: string, columnWidth: number, useWrapWord: boolean) => string[];
|
|
2
1
|
/**
|
|
3
2
|
* Wrap a single cell value into a list of lines
|
|
4
3
|
*
|
|
@@ -6,4 +5,4 @@ declare const _default: (cellValue: string, columnWidth: number, useWrapWord: bo
|
|
|
6
5
|
* depending on user configuration.
|
|
7
6
|
*
|
|
8
7
|
*/
|
|
9
|
-
export
|
|
8
|
+
export declare const wrapCell: (cellValue: string, cellWidth: number, useWrapWord: boolean) => string[];
|
package/dist/wrapCell.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
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.wrapCell = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const wrapString_1 = require("./wrapString");
|
|
6
|
+
const wrapWord_1 = require("./wrapWord");
|
|
8
7
|
/**
|
|
9
8
|
* Wrap a single cell value into a list of lines
|
|
10
9
|
*
|
|
@@ -12,17 +11,17 @@ const wrapWord_1 = __importDefault(require("./wrapWord"));
|
|
|
12
11
|
* depending on user configuration.
|
|
13
12
|
*
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
const wrapCell = (cellValue, cellWidth, useWrapWord) => {
|
|
16
15
|
// First split on literal newlines
|
|
17
|
-
const cellLines =
|
|
16
|
+
const cellLines = utils_1.splitAnsi(cellValue);
|
|
18
17
|
// Then iterate over the list and word-wrap every remaining line if necessary.
|
|
19
18
|
for (let lineNr = 0; lineNr < cellLines.length;) {
|
|
20
19
|
let lineChunks;
|
|
21
20
|
if (useWrapWord) {
|
|
22
|
-
lineChunks = wrapWord_1.
|
|
21
|
+
lineChunks = wrapWord_1.wrapWord(cellLines[lineNr], cellWidth);
|
|
23
22
|
}
|
|
24
23
|
else {
|
|
25
|
-
lineChunks = wrapString_1.
|
|
24
|
+
lineChunks = wrapString_1.wrapString(cellLines[lineNr], cellWidth);
|
|
26
25
|
}
|
|
27
26
|
// Replace our original array element with whatever the wrapping returned
|
|
28
27
|
cellLines.splice(lineNr, 1, ...lineChunks);
|
|
@@ -30,3 +29,4 @@ exports.default = (cellValue, columnWidth, useWrapWord) => {
|
|
|
30
29
|
}
|
|
31
30
|
return cellLines;
|
|
32
31
|
};
|
|
32
|
+
exports.wrapCell = wrapCell;
|
package/dist/wrapString.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
declare const _default: (subject: string, size: number) => string[];
|
|
2
1
|
/**
|
|
3
2
|
* Creates an array of strings split into groups the length of size.
|
|
4
3
|
* This function works with strings that contain ASCII characters.
|
|
@@ -7,4 +6,4 @@ declare const _default: (subject: string, size: number) => string[];
|
|
|
7
6
|
* in that whitespace characters that occur on a chunk size limit are trimmed.
|
|
8
7
|
*
|
|
9
8
|
*/
|
|
10
|
-
export
|
|
9
|
+
export declare const wrapString: (subject: string, size: number) => string[];
|
package/dist/wrapString.js
CHANGED
|
@@ -3,6 +3,7 @@ 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.wrapString = void 0;
|
|
6
7
|
const slice_ansi_1 = __importDefault(require("slice-ansi"));
|
|
7
8
|
const string_width_1 = __importDefault(require("string-width"));
|
|
8
9
|
/**
|
|
@@ -13,7 +14,7 @@ const string_width_1 = __importDefault(require("string-width"));
|
|
|
13
14
|
* in that whitespace characters that occur on a chunk size limit are trimmed.
|
|
14
15
|
*
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
const wrapString = (subject, size) => {
|
|
17
18
|
let subjectSlice = subject;
|
|
18
19
|
const chunks = [];
|
|
19
20
|
do {
|
|
@@ -22,3 +23,4 @@ exports.default = (subject, size) => {
|
|
|
22
23
|
} while (string_width_1.default(subjectSlice));
|
|
23
24
|
return chunks;
|
|
24
25
|
};
|
|
26
|
+
exports.wrapString = wrapString;
|
package/dist/wrapWord.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default _default;
|
|
1
|
+
export declare const wrapWord: (input: string, size: number) => string[];
|