table 6.0.9 → 6.3.1
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 +53 -1
- package/dist/src/alignString.d.ts +6 -0
- package/dist/src/alignString.js +64 -0
- package/dist/src/alignTableData.d.ts +3 -0
- package/dist/src/alignTableData.js +21 -0
- package/dist/src/calculateCellHeight.d.ts +2 -0
- package/dist/src/calculateCellHeight.js +17 -0
- package/dist/src/calculateCellWidthIndex.d.ts +6 -0
- package/dist/src/calculateCellWidthIndex.js +17 -0
- package/dist/src/calculateMaximumColumnWidthIndex.d.ts +6 -0
- package/dist/src/calculateMaximumColumnWidthIndex.js +25 -0
- package/dist/src/calculateRowHeightIndex.d.ts +6 -0
- package/dist/src/calculateRowHeightIndex.js +30 -0
- package/dist/src/createStream.d.ts +3 -0
- package/dist/src/createStream.js +74 -0
- package/dist/src/drawBorder.d.ts +25 -0
- package/dist/src/drawBorder.js +55 -0
- package/dist/src/drawHorizontalContent.d.ts +11 -0
- package/dist/src/drawHorizontalContent.js +19 -0
- package/dist/src/drawRow.d.ts +7 -0
- package/dist/src/drawRow.js +17 -0
- package/dist/src/drawTable.d.ts +3 -0
- package/dist/src/drawTable.js +38 -0
- package/dist/src/getBorderCharacters.d.ts +3 -0
- package/dist/src/getBorderCharacters.js +83 -0
- package/dist/{index.js.flow → src/index.d.ts} +2 -6
- package/dist/src/index.js +24 -0
- package/dist/src/makeConfig.d.ts +8 -0
- package/dist/src/makeConfig.js +59 -0
- package/dist/src/makeStreamConfig.d.ts +8 -0
- package/dist/src/makeStreamConfig.js +60 -0
- package/dist/src/mapDataUsingRowHeightIndex.d.ts +3 -0
- package/dist/src/mapDataUsingRowHeightIndex.js +27 -0
- package/dist/src/padTableData.d.ts +3 -0
- package/dist/src/padTableData.js +11 -0
- package/dist/src/stringifyTableData.d.ts +3 -0
- package/dist/src/stringifyTableData.js +8 -0
- package/dist/src/table.d.ts +3 -0
- package/dist/src/table.js +28 -0
- package/dist/src/truncateTableData.d.ts +6 -0
- package/dist/src/truncateTableData.js +20 -0
- package/dist/src/types/api.d.ts +100 -0
- package/dist/src/types/api.js +3 -0
- package/dist/src/types/internal.d.ts +1 -0
- package/dist/src/types/internal.js +3 -0
- package/dist/src/validateConfig.d.ts +3 -0
- package/dist/src/validateConfig.js +27 -0
- package/dist/src/validateTableData.d.ts +2 -0
- package/dist/src/validateTableData.js +29 -0
- package/dist/{validators.js → src/validators.js} +54 -14
- package/dist/src/wrapCell.d.ts +9 -0
- package/dist/src/wrapCell.js +33 -0
- package/dist/src/wrapString.d.ts +10 -0
- package/dist/src/wrapString.js +25 -0
- package/dist/src/wrapWord.d.ts +2 -0
- package/dist/src/wrapWord.js +29 -0
- package/package.json +32 -25
- package/dist/alignString.js +0 -107
- package/dist/alignString.js.flow +0 -97
- package/dist/alignTableData.js +0 -34
- package/dist/alignTableData.js.flow +0 -21
- package/dist/calculateCellHeight.js +0 -37
- package/dist/calculateCellHeight.js.flow +0 -24
- package/dist/calculateCellWidthIndex.js +0 -27
- package/dist/calculateCellWidthIndex.js.flow +0 -17
- package/dist/calculateMaximumColumnWidthIndex.js +0 -36
- package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
- package/dist/calculateRowHeightIndex.js +0 -45
- package/dist/calculateRowHeightIndex.js.flow +0 -36
- package/dist/createStream.js +0 -124
- package/dist/createStream.js.flow +0 -125
- package/dist/drawBorder.js +0 -109
- package/dist/drawBorder.js.flow +0 -101
- package/dist/drawRow.js +0 -25
- package/dist/drawRow.js.flow +0 -15
- package/dist/drawTable.js +0 -58
- package/dist/drawTable.js.flow +0 -53
- package/dist/getBorderCharacters.js +0 -118
- package/dist/getBorderCharacters.js.flow +0 -120
- package/dist/index.js +0 -31
- package/dist/makeConfig.js +0 -91
- package/dist/makeConfig.js.flow +0 -76
- package/dist/makeStreamConfig.js +0 -97
- package/dist/makeStreamConfig.js.flow +0 -83
- package/dist/mapDataUsingRowHeightIndex.js +0 -41
- package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
- package/dist/padTableData.js +0 -23
- package/dist/padTableData.js.flow +0 -14
- package/dist/schemas/config.json +0 -23
- package/dist/schemas/shared.json +0 -98
- package/dist/schemas/streamConfig.json +0 -20
- package/dist/stringifyTableData.js +0 -21
- package/dist/stringifyTableData.js.flow +0 -11
- package/dist/table.js +0 -109
- package/dist/table.js.flow +0 -96
- package/dist/truncateTableData.js +0 -29
- package/dist/truncateTableData.js.flow +0 -17
- package/dist/validateConfig.js +0 -40
- package/dist/validateConfig.js.flow +0 -27
- package/dist/validateTableData.js +0 -54
- package/dist/validateTableData.js.flow +0 -44
- package/dist/wrapCell.js +0 -47
- package/dist/wrapCell.js.flow +0 -35
- package/dist/wrapString.js +0 -39
- package/dist/wrapString.js.flow +0 -29
- package/dist/wrapWord.js +0 -46
- package/dist/wrapWord.js.flow +0 -39
package/dist/padTableData.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
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);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
var _default = padTableData;
|
|
23
|
-
exports.default = _default;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {table~row[]} rows
|
|
3
|
-
* @param {object} config
|
|
4
|
-
* @returns {table~row[]}
|
|
5
|
-
*/
|
|
6
|
-
export default (rows, config) => {
|
|
7
|
-
return rows.map((cells) => {
|
|
8
|
-
return cells.map((value, index1) => {
|
|
9
|
-
const column = config.columns[index1];
|
|
10
|
-
|
|
11
|
-
return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
};
|
package/dist/schemas/config.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$id": "config.json",
|
|
3
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
-
"type": "object",
|
|
5
|
-
"properties": {
|
|
6
|
-
"border": {
|
|
7
|
-
"$ref": "shared.json#/definitions/borders"
|
|
8
|
-
},
|
|
9
|
-
"columns": {
|
|
10
|
-
"$ref": "shared.json#/definitions/columns"
|
|
11
|
-
},
|
|
12
|
-
"columnDefault": {
|
|
13
|
-
"$ref": "shared.json#/definitions/column"
|
|
14
|
-
},
|
|
15
|
-
"drawHorizontalLine": {
|
|
16
|
-
"typeof": "function"
|
|
17
|
-
},
|
|
18
|
-
"singleLine": {
|
|
19
|
-
"typeof": "boolean"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"additionalProperties": false
|
|
23
|
-
}
|
package/dist/schemas/shared.json
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$id": "shared.json",
|
|
3
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
-
"definitions": {
|
|
5
|
-
"columns": {
|
|
6
|
-
"type": "object",
|
|
7
|
-
"patternProperties": {
|
|
8
|
-
"^[0-9]+$": {
|
|
9
|
-
"$ref": "#/definitions/column"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"additionalProperties": false
|
|
13
|
-
},
|
|
14
|
-
"column": {
|
|
15
|
-
"type": "object",
|
|
16
|
-
"properties": {
|
|
17
|
-
"alignment": {
|
|
18
|
-
"type": "string",
|
|
19
|
-
"enum": [
|
|
20
|
-
"left",
|
|
21
|
-
"right",
|
|
22
|
-
"center"
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
|
-
"width": {
|
|
26
|
-
"type": "number"
|
|
27
|
-
},
|
|
28
|
-
"wrapWord": {
|
|
29
|
-
"type": "boolean"
|
|
30
|
-
},
|
|
31
|
-
"truncate": {
|
|
32
|
-
"type": "number"
|
|
33
|
-
},
|
|
34
|
-
"paddingLeft": {
|
|
35
|
-
"type": "number"
|
|
36
|
-
},
|
|
37
|
-
"paddingRight": {
|
|
38
|
-
"type": "number"
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
"additionalProperties": false
|
|
42
|
-
},
|
|
43
|
-
"borders": {
|
|
44
|
-
"type": "object",
|
|
45
|
-
"properties": {
|
|
46
|
-
"topBody": {
|
|
47
|
-
"$ref": "#/definitions/border"
|
|
48
|
-
},
|
|
49
|
-
"topJoin": {
|
|
50
|
-
"$ref": "#/definitions/border"
|
|
51
|
-
},
|
|
52
|
-
"topLeft": {
|
|
53
|
-
"$ref": "#/definitions/border"
|
|
54
|
-
},
|
|
55
|
-
"topRight": {
|
|
56
|
-
"$ref": "#/definitions/border"
|
|
57
|
-
},
|
|
58
|
-
"bottomBody": {
|
|
59
|
-
"$ref": "#/definitions/border"
|
|
60
|
-
},
|
|
61
|
-
"bottomJoin": {
|
|
62
|
-
"$ref": "#/definitions/border"
|
|
63
|
-
},
|
|
64
|
-
"bottomLeft": {
|
|
65
|
-
"$ref": "#/definitions/border"
|
|
66
|
-
},
|
|
67
|
-
"bottomRight": {
|
|
68
|
-
"$ref": "#/definitions/border"
|
|
69
|
-
},
|
|
70
|
-
"bodyLeft": {
|
|
71
|
-
"$ref": "#/definitions/border"
|
|
72
|
-
},
|
|
73
|
-
"bodyRight": {
|
|
74
|
-
"$ref": "#/definitions/border"
|
|
75
|
-
},
|
|
76
|
-
"bodyJoin": {
|
|
77
|
-
"$ref": "#/definitions/border"
|
|
78
|
-
},
|
|
79
|
-
"joinBody": {
|
|
80
|
-
"$ref": "#/definitions/border"
|
|
81
|
-
},
|
|
82
|
-
"joinLeft": {
|
|
83
|
-
"$ref": "#/definitions/border"
|
|
84
|
-
},
|
|
85
|
-
"joinRight": {
|
|
86
|
-
"$ref": "#/definitions/border"
|
|
87
|
-
},
|
|
88
|
-
"joinJoin": {
|
|
89
|
-
"$ref": "#/definitions/border"
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
"additionalProperties": false
|
|
93
|
-
},
|
|
94
|
-
"border": {
|
|
95
|
-
"type": "string"
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$id": "streamConfig.json",
|
|
3
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
-
"type": "object",
|
|
5
|
-
"properties": {
|
|
6
|
-
"border": {
|
|
7
|
-
"$ref": "shared.json#/definitions/borders"
|
|
8
|
-
},
|
|
9
|
-
"columns": {
|
|
10
|
-
"$ref": "shared.json#/definitions/columns"
|
|
11
|
-
},
|
|
12
|
-
"columnDefault": {
|
|
13
|
-
"$ref": "shared.json#/definitions/column"
|
|
14
|
-
},
|
|
15
|
-
"columnCount": {
|
|
16
|
-
"type": "number"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"additionalProperties": false
|
|
20
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
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
|
-
});
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
var _default = stringifyTableData;
|
|
21
|
-
exports.default = _default;
|
package/dist/table.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _alignTableData = _interopRequireDefault(require("./alignTableData"));
|
|
9
|
-
|
|
10
|
-
var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
|
|
11
|
-
|
|
12
|
-
var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex"));
|
|
13
|
-
|
|
14
|
-
var _drawTable = _interopRequireDefault(require("./drawTable"));
|
|
15
|
-
|
|
16
|
-
var _makeConfig = _interopRequireDefault(require("./makeConfig"));
|
|
17
|
-
|
|
18
|
-
var _mapDataUsingRowHeightIndex = _interopRequireDefault(require("./mapDataUsingRowHeightIndex"));
|
|
19
|
-
|
|
20
|
-
var _padTableData = _interopRequireDefault(require("./padTableData"));
|
|
21
|
-
|
|
22
|
-
var _stringifyTableData = _interopRequireDefault(require("./stringifyTableData"));
|
|
23
|
-
|
|
24
|
-
var _truncateTableData = _interopRequireDefault(require("./truncateTableData"));
|
|
25
|
-
|
|
26
|
-
var _validateTableData = _interopRequireDefault(require("./validateTableData"));
|
|
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 horizontal 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} drawHorizontalLine
|
|
73
|
-
* @param {number} index
|
|
74
|
-
* @param {number} size
|
|
75
|
-
* @returns {boolean}
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @typedef {object} table~config
|
|
80
|
-
* @property {table~border} border
|
|
81
|
-
* @property {table~columns[]} columns Column specific configuration.
|
|
82
|
-
* @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
|
|
83
|
-
* @property {table~drawHorizontalLine} drawHorizontalLine
|
|
84
|
-
* @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Generates a text table.
|
|
89
|
-
*
|
|
90
|
-
* @param {table~row[]} data
|
|
91
|
-
* @param {table~config} userConfig
|
|
92
|
-
* @returns {string}
|
|
93
|
-
*/
|
|
94
|
-
const table = (data, userConfig = {}) => {
|
|
95
|
-
let rows;
|
|
96
|
-
(0, _validateTableData.default)(data);
|
|
97
|
-
rows = (0, _stringifyTableData.default)(data);
|
|
98
|
-
const config = (0, _makeConfig.default)(rows, userConfig);
|
|
99
|
-
rows = (0, _truncateTableData.default)(data, config);
|
|
100
|
-
const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config);
|
|
101
|
-
rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config);
|
|
102
|
-
rows = (0, _alignTableData.default)(rows, config);
|
|
103
|
-
rows = (0, _padTableData.default)(rows, config);
|
|
104
|
-
const cellWidthIndex = (0, _calculateCellWidthIndex.default)(rows[0]);
|
|
105
|
-
return (0, _drawTable.default)(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine, config.singleLine);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
var _default = table;
|
|
109
|
-
exports.default = _default;
|
package/dist/table.js.flow
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import alignTableData from './alignTableData';
|
|
2
|
-
import calculateCellWidthIndex from './calculateCellWidthIndex';
|
|
3
|
-
import calculateRowHeightIndex from './calculateRowHeightIndex';
|
|
4
|
-
import drawTable from './drawTable';
|
|
5
|
-
import makeConfig from './makeConfig';
|
|
6
|
-
import mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';
|
|
7
|
-
import padTableData from './padTableData';
|
|
8
|
-
import stringifyTableData from './stringifyTableData';
|
|
9
|
-
import truncateTableData from './truncateTableData';
|
|
10
|
-
import validateTableData from './validateTableData';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {string} table~cell
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {table~cell[]} table~row
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @typedef {object} table~columns
|
|
22
|
-
* @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
|
|
23
|
-
* @property {number} width Column width (default: auto).
|
|
24
|
-
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
|
|
25
|
-
* @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters
|
|
26
|
-
* @property {number} paddingLeft Cell content padding width left (default: 1).
|
|
27
|
-
* @property {number} paddingRight Cell content padding width right (default: 1).
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @typedef {object} table~border
|
|
32
|
-
* @property {string} topBody
|
|
33
|
-
* @property {string} topJoin
|
|
34
|
-
* @property {string} topLeft
|
|
35
|
-
* @property {string} topRight
|
|
36
|
-
* @property {string} bottomBody
|
|
37
|
-
* @property {string} bottomJoin
|
|
38
|
-
* @property {string} bottomLeft
|
|
39
|
-
* @property {string} bottomRight
|
|
40
|
-
* @property {string} bodyLeft
|
|
41
|
-
* @property {string} bodyRight
|
|
42
|
-
* @property {string} bodyJoin
|
|
43
|
-
* @property {string} joinBody
|
|
44
|
-
* @property {string} joinLeft
|
|
45
|
-
* @property {string} joinRight
|
|
46
|
-
* @property {string} joinJoin
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Used to tell whether to draw a horizontal line.
|
|
51
|
-
* This callback is called for each non-content line of the table.
|
|
52
|
-
* The default behavior is to always return true.
|
|
53
|
-
*
|
|
54
|
-
* @typedef {Function} drawHorizontalLine
|
|
55
|
-
* @param {number} index
|
|
56
|
-
* @param {number} size
|
|
57
|
-
* @returns {boolean}
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @typedef {object} table~config
|
|
62
|
-
* @property {table~border} border
|
|
63
|
-
* @property {table~columns[]} columns Column specific configuration.
|
|
64
|
-
* @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
|
|
65
|
-
* @property {table~drawHorizontalLine} drawHorizontalLine
|
|
66
|
-
* @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Generates a text table.
|
|
71
|
-
*
|
|
72
|
-
* @param {table~row[]} data
|
|
73
|
-
* @param {table~config} userConfig
|
|
74
|
-
* @returns {string}
|
|
75
|
-
*/
|
|
76
|
-
export default (data, userConfig = {}) => {
|
|
77
|
-
let rows;
|
|
78
|
-
|
|
79
|
-
validateTableData(data);
|
|
80
|
-
|
|
81
|
-
rows = stringifyTableData(data);
|
|
82
|
-
|
|
83
|
-
const config = makeConfig(rows, userConfig);
|
|
84
|
-
|
|
85
|
-
rows = truncateTableData(data, config);
|
|
86
|
-
|
|
87
|
-
const rowHeightIndex = calculateRowHeightIndex(rows, config);
|
|
88
|
-
|
|
89
|
-
rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);
|
|
90
|
-
rows = alignTableData(rows, config);
|
|
91
|
-
rows = padTableData(rows, config);
|
|
92
|
-
|
|
93
|
-
const cellWidthIndex = calculateCellWidthIndex(rows[0]);
|
|
94
|
-
|
|
95
|
-
return drawTable(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine, config.singleLine);
|
|
96
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _lodash = _interopRequireDefault(require("lodash.truncate"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @todo Make it work with ASCII content.
|
|
14
|
-
* @param {table~row[]} rows
|
|
15
|
-
* @param {object} config
|
|
16
|
-
* @returns {table~row[]}
|
|
17
|
-
*/
|
|
18
|
-
const truncateTableData = (rows, config) => {
|
|
19
|
-
return rows.map(cells => {
|
|
20
|
-
return cells.map((content, index) => {
|
|
21
|
-
return (0, _lodash.default)(content, {
|
|
22
|
-
length: config.columns[index].truncate
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
var _default = truncateTableData;
|
|
29
|
-
exports.default = _default;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import truncate from 'lodash.truncate';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @todo Make it work with ASCII content.
|
|
5
|
-
* @param {table~row[]} rows
|
|
6
|
-
* @param {object} config
|
|
7
|
-
* @returns {table~row[]}
|
|
8
|
-
*/
|
|
9
|
-
export default (rows, config) => {
|
|
10
|
-
return rows.map((cells) => {
|
|
11
|
-
return cells.map((content, index) => {
|
|
12
|
-
return truncate(content, {
|
|
13
|
-
length: config.columns[index].truncate,
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
};
|
package/dist/validateConfig.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _validators = _interopRequireDefault(require("../dist/validators"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @param {string} schemaId
|
|
14
|
-
* @param {formatData~config} config
|
|
15
|
-
* @returns {undefined}
|
|
16
|
-
*/
|
|
17
|
-
const validateConfig = (schemaId, config = {}) => {
|
|
18
|
-
const validate = _validators.default[schemaId];
|
|
19
|
-
|
|
20
|
-
if (!validate(config)) {
|
|
21
|
-
const errors = validate.errors.map(error => {
|
|
22
|
-
return {
|
|
23
|
-
dataPath: error.dataPath,
|
|
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
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
var _default = validateConfig;
|
|
40
|
-
exports.default = _default;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import validators from '../dist/validators';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {string} schemaId
|
|
5
|
-
* @param {formatData~config} config
|
|
6
|
-
* @returns {undefined}
|
|
7
|
-
*/
|
|
8
|
-
export default (schemaId, config = {}) => {
|
|
9
|
-
const validate = validators[schemaId];
|
|
10
|
-
if (!validate(config)) {
|
|
11
|
-
const errors = validate.errors.map((error) => {
|
|
12
|
-
return {
|
|
13
|
-
dataPath: error.dataPath,
|
|
14
|
-
message: error.message,
|
|
15
|
-
params: error.params,
|
|
16
|
-
schemaPath: error.schemaPath,
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
/* eslint-disable no-console */
|
|
21
|
-
console.log('config', config);
|
|
22
|
-
console.log('errors', errors);
|
|
23
|
-
/* eslint-enable no-console */
|
|
24
|
-
|
|
25
|
-
throw new Error('Invalid config.');
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
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.');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (cells.length !== columnNumber) {
|
|
41
|
-
throw new Error('Table must have a consistent number of cells.');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
for (const cell of cells) {
|
|
45
|
-
// eslint-disable-next-line no-control-regex
|
|
46
|
-
if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) {
|
|
47
|
-
throw new Error('Table data must not contain control characters.');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
var _default = validateTableData;
|
|
54
|
-
exports.default = _default;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {string} cell
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {cell[]} validateData~column
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @param {column[]} rows
|
|
11
|
-
* @returns {undefined}
|
|
12
|
-
*/
|
|
13
|
-
export default (rows) => {
|
|
14
|
-
if (!Array.isArray(rows)) {
|
|
15
|
-
throw new TypeError('Table data must be an array.');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (rows.length === 0) {
|
|
19
|
-
throw new Error('Table must define at least one row.');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (rows[0].length === 0) {
|
|
23
|
-
throw new Error('Table must define at least one column.');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const columnNumber = rows[0].length;
|
|
27
|
-
|
|
28
|
-
for (const cells of rows) {
|
|
29
|
-
if (!Array.isArray(cells)) {
|
|
30
|
-
throw new TypeError('Table row data must be an array.');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (cells.length !== columnNumber) {
|
|
34
|
-
throw new Error('Table must have a consistent number of cells.');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
for (const cell of cells) {
|
|
38
|
-
// eslint-disable-next-line no-control-regex
|
|
39
|
-
if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) {
|
|
40
|
-
throw new Error('Table data must not contain control characters.');
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
package/dist/wrapCell.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
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
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Wrap a single cell value into a list of lines
|
|
16
|
-
*
|
|
17
|
-
* Always wraps on newlines, for the remainder uses either word or string wrapping
|
|
18
|
-
* depending on user configuration.
|
|
19
|
-
*
|
|
20
|
-
* @param {string} cellValue
|
|
21
|
-
* @param {number} columnWidth
|
|
22
|
-
* @param {boolean} useWrapWord
|
|
23
|
-
* @returns {Array}
|
|
24
|
-
*/
|
|
25
|
-
const wrapCell = (cellValue, columnWidth, useWrapWord) => {
|
|
26
|
-
// First split on literal newlines
|
|
27
|
-
const cellLines = cellValue.split('\n'); // Then iterate over the list and word-wrap every remaining line if necessary.
|
|
28
|
-
|
|
29
|
-
for (let lineNr = 0; lineNr < cellLines.length;) {
|
|
30
|
-
let lineChunks;
|
|
31
|
-
|
|
32
|
-
if (useWrapWord) {
|
|
33
|
-
lineChunks = (0, _wrapWord.default)(cellLines[lineNr], columnWidth);
|
|
34
|
-
} else {
|
|
35
|
-
lineChunks = (0, _wrapString.default)(cellLines[lineNr], columnWidth);
|
|
36
|
-
} // Replace our original array element with whatever the wrapping returned
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
cellLines.splice(lineNr, 1, ...lineChunks);
|
|
40
|
-
lineNr += lineChunks.length;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return cellLines;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
var _default = wrapCell;
|
|
47
|
-
exports.default = _default;
|