UNPKG

dev-lamp

Version:

Your friendly lighthouse performance companion - 100% local

113 lines 4.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextFormatter = void 0; const base_formatter_1 = require("../base.formatter"); class TextFormatter extends base_formatter_1.BaseFormatter { async format(report, _options) { const lines = []; const separator = '='.repeat(60); const subSeparator = '-'.repeat(60); // Header lines.push('LIGHTHOUSE PERFORMANCE REPORT'); lines.push(separator); lines.push(`URL: ${report.metadata.url}`); lines.push(`Date: ${report.metadata.timestamp}`); lines.push(`Device: ${report.metadata.device || 'desktop'}`); lines.push(''); // Overall Score if (report.scores.performance !== undefined) { lines.push('PERFORMANCE SCORE'); lines.push(subSeparator); lines.push(`${report.scores.performance}/100 ${this.getScoreIndicator(report.scores.performance)}`); lines.push(''); } // All Category Scores const categories = Object.entries(report.scores).filter(([key]) => key !== 'performance'); if (categories.length > 0) { lines.push('OTHER CATEGORIES'); lines.push(subSeparator); for (const [category, score] of categories) { if (score !== undefined) { lines.push(`${this.formatCategoryName(category)}: ${score}/100 ${this.getScoreIndicator(score)}`); } } lines.push(''); } // Core Web Vitals if (report.metrics.lcp || report.metrics.fid || report.metrics.cls) { lines.push('CORE WEB VITALS'); lines.push(subSeparator); if (report.metrics.lcp) { lines.push(`LCP: ${report.metrics.lcp.displayValue} ${this.getScoreIndicator(report.metrics.lcp.score)}`); } if (report.metrics.fid) { lines.push(`FID: ${report.metrics.fid.displayValue} ${this.getScoreIndicator(report.metrics.fid.score)}`); } if (report.metrics.cls) { lines.push(`CLS: ${report.metrics.cls.displayValue} ${this.getScoreIndicator(report.metrics.cls.score)}`); } lines.push(''); } // Other Metrics const otherMetrics = ['fcp', 'ttfb', 'speedIndex', 'totalBlockingTime']; const hasOtherMetrics = otherMetrics.some(m => report.metrics[m]); if (hasOtherMetrics) { lines.push('OTHER METRICS'); lines.push(subSeparator); for (const metricKey of otherMetrics) { const metric = report.metrics[metricKey]; if (metric) { lines.push(`${metric.title || metricKey}: ${metric.displayValue}`); } } lines.push(''); } // Opportunities if (report.opportunities && report.opportunities.length > 0) { lines.push('OPPORTUNITIES FOR IMPROVEMENT'); lines.push(subSeparator); report.opportunities.forEach(opp => { lines.push(`* ${opp.title}`); if (opp.displayValue) { lines.push(` Savings: ${opp.displayValue}`); } }); lines.push(''); } // Diagnostics if (report.diagnostics && report.diagnostics.length > 0) { lines.push('DIAGNOSTICS'); lines.push(subSeparator); report.diagnostics.forEach(diag => { lines.push(`* ${diag.title}`); if (diag.displayValue) { lines.push(` Value: ${diag.displayValue}`); } }); lines.push(''); } // Footer lines.push(separator); lines.push('Generated by dev-lamp (100% local processing)'); return lines.join('\n'); } getScoreIndicator(score) { if (score >= 90) return '[GOOD]'; if (score >= 50) return '[NEEDS IMPROVEMENT]'; return '[POOR]'; } formatCategoryName(category) { const names = { performance: 'Performance', accessibility: 'Accessibility', bestPractices: 'Best Practices', seo: 'SEO', pwa: 'PWA' }; return names[category] || category; } } exports.TextFormatter = TextFormatter; //# sourceMappingURL=text.formatter.js.map