3 Object.defineProperty(exports, "__esModule", {
6 exports.default = void 0;
8 var _alignTableData = _interopRequireDefault(require("./alignTableData"));
10 var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
12 var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex"));
14 var _drawTable = _interopRequireDefault(require("./drawTable"));
16 var _makeConfig = _interopRequireDefault(require("./makeConfig"));
18 var _mapDataUsingRowHeightIndex = _interopRequireDefault(require("./mapDataUsingRowHeightIndex"));
20 var _padTableData = _interopRequireDefault(require("./padTableData"));
22 var _stringifyTableData = _interopRequireDefault(require("./stringifyTableData"));
24 var _truncateTableData = _interopRequireDefault(require("./truncateTableData"));
26 var _validateTableData = _interopRequireDefault(require("./validateTableData"));
28 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31 * @typedef {string} table~cell
35 * @typedef {table~cell[]} table~row
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).
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
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.
72 * @typedef {Function} drawHorizontalLine
73 * @param {number} index
74 * @param {number} size
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.
88 * Generates a text table.
90 * @param {table~row[]} data
91 * @param {table~config} userConfig
94 const table = (data, userConfig = {}) => {
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);
108 var _default = table;
109 exports.default = _default;
110 //# sourceMappingURL=table.js.map