@graphql-hive/cli
Version:
A CLI util to manage and control your GraphQL Hive
28 lines • 1.09 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.table = void 0;
const table = (data) => {
const printedTable = mapTableCells(data, 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 = mapTableCells(printedTable, (cell, _, c) => cell.padEnd(columnWidths[c] + 2));
return paddedTable.map(row => `${row.join('')}\n`).join(divider);
};
exports.table = table;
const printCell = (cell) => {
if (cell instanceof Date) {
return cell.toISOString();
}
return String(cell);
};
const mapTableCells = (data, cellMapper) => {
return data.map((row, rowIndex) => row.map((cell, colIndex) => cellMapper(cell, rowIndex, colIndex)));
};
//# sourceMappingURL=table.js.map
;