Comparing version 6.5.0 to 6.5.1
import type { TableConfig, Row } from './types/internal'; | ||
declare const _default: (rows: Row[], columnSizeIndex: number[], rowSpanIndex: number[], config: TableConfig) => string; | ||
declare const _default: (rows: Row[], columnWidths: number[], rowHeights: number[], config: TableConfig) => string; | ||
export default _default; |
@@ -8,31 +8,42 @@ "use strict"; | ||
const drawRow_1 = __importDefault(require("./drawRow")); | ||
exports.default = (rows, columnSizeIndex, rowSpanIndex, config) => { | ||
const { drawHorizontalLine, singleLine, } = config; | ||
let output; | ||
let realRowIndex; | ||
let rowHeight; | ||
const rowCount = rows.length; | ||
realRowIndex = 0; | ||
output = ''; | ||
if (drawHorizontalLine(realRowIndex, rowCount)) { | ||
output += drawBorder_1.drawBorderTop(columnSizeIndex, config); | ||
/** | ||
* Group the array into sub-arrays by sizes. | ||
* | ||
* @example | ||
* chunkBySizes(['a', 'b', 'c', 'd', 'e'], [2, 1, 2]) = [ ['a', 'b'], ['c'], ['d', 'e'] ] | ||
*/ | ||
const groupBySizes = (array, sizes) => { | ||
let startIndex = 0; | ||
return sizes.map((rowHeight) => { | ||
const chunk = array.slice(startIndex, startIndex + rowHeight); | ||
startIndex += rowHeight; | ||
return chunk; | ||
}); | ||
}; | ||
const shouldDrawBorderJoin = (rowIndex, rowCount, config) => { | ||
const { singleLine, drawHorizontalLine } = config; | ||
return !singleLine && rowIndex + 1 < rowCount && drawHorizontalLine(rowIndex + 1, rowCount); | ||
}; | ||
exports.default = (rows, columnWidths, rowHeights, config) => { | ||
const { drawHorizontalLine, } = config; | ||
const groupedRows = groupBySizes(rows, rowHeights).map((group) => { | ||
return group.map((row) => { | ||
return drawRow_1.default(row, config); | ||
}).join(''); | ||
}); | ||
const rowCount = groupedRows.length; | ||
let output = ''; | ||
if (drawHorizontalLine(0, rowCount)) { | ||
output += drawBorder_1.drawBorderTop(columnWidths, config); | ||
} | ||
rows.forEach((row, index0) => { | ||
output += drawRow_1.default(row, config); | ||
if (!rowHeight) { | ||
rowHeight = rowSpanIndex[realRowIndex]; | ||
realRowIndex++; | ||
groupedRows.forEach((row, rowIndex) => { | ||
output += row; | ||
if (shouldDrawBorderJoin(rowIndex, rowCount, config)) { | ||
output += drawBorder_1.drawBorderJoin(columnWidths, config); | ||
} | ||
rowHeight--; | ||
if (!singleLine && | ||
rowHeight === 0 && | ||
index0 !== rowCount - 1 && | ||
drawHorizontalLine(realRowIndex, rowCount)) { | ||
output += drawBorder_1.drawBorderJoin(columnSizeIndex, config); | ||
} | ||
}); | ||
if (drawHorizontalLine(realRowIndex, rowCount)) { | ||
output += drawBorder_1.drawBorderBottom(columnSizeIndex, config); | ||
if (drawHorizontalLine(rowCount, rowCount)) { | ||
output += drawBorder_1.drawBorderBottom(columnWidths, config); | ||
} | ||
return output; | ||
}; |
@@ -94,3 +94,3 @@ { | ||
}, | ||
"version": "6.5.0" | ||
"version": "6.5.1" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126234
2906