table 6.1.0 → 6.3.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 +1 -1
- package/dist/alignString.d.ts +6 -0
- package/dist/alignString.js +51 -95
- package/dist/alignTableData.d.ts +3 -0
- package/dist/alignTableData.js +17 -31
- package/dist/calculateCellHeight.d.ts +2 -0
- package/dist/calculateCellHeight.js +14 -35
- package/dist/calculateCellWidthIndex.d.ts +6 -0
- package/dist/calculateCellWidthIndex.js +11 -22
- package/dist/calculateMaximumColumnWidthIndex.d.ts +6 -0
- package/dist/calculateMaximumColumnWidthIndex.js +18 -30
- package/dist/calculateRowHeightIndex.d.ts +6 -0
- package/dist/calculateRowHeightIndex.js +23 -39
- package/dist/createStream.d.ts +3 -0
- package/dist/createStream.js +65 -116
- package/dist/drawBorder.d.ts +25 -0
- package/dist/drawBorder.js +45 -106
- package/dist/drawHorizontalContent.d.ts +11 -0
- package/dist/drawHorizontalContent.js +17 -40
- package/dist/drawRow.d.ts +7 -0
- package/dist/drawRow.js +14 -39
- package/dist/drawTable.d.ts +3 -0
- package/dist/drawTable.js +33 -56
- package/dist/generated/validators.d.ts +13 -0
- package/dist/{validators.js → generated/validators.js} +309 -315
- package/dist/getBorderCharacters.d.ts +3 -0
- package/dist/getBorderCharacters.js +79 -115
- package/dist/{index.js.flow → index.d.ts} +2 -6
- package/dist/index.js +22 -30
- package/dist/makeConfig.d.ts +8 -0
- package/dist/makeConfig.js +42 -84
- package/dist/makeStreamConfig.d.ts +8 -0
- package/dist/makeStreamConfig.js +42 -90
- package/dist/mapDataUsingRowHeightIndex.d.ts +3 -0
- package/dist/mapDataUsingRowHeightIndex.js +23 -38
- package/dist/padTableData.d.ts +3 -0
- package/dist/padTableData.js +7 -20
- package/dist/stringifyTableData.d.ts +3 -0
- package/dist/stringifyTableData.js +5 -19
- package/dist/table.d.ts +3 -0
- package/dist/table.js +25 -119
- package/dist/truncateTableData.d.ts +6 -0
- package/dist/truncateTableData.js +13 -23
- package/dist/types/api.d.ts +100 -0
- package/dist/types/api.js +2 -0
- package/dist/types/internal.d.ts +1 -0
- package/dist/types/internal.js +2 -0
- package/dist/validateConfig.d.ts +3 -0
- package/dist/validateConfig.js +22 -38
- package/dist/validateTableData.d.ts +2 -0
- package/dist/validateTableData.js +23 -49
- package/dist/wrapCell.d.ts +9 -0
- package/dist/wrapCell.js +23 -38
- package/dist/wrapString.d.ts +10 -0
- package/dist/wrapString.js +14 -29
- package/dist/wrapWord.d.ts +2 -0
- package/dist/wrapWord.js +26 -44
- package/package.json +32 -24
- package/dist/alignString.js.flow +0 -97
- package/dist/alignTableData.js.flow +0 -21
- package/dist/calculateCellHeight.js.flow +0 -24
- package/dist/calculateCellWidthIndex.js.flow +0 -17
- package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
- package/dist/calculateRowHeightIndex.js.flow +0 -36
- package/dist/createStream.js.flow +0 -125
- package/dist/drawBorder.js.flow +0 -89
- package/dist/drawHorizontalContent.js.flow +0 -31
- package/dist/drawRow.js.flow +0 -29
- package/dist/drawTable.js.flow +0 -64
- package/dist/getBorderCharacters.js.flow +0 -120
- package/dist/makeConfig.js.flow +0 -85
- package/dist/makeStreamConfig.js.flow +0 -92
- package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
- package/dist/padTableData.js.flow +0 -14
- package/dist/schemas/config.json +0 -26
- package/dist/schemas/shared.json +0 -98
- package/dist/schemas/streamConfig.json +0 -23
- package/dist/stringifyTableData.js.flow +0 -11
- package/dist/table.js.flow +0 -108
- package/dist/truncateTableData.js.flow +0 -17
- package/dist/validateConfig.js.flow +0 -27
- package/dist/validateTableData.js.flow +0 -44
- package/dist/wrapCell.js.flow +0 -35
- package/dist/wrapString.js.flow +0 -29
- package/dist/wrapWord.js.flow +0 -39
package/dist/padTableData.js
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @param {table~row[]} rows
|
|
10
|
-
* @param {object} config
|
|
11
|
-
* @returns {table~row[]}
|
|
12
|
-
*/
|
|
13
|
-
const padTableData = (rows, config) => {
|
|
14
|
-
return rows.map(cells => {
|
|
15
|
-
return cells.map((value, index1) => {
|
|
16
|
-
const column = config.columns[index1];
|
|
17
|
-
return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (rows, config) => {
|
|
4
|
+
return rows.map((cells) => {
|
|
5
|
+
return cells.map((value, index1) => {
|
|
6
|
+
const column = config.columns[index1];
|
|
7
|
+
return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight);
|
|
8
|
+
});
|
|
18
9
|
});
|
|
19
|
-
});
|
|
20
10
|
};
|
|
21
|
-
|
|
22
|
-
var _default = padTableData;
|
|
23
|
-
exports.default = _default;
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Casts all cell values to a string.
|
|
10
|
-
*
|
|
11
|
-
* @param {table~row[]} rows
|
|
12
|
-
* @returns {table~row[]}
|
|
13
|
-
*/
|
|
14
|
-
const stringifyTableData = rows => {
|
|
15
|
-
return rows.map(cells => {
|
|
16
|
-
return cells.map(String);
|
|
17
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (rows) => {
|
|
4
|
+
return rows.map((cells) => {
|
|
5
|
+
return cells.map(String);
|
|
6
|
+
});
|
|
18
7
|
};
|
|
19
|
-
|
|
20
|
-
var _default = stringifyTableData;
|
|
21
|
-
exports.default = _default;
|
package/dist/table.d.ts
ADDED
package/dist/table.js
CHANGED
|
@@ -1,121 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @typedef {string} table~cell
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @typedef {table~cell[]} table~row
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @typedef {object} table~columns
|
|
40
|
-
* @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
|
|
41
|
-
* @property {number} width Column width (default: auto).
|
|
42
|
-
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
|
|
43
|
-
* @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters
|
|
44
|
-
* @property {number} paddingLeft Cell content padding width left (default: 1).
|
|
45
|
-
* @property {number} paddingRight Cell content padding width right (default: 1).
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @typedef {object} table~border
|
|
50
|
-
* @property {string} topBody
|
|
51
|
-
* @property {string} topJoin
|
|
52
|
-
* @property {string} topLeft
|
|
53
|
-
* @property {string} topRight
|
|
54
|
-
* @property {string} bottomBody
|
|
55
|
-
* @property {string} bottomJoin
|
|
56
|
-
* @property {string} bottomLeft
|
|
57
|
-
* @property {string} bottomRight
|
|
58
|
-
* @property {string} bodyLeft
|
|
59
|
-
* @property {string} bodyRight
|
|
60
|
-
* @property {string} bodyJoin
|
|
61
|
-
* @property {string} joinBody
|
|
62
|
-
* @property {string} joinLeft
|
|
63
|
-
* @property {string} joinRight
|
|
64
|
-
* @property {string} joinJoin
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Used to tell whether to draw a vertical line.
|
|
69
|
-
* This callback is called for each non-content line of the table.
|
|
70
|
-
* The default behavior is to always return true.
|
|
71
|
-
*
|
|
72
|
-
* @typedef {Function} drawVerticalLine
|
|
73
|
-
* @param {number} index
|
|
74
|
-
* @param {number} size
|
|
75
|
-
* @returns {boolean}
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Used to tell whether to draw a horizontal line.
|
|
80
|
-
* This callback is called for each non-content line of the table.
|
|
81
|
-
* The default behavior is to always return true.
|
|
82
|
-
*
|
|
83
|
-
* @typedef {Function} drawHorizontalLine
|
|
84
|
-
* @param {number} index
|
|
85
|
-
* @param {number} size
|
|
86
|
-
* @returns {boolean}
|
|
87
|
-
*/
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @typedef {object} table~config
|
|
91
|
-
* @property {table~border} border
|
|
92
|
-
* @property {table~columns[]} columns Column specific configuration.
|
|
93
|
-
* @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
|
|
94
|
-
* @property {table~drawVerticalLine} drawVerticalLine
|
|
95
|
-
* @property {table~drawHorizontalLine} drawHorizontalLine
|
|
96
|
-
* @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Generates a text table.
|
|
101
|
-
*
|
|
102
|
-
* @param {table~row[]} data
|
|
103
|
-
* @param {table~config} userConfig
|
|
104
|
-
* @returns {string}
|
|
105
|
-
*/
|
|
106
|
-
const table = (data, userConfig = {}) => {
|
|
107
|
-
let rows;
|
|
108
|
-
(0, _validateTableData.default)(data);
|
|
109
|
-
rows = (0, _stringifyTableData.default)(data);
|
|
110
|
-
const config = (0, _makeConfig.default)(rows, userConfig);
|
|
111
|
-
rows = (0, _truncateTableData.default)(data, config);
|
|
112
|
-
const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config);
|
|
113
|
-
rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config);
|
|
114
|
-
rows = (0, _alignTableData.default)(rows, config);
|
|
115
|
-
rows = (0, _padTableData.default)(rows, config);
|
|
116
|
-
const cellWidthIndex = (0, _calculateCellWidthIndex.default)(rows[0]);
|
|
117
|
-
return (0, _drawTable.default)(rows, cellWidthIndex, rowHeightIndex, config);
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const alignTableData_1 = __importDefault(require("./alignTableData"));
|
|
7
|
+
const calculateCellWidthIndex_1 = __importDefault(require("./calculateCellWidthIndex"));
|
|
8
|
+
const calculateRowHeightIndex_1 = __importDefault(require("./calculateRowHeightIndex"));
|
|
9
|
+
const drawTable_1 = __importDefault(require("./drawTable"));
|
|
10
|
+
const makeConfig_1 = __importDefault(require("./makeConfig"));
|
|
11
|
+
const mapDataUsingRowHeightIndex_1 = __importDefault(require("./mapDataUsingRowHeightIndex"));
|
|
12
|
+
const padTableData_1 = __importDefault(require("./padTableData"));
|
|
13
|
+
const stringifyTableData_1 = __importDefault(require("./stringifyTableData"));
|
|
14
|
+
const truncateTableData_1 = __importDefault(require("./truncateTableData"));
|
|
15
|
+
const validateTableData_1 = __importDefault(require("./validateTableData"));
|
|
16
|
+
exports.default = (data, userConfig = {}) => {
|
|
17
|
+
validateTableData_1.default(data);
|
|
18
|
+
let rows = stringifyTableData_1.default(data);
|
|
19
|
+
const config = makeConfig_1.default(rows, userConfig);
|
|
20
|
+
rows = truncateTableData_1.default(rows, config);
|
|
21
|
+
const rowHeightIndex = calculateRowHeightIndex_1.default(rows, config);
|
|
22
|
+
rows = mapDataUsingRowHeightIndex_1.default(rows, rowHeightIndex, config);
|
|
23
|
+
rows = alignTableData_1.default(rows, config);
|
|
24
|
+
rows = padTableData_1.default(rows, config);
|
|
25
|
+
const cellWidthIndex = calculateCellWidthIndex_1.default(rows[0]);
|
|
26
|
+
return drawTable_1.default(rows, cellWidthIndex, rowHeightIndex, config);
|
|
118
27
|
};
|
|
119
|
-
|
|
120
|
-
var _default = table;
|
|
121
|
-
exports.default = _default;
|
|
@@ -1,29 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _lodash = _interopRequireDefault(require("lodash.truncate"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const lodash_truncate_1 = __importDefault(require("lodash.truncate"));
|
|
12
7
|
/**
|
|
13
8
|
* @todo Make it work with ASCII content.
|
|
14
|
-
* @param {table~row[]} rows
|
|
15
|
-
* @param {object} config
|
|
16
|
-
* @returns {table~row[]}
|
|
17
9
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
exports.default = (rows, config) => {
|
|
11
|
+
return rows.map((cells) => {
|
|
12
|
+
return cells.map((content, index) => {
|
|
13
|
+
return lodash_truncate_1.default(content, {
|
|
14
|
+
length: config.columns[index].truncate,
|
|
15
|
+
omission: '…',
|
|
16
|
+
});
|
|
17
|
+
});
|
|
24
18
|
});
|
|
25
|
-
});
|
|
26
19
|
};
|
|
27
|
-
|
|
28
|
-
var _default = truncateTableData;
|
|
29
|
-
exports.default = _default;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export declare type DrawLinePredicate = (index: number, size: number) => boolean;
|
|
2
|
+
export declare type DrawVerticalLine = DrawLinePredicate;
|
|
3
|
+
export declare type DrawHorizontalLine = DrawLinePredicate;
|
|
4
|
+
export declare type BorderUserConfig = {
|
|
5
|
+
readonly topLeft?: string;
|
|
6
|
+
readonly topRight?: string;
|
|
7
|
+
readonly topBody?: string;
|
|
8
|
+
readonly topJoin?: string;
|
|
9
|
+
readonly bottomLeft?: string;
|
|
10
|
+
readonly bottomRight?: string;
|
|
11
|
+
readonly bottomBody?: string;
|
|
12
|
+
readonly bottomJoin?: string;
|
|
13
|
+
readonly bodyRight?: string;
|
|
14
|
+
readonly bodyLeft?: string;
|
|
15
|
+
readonly bodyJoin?: string;
|
|
16
|
+
readonly joinLeft?: string;
|
|
17
|
+
readonly joinRight?: string;
|
|
18
|
+
readonly joinBody?: string;
|
|
19
|
+
readonly joinJoin?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare type BorderConfig = Required<BorderUserConfig>;
|
|
22
|
+
export declare type ColumnUserConfig = {
|
|
23
|
+
/**
|
|
24
|
+
* Cell content horizontal alignment (default: left)
|
|
25
|
+
*/
|
|
26
|
+
readonly alignment?: 'center' | 'left' | 'right';
|
|
27
|
+
/**
|
|
28
|
+
* Column width (default: auto calculation based on the cell content)
|
|
29
|
+
*/
|
|
30
|
+
readonly width?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Number of characters are which the content will be truncated (default: Infinity)
|
|
33
|
+
*/
|
|
34
|
+
readonly truncate?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Cell content padding width left (default: 1)
|
|
37
|
+
*/
|
|
38
|
+
readonly paddingLeft?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Cell content padding width right (default: 1)
|
|
41
|
+
*/
|
|
42
|
+
readonly paddingRight?: number;
|
|
43
|
+
/**
|
|
44
|
+
* If true, the text is broken at the nearest space or one of the special characters: "\|/_.,;-"
|
|
45
|
+
*/
|
|
46
|
+
readonly wrapWord?: boolean;
|
|
47
|
+
};
|
|
48
|
+
export declare type BaseUserConfig = {
|
|
49
|
+
/**
|
|
50
|
+
* Custom border
|
|
51
|
+
*/
|
|
52
|
+
readonly border?: BorderUserConfig;
|
|
53
|
+
/**
|
|
54
|
+
* Default values for all columns. Column specific settings overwrite the default values.
|
|
55
|
+
*/
|
|
56
|
+
readonly columnDefault?: ColumnUserConfig;
|
|
57
|
+
/**
|
|
58
|
+
* Column specific configuration.
|
|
59
|
+
*/
|
|
60
|
+
readonly columns?: Indexable<ColumnUserConfig>;
|
|
61
|
+
/**
|
|
62
|
+
* Used to tell whether to draw a vertical line.
|
|
63
|
+
* This callback is called for each non-content line of the table.
|
|
64
|
+
* The default behavior is to always return true.
|
|
65
|
+
*/
|
|
66
|
+
readonly drawVerticalLine?: DrawVerticalLine;
|
|
67
|
+
};
|
|
68
|
+
export declare type TableUserConfig = BaseUserConfig & {
|
|
69
|
+
/**
|
|
70
|
+
* Used to tell whether to draw a horizontal line.
|
|
71
|
+
* This callback is called for each non-content line of the table.
|
|
72
|
+
* The default behavior is to always return true.
|
|
73
|
+
*/
|
|
74
|
+
readonly drawHorizontalLine?: DrawHorizontalLine;
|
|
75
|
+
/**
|
|
76
|
+
* Horizontal lines inside the table are not drawn.
|
|
77
|
+
*/
|
|
78
|
+
readonly singleLine?: boolean;
|
|
79
|
+
};
|
|
80
|
+
export declare type StreamUserConfig = BaseUserConfig & {
|
|
81
|
+
/**
|
|
82
|
+
* The number of columns
|
|
83
|
+
*/
|
|
84
|
+
readonly columnCount: number;
|
|
85
|
+
/**
|
|
86
|
+
* Default values for all columns. Column specific settings overwrite the default values.
|
|
87
|
+
*/
|
|
88
|
+
readonly columnDefault: ColumnUserConfig & {
|
|
89
|
+
/**
|
|
90
|
+
* The default width for each column
|
|
91
|
+
*/
|
|
92
|
+
readonly width: number;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
export declare type WritableStream = {
|
|
96
|
+
readonly write: (rows: string[]) => void;
|
|
97
|
+
};
|
|
98
|
+
export declare type Indexable<T> = {
|
|
99
|
+
readonly [index: number]: T;
|
|
100
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/validateConfig.js
CHANGED
|
@@ -1,40 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
message: error.message,
|
|
25
|
-
params: error.params,
|
|
26
|
-
schemaPath: error.schemaPath
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
/* eslint-disable no-console */
|
|
30
|
-
|
|
31
|
-
console.log('config', config);
|
|
32
|
-
console.log('errors', errors);
|
|
33
|
-
/* eslint-enable no-console */
|
|
34
|
-
|
|
35
|
-
throw new Error('Invalid config.');
|
|
36
|
-
}
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const validators_1 = __importDefault(require("./generated/validators"));
|
|
7
|
+
exports.default = (schemaId, config) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const validate = validators_1.default[schemaId];
|
|
10
|
+
if (!validate(config)) {
|
|
11
|
+
const errors = (_a = validate.errors) === null || _a === void 0 ? void 0 : _a.map((error) => {
|
|
12
|
+
return {
|
|
13
|
+
message: error.message,
|
|
14
|
+
params: error.params,
|
|
15
|
+
schemaPath: error.schemaPath,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
/* eslint-disable no-console */
|
|
19
|
+
console.log('config', config);
|
|
20
|
+
console.log('errors', errors);
|
|
21
|
+
/* eslint-enable no-console */
|
|
22
|
+
throw new Error('Invalid config.');
|
|
23
|
+
}
|
|
37
24
|
};
|
|
38
|
-
|
|
39
|
-
var _default = validateConfig;
|
|
40
|
-
exports.default = _default;
|
|
@@ -1,54 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {string} cell
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {cell[]} validateData~column
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {column[]} rows
|
|
18
|
-
* @returns {undefined}
|
|
19
|
-
*/
|
|
20
|
-
const validateTableData = rows => {
|
|
21
|
-
if (!Array.isArray(rows)) {
|
|
22
|
-
throw new TypeError('Table data must be an array.');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (rows.length === 0) {
|
|
26
|
-
throw new Error('Table must define at least one row.');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (rows[0].length === 0) {
|
|
30
|
-
throw new Error('Table must define at least one column.');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const columnNumber = rows[0].length;
|
|
34
|
-
|
|
35
|
-
for (const cells of rows) {
|
|
36
|
-
if (!Array.isArray(cells)) {
|
|
37
|
-
throw new TypeError('Table row data must be an array.');
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (rows) => {
|
|
4
|
+
if (!Array.isArray(rows)) {
|
|
5
|
+
throw new TypeError('Table data must be an array.');
|
|
38
6
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
throw new Error('Table must have a consistent number of cells.');
|
|
7
|
+
if (rows.length === 0) {
|
|
8
|
+
throw new Error('Table must define at least one row.');
|
|
42
9
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
10
|
+
if (rows[0].length === 0) {
|
|
11
|
+
throw new Error('Table must define at least one column.');
|
|
12
|
+
}
|
|
13
|
+
const columnNumber = rows[0].length;
|
|
14
|
+
for (const row of rows) {
|
|
15
|
+
if (!Array.isArray(row)) {
|
|
16
|
+
throw new TypeError('Table row data must be an array.');
|
|
17
|
+
}
|
|
18
|
+
if (row.length !== columnNumber) {
|
|
19
|
+
throw new Error('Table must have a consistent number of cells.');
|
|
20
|
+
}
|
|
21
|
+
for (const cell of row) {
|
|
22
|
+
// eslint-disable-next-line no-control-regex
|
|
23
|
+
if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) {
|
|
24
|
+
throw new Error('Table data must not contain control characters.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
49
27
|
}
|
|
50
|
-
}
|
|
51
28
|
};
|
|
52
|
-
|
|
53
|
-
var _default = validateTableData;
|
|
54
|
-
exports.default = _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const _default: (cellValue: string, columnWidth: number, useWrapWord: boolean) => string[];
|
|
2
|
+
/**
|
|
3
|
+
* Wrap a single cell value into a list of lines
|
|
4
|
+
*
|
|
5
|
+
* Always wraps on newlines, for the remainder uses either word or string wrapping
|
|
6
|
+
* depending on user configuration.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export default _default;
|
package/dist/wrapCell.js
CHANGED
|
@@ -1,47 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _wrapString = _interopRequireDefault(require("./wrapString"));
|
|
9
|
-
|
|
10
|
-
var _wrapWord = _interopRequireDefault(require("./wrapWord"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const wrapString_1 = __importDefault(require("./wrapString"));
|
|
7
|
+
const wrapWord_1 = __importDefault(require("./wrapWord"));
|
|
14
8
|
/**
|
|
15
9
|
* Wrap a single cell value into a list of lines
|
|
16
10
|
*
|
|
17
11
|
* Always wraps on newlines, for the remainder uses either word or string wrapping
|
|
18
12
|
* depending on user configuration.
|
|
19
13
|
*
|
|
20
|
-
* @param {string} cellValue
|
|
21
|
-
* @param {number} columnWidth
|
|
22
|
-
* @param {boolean} useWrapWord
|
|
23
|
-
* @returns {Array}
|
|
24
14
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return cellLines;
|
|
15
|
+
exports.default = (cellValue, columnWidth, useWrapWord) => {
|
|
16
|
+
// First split on literal newlines
|
|
17
|
+
const cellLines = cellValue.split('\n');
|
|
18
|
+
// Then iterate over the list and word-wrap every remaining line if necessary.
|
|
19
|
+
for (let lineNr = 0; lineNr < cellLines.length;) {
|
|
20
|
+
let lineChunks;
|
|
21
|
+
if (useWrapWord) {
|
|
22
|
+
lineChunks = wrapWord_1.default(cellLines[lineNr], columnWidth);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
lineChunks = wrapString_1.default(cellLines[lineNr], columnWidth);
|
|
26
|
+
}
|
|
27
|
+
// Replace our original array element with whatever the wrapping returned
|
|
28
|
+
cellLines.splice(lineNr, 1, ...lineChunks);
|
|
29
|
+
lineNr += lineChunks.length;
|
|
30
|
+
}
|
|
31
|
+
return cellLines;
|
|
44
32
|
};
|
|
45
|
-
|
|
46
|
-
var _default = wrapCell;
|
|
47
|
-
exports.default = _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _default: (subject: string, size: number) => string[];
|
|
2
|
+
/**
|
|
3
|
+
* Creates an array of strings split into groups the length of size.
|
|
4
|
+
* This function works with strings that contain ASCII characters.
|
|
5
|
+
*
|
|
6
|
+
* wrapText is different from would-be "chunk" implementation
|
|
7
|
+
* in that whitespace characters that occur on a chunk size limit are trimmed.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export default _default;
|