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.

58 lines
1.5 KiB

4 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _drawBorder = require("./drawBorder");
  7. var _drawRow = _interopRequireDefault(require("./drawRow"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /**
  10. * @param {Array} rows
  11. * @param {Object} border
  12. * @param {Array} columnSizeIndex
  13. * @param {Array} rowSpanIndex
  14. * @param {Function} drawHorizontalLine
  15. * @param {boolean} singleLine
  16. * @returns {string}
  17. */
  18. const drawTable = (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine, singleLine) => {
  19. let output;
  20. let realRowIndex;
  21. let rowHeight;
  22. const rowCount = rows.length;
  23. realRowIndex = 0;
  24. output = '';
  25. if (drawHorizontalLine(realRowIndex, rowCount)) {
  26. output += (0, _drawBorder.drawBorderTop)(columnSizeIndex, border);
  27. }
  28. rows.forEach((row, index0) => {
  29. output += (0, _drawRow.default)(row, border);
  30. if (!rowHeight) {
  31. rowHeight = rowSpanIndex[realRowIndex];
  32. realRowIndex++;
  33. }
  34. rowHeight--;
  35. if (!singleLine && rowHeight === 0 && index0 !== rowCount - 1 && drawHorizontalLine(realRowIndex, rowCount)) {
  36. output += (0, _drawBorder.drawBorderJoin)(columnSizeIndex, border);
  37. }
  38. });
  39. if (drawHorizontalLine(realRowIndex, rowCount)) {
  40. output += (0, _drawBorder.drawBorderBottom)(columnSizeIndex, border);
  41. }
  42. return output;
  43. };
  44. var _default = drawTable;
  45. exports.default = _default;
  46. //# sourceMappingURL=drawTable.js.map