3 Object.defineProperty(exports, "__esModule", {
7 var _drawTable = require('./drawTable');
9 var _drawTable2 = _interopRequireDefault(_drawTable);
11 var _calculateCellWidthIndex = require('./calculateCellWidthIndex');
13 var _calculateCellWidthIndex2 = _interopRequireDefault(_calculateCellWidthIndex);
15 var _makeConfig = require('./makeConfig');
17 var _makeConfig2 = _interopRequireDefault(_makeConfig);
19 var _calculateRowHeightIndex = require('./calculateRowHeightIndex');
21 var _calculateRowHeightIndex2 = _interopRequireDefault(_calculateRowHeightIndex);
23 var _mapDataUsingRowHeightIndex = require('./mapDataUsingRowHeightIndex');
25 var _mapDataUsingRowHeightIndex2 = _interopRequireDefault(_mapDataUsingRowHeightIndex);
27 var _alignTableData = require('./alignTableData');
29 var _alignTableData2 = _interopRequireDefault(_alignTableData);
31 var _padTableData = require('./padTableData');
33 var _padTableData2 = _interopRequireDefault(_padTableData);
35 var _validateTableData = require('./validateTableData');
37 var _validateTableData2 = _interopRequireDefault(_validateTableData);
39 var _stringifyTableData = require('./stringifyTableData');
41 var _stringifyTableData2 = _interopRequireDefault(_stringifyTableData);
43 var _truncateTableData = require('./truncateTableData');
45 var _truncateTableData2 = _interopRequireDefault(_truncateTableData);
47 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
50 * @typedef {string} table~cell
54 * @typedef {table~cell[]} table~row
58 * @typedef {Object} table~columns
59 * @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
60 * @property {number} width Column width (default: auto).
61 * @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
62 * @property {number} paddingLeft Cell content padding width left (default: 1).
63 * @property {number} paddingRight Cell content padding width right (default: 1).
67 * @typedef {Object} table~border
68 * @property {string} topBody
69 * @property {string} topJoin
70 * @property {string} topLeft
71 * @property {string} topRight
72 * @property {string} bottomBody
73 * @property {string} bottomJoin
74 * @property {string} bottomLeft
75 * @property {string} bottomRight
76 * @property {string} bodyLeft
77 * @property {string} bodyRight
78 * @property {string} bodyJoin
79 * @property {string} joinBody
80 * @property {string} joinLeft
81 * @property {string} joinRight
82 * @property {string} joinJoin
86 * Used to tell whether to draw a horizontal line.
87 * This callback is called for each non-content line of the table.
88 * The default behavior is to always return true.
90 * @typedef {Function} drawHorizontalLine
91 * @param {number} index
92 * @param {number} size
97 * @typedef {Object} table~config
98 * @property {table~border} border
99 * @property {table~columns[]} columns Column specific configuration.
100 * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
101 * @property {table~drawHorizontalLine} drawHorizontalLine
105 * Generates a text table.
107 * @param {table~row[]} data
108 * @param {table~config} userConfig
111 exports.default = function (data) {
112 let userConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
116 (0, _validateTableData2.default)(data);
118 rows = (0, _stringifyTableData2.default)(data);
120 const config = (0, _makeConfig2.default)(rows, userConfig);
122 rows = (0, _truncateTableData2.default)(data, config);
124 const rowHeightIndex = (0, _calculateRowHeightIndex2.default)(rows, config);
126 rows = (0, _mapDataUsingRowHeightIndex2.default)(rows, rowHeightIndex, config);
127 rows = (0, _alignTableData2.default)(rows, config);
128 rows = (0, _padTableData2.default)(rows, config);
130 const cellWidthIndex = (0, _calculateCellWidthIndex2.default)(rows[0]);
132 return (0, _drawTable2.default)(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine);