markdown-table-prettify
Version:
Transforms markdown tables to be more readable.
58 lines (57 loc) • 2.61 kB
JavaScript
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableViewModelFactory = void 0;
var tableViewModel_1 = require("../viewModels/tableViewModel");
var TableViewModelFactory = /** @class */ (function () {
function TableViewModelFactory(_rowViewModelFactory) {
this._rowViewModelFactory = _rowViewModelFactory;
}
TableViewModelFactory.prototype.build = function (tableWithoutSeparator) {
var result = new tableViewModel_1.TableViewModel();
result.leftPad = tableWithoutSeparator.leftPad;
result.hasLeftBorder = tableWithoutSeparator.hasLeftBorder;
result.hasRightBorder = tableWithoutSeparator.hasRightBorder;
result.header = this._rowViewModelFactory.buildRow(0, tableWithoutSeparator);
result.rows = this.buildRows(tableWithoutSeparator);
result.separator = this.buildSeparator(result, tableWithoutSeparator);
return result;
};
TableViewModelFactory.prototype.buildRows = function (table) {
var result = new Array(table.rowCount - 1);
for (var row = 1; row < table.rowCount; row++)
result[row - 1] = this._rowViewModelFactory.buildRow(row, table);
return result;
};
TableViewModelFactory.prototype.buildSeparator = function (tableVm, table) {
var e_1, _a;
var rowsForSeparatorCalculation = new Array();
rowsForSeparatorCalculation.push(tableVm.header);
try {
for (var _b = __values(tableVm.rows), _c = _b.next(); !_c.done; _c = _b.next()) {
var r = _c.value;
rowsForSeparatorCalculation.push(r);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return this._rowViewModelFactory.buildSeparator(rowsForSeparatorCalculation, table);
};
return TableViewModelFactory;
}());
exports.TableViewModelFactory = TableViewModelFactory;
;