This repository has been archived on 2022-01-16. You can view files and clone it, but cannot push or open issues or pull requests.
irreligious/node_modules/table/dist/drawHeader.js

30 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-09-04 22:21:14 -05:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawHeader = void 0;
const alignString_1 = require("./alignString");
const drawRow_1 = require("./drawRow");
const padTableData_1 = require("./padTableData");
const truncateTableData_1 = require("./truncateTableData");
const wrapCell_1 = require("./wrapCell");
const drawHeader = (width, config) => {
if (!config.header) {
throw new Error('Can not draw header without header configuration');
}
const { alignment, paddingRight, paddingLeft, wrapWord } = config.header;
let content = config.header.content;
content = truncateTableData_1.truncateString(content, config.header.truncate);
const headerLines = wrapCell_1.wrapCell(content, width, wrapWord);
return headerLines.map((headerLine) => {
let line = alignString_1.alignString(headerLine, width, alignment);
line = padTableData_1.padString(line, paddingLeft, paddingRight);
return drawRow_1.drawRow([line], {
...config,
drawVerticalLine: (index) => {
const columnCount = config.columns.length;
return config.drawVerticalLine(index === 0 ? 0 : columnCount, columnCount);
},
});
}).join('');
};
exports.drawHeader = drawHeader;