.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / node_modules / table / dist / calculateMaximumColumnWidthIndex.js
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4   value: true
5 });
6
7 var _calculateCellWidthIndex = require('./calculateCellWidthIndex');
8
9 var _calculateCellWidthIndex2 = _interopRequireDefault(_calculateCellWidthIndex);
10
11 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13 /**
14  * Produces an array of values that describe the largest value length (width) in every column.
15  *
16  * @param {Array[]} rows
17  * @returns {number[]}
18  */
19 exports.default = rows => {
20   if (!rows[0]) {
21     throw new Error('Dataset must have at least one row.');
22   }
23
24   const columns = Array(rows[0].length).fill(0);
25
26   rows.forEach(row => {
27     const columnWidthIndex = (0, _calculateCellWidthIndex2.default)(row);
28
29     columnWidthIndex.forEach((valueWidth, index0) => {
30       if (columns[index0] < valueWidth) {
31         columns[index0] = valueWidth;
32       }
33     });
34   });
35
36   return columns;
37 };