UNPKG

markdown-table-prettify

Version:

Transforms markdown tables to be more readable.

62 lines (61 loc) 2.83 kB
"use strict"; 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.RowViewModelFactory = void 0; var rowViewModel_1 = require("../viewModels/rowViewModel"); var RowViewModelFactory = /** @class */ (function () { function RowViewModelFactory(_contentPadCalculator, _alignmentMarkerStrategy) { this._contentPadCalculator = _contentPadCalculator; this._alignmentMarkerStrategy = _alignmentMarkerStrategy; this.separatorChar = "-"; } RowViewModelFactory.prototype.buildRow = function (row, table) { if (table == null) throw new Error("Paramter can't be null"); var resultRow = new Array(table.columnCount); for (var col = 0; col < table.columnCount; col++) { resultRow[col] = this._contentPadCalculator.getLeftPadding(table, row, col) + table.rows[row].cells[col].getValue() + this._contentPadCalculator.getRightPadding(table, row, col); } return new rowViewModel_1.RowViewModel(resultRow, table.rows[row].EOL); }; RowViewModelFactory.prototype.buildSeparator = function (rows, table) { var e_1, _a; var _this = this; var columnCount = rows[0].columnCount; var lengths = Array(columnCount).fill(0); try { for (var rows_1 = __values(rows), rows_1_1 = rows_1.next(); !rows_1_1.done; rows_1_1 = rows_1.next()) { var row = rows_1_1.value; for (var i = 0; i < columnCount; i++) { lengths[i] = Math.max(lengths[i], (row.getValueAt(i).length)); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (rows_1_1 && !rows_1_1.done && (_a = rows_1.return)) _a.call(rows_1); } finally { if (e_1) throw e_1.error; } } var values = lengths .map(function (l) { return _this.separatorChar.repeat(l); }) .map(function (val, col) { return _this._alignmentMarkerStrategy.markerFor(table.alignments[col]).mark(val); }); return new rowViewModel_1.RowViewModel(values, table.separatorEOL); }; return RowViewModelFactory; }()); exports.RowViewModelFactory = RowViewModelFactory;