markdown-table-prettify
Version:
Transforms markdown tables to be more readable.
61 lines (60 loc) • 2.41 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Table = void 0;
var Table = /** @class */ (function () {
function Table(rows, _separatorEOL, _alignments, leftPad) {
if (leftPad === void 0) { leftPad = ""; }
this._separatorEOL = _separatorEOL;
this._alignments = _alignments;
this.leftPad = leftPad;
this.hasLeftBorder = false;
this.hasRightBorder = false;
if (rows != null && rows[0] != null && rows[0].cells.length != _alignments.length)
throw new Error("The number of columns must match the number of alignments.");
this._rows = rows;
}
Object.defineProperty(Table.prototype, "rows", {
get: function () { return this._rows; },
enumerable: false,
configurable: true
});
Object.defineProperty(Table.prototype, "alignments", {
get: function () { return this._alignments; },
enumerable: false,
configurable: true
});
Object.defineProperty(Table.prototype, "columnCount", {
get: function () { return this.hasRows ? this.rows[0].cells.length : 0; },
enumerable: false,
configurable: true
});
Object.defineProperty(Table.prototype, "rowCount", {
get: function () { return this.hasRows ? this.rows.length : 0; },
enumerable: false,
configurable: true
});
Object.defineProperty(Table.prototype, "separatorEOL", {
get: function () { return this._separatorEOL; },
enumerable: false,
configurable: true
});
Object.defineProperty(Table.prototype, "hasRows", {
get: function () { return this.rows != null && this.rows.length > 0; },
enumerable: false,
configurable: true
});
Table.prototype.isEmpty = function () {
return !this.hasRows;
};
Table.prototype.getLongestColumnLengths = function () {
if (!this.hasRows)
return [];
var maxColLengths = new Array(this.columnCount).fill(0);
for (var row = 0; row < this.rows.length; row++)
for (var col = 0; col < this.rows[row].cells.length; col++)
maxColLengths[col] = Math.max(this.rows[row].cells[col].getLength(), maxColLengths[col]);
return maxColLengths;
};
return Table;
}());
exports.Table = Table;