@philiprehberger/web-vitals
v0.1.1
Published
Web Vitals calculation utilities and client error capture
Readme
@philiprehberger/web-vitals
Web Vitals calculation utilities and client error capture.
Installation
npm install @philiprehberger/web-vitalsUsage
import { getWebVitalRating, calculateWebVitalStats, formatWebVitalValue } from '@philiprehberger/web-vitals';
const rating = getWebVitalRating('LCP', 2100); // 'good'
const stats = calculateWebVitalStats('LCP', [1200, 2500, 3800, 1800]);
console.log(formatWebVitalValue('LCP', stats.p75)); // '2.5s'Client Error Capture
import { initClientErrorCapture } from '@philiprehberger/web-vitals';
initClientErrorCapture({
endpoint: '/api/monitoring/errors',
});Features
- Web Vitals thresholds based on Google's recommendations (LCP, CLS, FID, INP, FCP, TTFB)
- Rating calculation (good / needs-improvement / poor)
- Percentile calculation (p50, p75, p95)
- Value formatting for display
- Page path normalization (replaces dynamic IDs)
- Client-side error capture (unhandled errors + promise rejections)
License
MIT
