.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / node_modules / table / dist / table.js
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4   value: true
5 });
6
7 var _drawTable = require('./drawTable');
8
9 var _drawTable2 = _interopRequireDefault(_drawTable);
10
11 var _calculateCellWidthIndex = require('./calculateCellWidthIndex');
12
13 var _calculateCellWidthIndex2 = _interopRequireDefault(_calculateCellWidthIndex);
14
15 var _makeConfig = require('./makeConfig');
16
17 var _makeConfig2 = _interopRequireDefault(_makeConfig);
18
19 var _calculateRowHeightIndex = require('./calculateRowHeightIndex');
20
21 var _calculateRowHeightIndex2 = _interopRequireDefault(_calculateRowHeightIndex);
22
23 var _mapDataUsingRowHeightIndex = require('./mapDataUsingRowHeightIndex');
24
25 var _mapDataUsingRowHeightIndex2 = _interopRequireDefault(_mapDataUsingRowHeightIndex);
26
27 var _alignTableData = require('./alignTableData');
28
29 var _alignTableData2 = _interopRequireDefault(_alignTableData);
30
31 var _padTableData = require('./padTableData');
32
33 var _padTableData2 = _interopRequireDefault(_padTableData);
34
35 var _validateTableData = require('./validateTableData');
36
37 var _validateTableData2 = _interopRequireDefault(_validateTableData);
38
39 var _stringifyTableData = require('./stringifyTableData');
40
41 var _stringifyTableData2 = _interopRequireDefault(_stringifyTableData);
42
43 var _truncateTableData = require('./truncateTableData');
44
45 var _truncateTableData2 = _interopRequireDefault(_truncateTableData);
46
47 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
48
49 /**
50  * @typedef {string} table~cell
51  */
52
53 /**
54  * @typedef {table~cell[]} table~row
55  */
56
57 /**
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).
64  */
65
66 /**
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
83  */
84
85 /**
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.
89  *
90  * @typedef {Function} drawHorizontalLine
91  * @param {number} index
92  * @param {number} size
93  * @returns {boolean}
94  */
95
96 /**
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
102  */
103
104 /**
105  * Generates a text table.
106  *
107  * @param {table~row[]} data
108  * @param {table~config} userConfig
109  * @returns {string}
110  */
111 exports.default = function (data) {
112   let userConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
113
114   let rows;
115
116   (0, _validateTableData2.default)(data);
117
118   rows = (0, _stringifyTableData2.default)(data);
119
120   const config = (0, _makeConfig2.default)(rows, userConfig);
121
122   rows = (0, _truncateTableData2.default)(data, config);
123
124   const rowHeightIndex = (0, _calculateRowHeightIndex2.default)(rows, config);
125
126   rows = (0, _mapDataUsingRowHeightIndex2.default)(rows, rowHeightIndex, config);
127   rows = (0, _alignTableData2.default)(rows, config);
128   rows = (0, _padTableData2.default)(rows, config);
129
130   const cellWidthIndex = (0, _calculateCellWidthIndex2.default)(rows[0]);
131
132   return (0, _drawTable2.default)(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine);
133 };