@graphql-hive/cli
Version:
A CLI util to manage and control your GraphQL Hive
27 lines • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.printTable = printTable;
function printCell(cell) {
if (cell instanceof Date) {
return cell.toISOString();
}
return String(cell);
}
function mapTable(table, map) {
return table.map((row, r) => row.map((cell, c) => map(cell, r, c)));
}
function printTable(table) {
const printedTable = mapTable(table, printCell);
const columnWidths = [];
for (let row of printedTable) {
for (let i = 0; i < row.length; i++) {
const cell = row[i];
columnWidths[i] = Math.max(columnWidths[i] || 0, cell.length);
}
}
const totalWidth = columnWidths.reduce((acc, n) => acc + n, 0) + (columnWidths.length - 1) * 2;
const divider = `${'-'.repeat(totalWidth)}\n`;
const paddedTable = mapTable(printedTable, (cell, r, c) => cell.padEnd(columnWidths[c] + 2));
return paddedTable.map(row => `${row.join('')}\n`).join(divider);
}
//# sourceMappingURL=print-table.js.map