drawHeader.js 1.3 KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.drawHeader = void 0;
  4. const alignString_1 = require("./alignString");
  5. const drawRow_1 = require("./drawRow");
  6. const padTableData_1 = require("./padTableData");
  7. const truncateTableData_1 = require("./truncateTableData");
  8. const wrapCell_1 = require("./wrapCell");
  9. const drawHeader = (width, config) => {
  10. if (!config.header) {
  11. throw new Error('Can not draw header without header configuration');
  12. }
  13. const { alignment, paddingRight, paddingLeft, wrapWord } = config.header;
  14. let content = config.header.content;
  15. content = truncateTableData_1.truncateString(content, config.header.truncate);
  16. const headerLines = wrapCell_1.wrapCell(content, width, wrapWord);
  17. return headerLines.map((headerLine) => {
  18. let line = alignString_1.alignString(headerLine, width, alignment);
  19. line = padTableData_1.padString(line, paddingLeft, paddingRight);
  20. return drawRow_1.drawRow([line], {
  21. ...config,
  22. drawVerticalLine: (index) => {
  23. const columnCount = config.columns.length;
  24. return config.drawVerticalLine(index === 0 ? 0 : columnCount, columnCount);
  25. },
  26. });
  27. }).join('');
  28. };
  29. exports.drawHeader = drawHeader;