UNPKG

perfrunner-reporters

Version:

Home of the perfrunner reporters

27 lines (26 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNavigationEvent = exports.getRecalculateStyleDuration = exports.getLayoutDuration = exports.getScriptDuration = exports.getDomInteractive = exports.getLCP = exports.getFP = exports.getFCP = void 0; const numbers_1 = require("./numbers"); const getFCP = (performanceEntries) => { var _a, _b; return Math.round((_b = (_a = performanceEntries.find((x) => x.name === 'first-contentful-paint')) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0); }; exports.getFCP = getFCP; const getFP = (performanceEntries) => { var _a, _b; return Math.round((_b = (_a = performanceEntries.find((x) => x.name === 'first-paint')) === null || _a === void 0 ? void 0 : _a.startTime) !== null && _b !== void 0 ? _b : 0); }; exports.getFP = getFP; const getLCP = (performanceEntries) => { const lcpEvent = performanceEntries.find((x) => x.entryType === 'largest-contentful-paint'); return Math.round((lcpEvent === null || lcpEvent === void 0 ? void 0 : lcpEvent.renderTime) || (lcpEvent === null || lcpEvent === void 0 ? void 0 : lcpEvent.loadTime) || 0); }; exports.getLCP = getLCP; const getDomInteractive = (performanceEntries) => { const event = performanceEntries.find((x) => x.entryType === 'navigation'); return Math.round((event === null || event === void 0 ? void 0 : event.domInteractive) || 0); }; exports.getDomInteractive = getDomInteractive; const getScriptDuration = (metric) => Math.round((0, numbers_1.numberOrZero)(metric.ScriptDuration)); exports.getScriptDuration = getScriptDuration; const getLayoutDuration = (metric) => Math.round((0, numbers_1.numberOrZero)(metric.LayoutDuration)); exports.getLayoutDuration = getLayoutDuration; const getRecalculateStyleDuration = (metric) => Math.round((0, numbers_1.numberOrZero)(metric.RecalcStyleDuration)); exports.getRecalculateStyleDuration = getRecalculateStyleDuration; const getNavigationEvent = (performanceEntries) => performanceEntries.find((x) => x.entryType === 'navigation'); exports.getNavigationEvent = getNavigationEvent;