Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
99 lines
4.6 KiB
Plaintext
99 lines
4.6 KiB
Plaintext
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const colored_console_line_1 = require("../utils/colored-console-line");
|
|
const table_constants_1 = require("../utils/table-constants");
|
|
const table_helpers_1 = require("../utils/table-helpers");
|
|
const input_converter_1 = require("./input-converter");
|
|
const internal_table_printer_1 = require("./internal-table-printer");
|
|
const DEFAULT_ROW_SORT_FUNC = () => 0;
|
|
const DEFAULT_ROW_FILTER_FUNC = () => true;
|
|
class TableInternal {
|
|
initSimple(columns) {
|
|
this.columns = columns.map((column) => ({
|
|
name: column,
|
|
title: column,
|
|
alignment: table_constants_1.DEFAULT_ROW_ALIGNMENT,
|
|
}));
|
|
}
|
|
initDetailed(options) {
|
|
var _a;
|
|
this.title = (options === null || options === void 0 ? void 0 : options.title) || this.title;
|
|
this.tableStyle = (options === null || options === void 0 ? void 0 : options.style) || this.tableStyle;
|
|
this.sortFunction = (options === null || options === void 0 ? void 0 : options.sort) || this.sortFunction;
|
|
this.filterFunction = (options === null || options === void 0 ? void 0 : options.filter) || this.filterFunction;
|
|
this.enabledColumns = (options === null || options === void 0 ? void 0 : options.enabledColumns) || this.enabledColumns;
|
|
this.disabledColumns = (options === null || options === void 0 ? void 0 : options.disabledColumns) || this.disabledColumns;
|
|
this.computedColumns = (options === null || options === void 0 ? void 0 : options.computedColumns) || this.computedColumns;
|
|
this.columns =
|
|
((_a = options === null || options === void 0 ? void 0 : options.columns) === null || _a === void 0 ? void 0 : _a.map(input_converter_1.rawColumnToInternalColumn)) || this.columns;
|
|
this.rowSeparator = (options === null || options === void 0 ? void 0 : options.rowSeparator) || this.rowSeparator;
|
|
this.charLength = (options === null || options === void 0 ? void 0 : options.charLength) || this.charLength;
|
|
if (options === null || options === void 0 ? void 0 : options.shouldDisableColors) {
|
|
this.colorMap = {};
|
|
}
|
|
else if (options === null || options === void 0 ? void 0 : options.colorMap) {
|
|
this.colorMap = Object.assign(Object.assign({}, this.colorMap), options.colorMap);
|
|
}
|
|
if (options.rows !== undefined) {
|
|
this.addRows(options.rows);
|
|
}
|
|
}
|
|
constructor(options) {
|
|
// default construction
|
|
this.rows = [];
|
|
this.columns = [];
|
|
this.title = undefined;
|
|
this.tableStyle = table_constants_1.DEFAULT_TABLE_STYLE;
|
|
this.filterFunction = DEFAULT_ROW_FILTER_FUNC;
|
|
this.sortFunction = DEFAULT_ROW_SORT_FUNC;
|
|
this.enabledColumns = [];
|
|
this.disabledColumns = [];
|
|
this.computedColumns = [];
|
|
this.rowSeparator = table_constants_1.DEFAULT_ROW_SEPARATOR;
|
|
this.colorMap = colored_console_line_1.DEFAULT_COLOR_MAP;
|
|
this.charLength = {};
|
|
if (options instanceof Array) {
|
|
this.initSimple(options);
|
|
}
|
|
else if (typeof options === 'object') {
|
|
this.initDetailed(options);
|
|
}
|
|
}
|
|
createColumnFromRow(text) {
|
|
const colNames = this.columns.map((col) => col.name);
|
|
Object.keys(text).forEach((key) => {
|
|
if (!colNames.includes(key)) {
|
|
this.columns.push((0, table_helpers_1.createColumFromOnlyName)(key));
|
|
}
|
|
});
|
|
}
|
|
addColumn(textOrObj) {
|
|
if (typeof textOrObj === 'string') {
|
|
this.columns.push((0, table_helpers_1.createColumFromOnlyName)(textOrObj));
|
|
}
|
|
else {
|
|
this.columns.push((0, table_helpers_1.createColumFromComputedColumn)(textOrObj));
|
|
}
|
|
}
|
|
addColumns(toBeInsertedColumns) {
|
|
toBeInsertedColumns.forEach((toBeInsertedColumn) => {
|
|
this.addColumn(toBeInsertedColumn);
|
|
});
|
|
}
|
|
addRow(text, options) {
|
|
this.createColumnFromRow(text);
|
|
this.rows.push((0, table_helpers_1.createRow)((options === null || options === void 0 ? void 0 : options.color) || table_constants_1.DEFAULT_ROW_FONT_COLOR, text, (options === null || options === void 0 ? void 0 : options.separator) !== undefined
|
|
? options === null || options === void 0 ? void 0 : options.separator
|
|
: this.rowSeparator));
|
|
}
|
|
addRows(toBeInsertedRows, options) {
|
|
toBeInsertedRows.forEach((toBeInsertedRow) => {
|
|
this.addRow(toBeInsertedRow, options);
|
|
});
|
|
}
|
|
renderTable() {
|
|
return (0, internal_table_printer_1.renderTable)(this);
|
|
}
|
|
}
|
|
exports.default = TableInternal;
|