UNPKG

gcal-commander

Version:

A command-line interface for Google Calendar operations

48 lines (47 loc) 1.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TableFormatter = void 0; const cli_table3_1 = __importDefault(require("cli-table3")); class TableFormatter { columns; filteredColumns; constructor(options) { this.columns = options.columns; this.filteredColumns = this.filterColumns(options.fields); } format(data) { if (data.length === 0) { return ''; } const table = new cli_table3_1.default({ head: this.filteredColumns.map((col) => col.label), colAligns: this.filteredColumns.map((col) => col.align || 'left'), colWidths: this.filteredColumns.map((col) => col.width || null), style: { head: ['cyan'], border: ['grey'], }, }); for (const row of data) { const tableRow = this.filteredColumns.map((col) => { const value = row[col.key]; return value !== undefined && value !== null ? String(value) : ''; }); table.push(tableRow); } return table.toString(); } getAvailableFields() { return this.columns.map((col) => col.key); } filterColumns(fields) { if (!fields) { return this.columns; } return this.columns.filter((column) => fields.includes(column.key)); } } exports.TableFormatter = TableFormatter;