You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

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