UNPKG

navy

Version:

Quick and powerful development environments using Docker and Docker Compose

26 lines (19 loc) 768 B
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = table; var _pad = _interopRequireDefault(require("pad")); var _stripAnsi = _interopRequireDefault(require("strip-ansi")); function table(rows) { if (rows.length === 0) { return ''; } const cols = rows[0]; const colSizes = cols.map((col, colIndex) => rows.reduce((currentSize, row) => currentSize = Math.max(currentSize, (0, _stripAnsi.default)(row[colIndex] || '').length), 0) + 2); return rows.map(row => row.map((col, colIndex) => (0, _pad.default)(col || '', colSizes[colIndex], { colors: true })).join('')).join('\n'); } module.exports = exports.default;