@grafana/faro-web-sdk
Version:
Faro instrumentations, metas, transports for web.
36 lines • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertDataAttributeName = convertDataAttributeName;
exports.startTimeout = startTimeout;
exports.isRequestStartMessage = isRequestStartMessage;
exports.isRequestEndMessage = isRequestEndMessage;
const const_1 = require("./const");
/**
* Parses the action attribute name by removing the 'data-' prefix and converting
* the remaining string to camelCase.
*
* This is needed because the browser will remove the 'data-' prefix and the dashes from
* data attributes and make then camelCase.
*/
function convertDataAttributeName(userActionDataAttribute) {
const withoutData = userActionDataAttribute.split('data-')[1];
const withUpperCase = withoutData === null || withoutData === void 0 ? void 0 : withoutData.replace(/-(.)/g, (_, char) => char.toUpperCase());
return withUpperCase === null || withUpperCase === void 0 ? void 0 : withUpperCase.replace(/-/g, '');
}
function startTimeout(timeoutId, cb, delay) {
if (timeoutId) {
clearTimeout(timeoutId);
}
//@ts-expect-error for some reason vscode is using the node types
timeoutId = setTimeout(() => {
cb();
}, delay);
return timeoutId;
}
function isRequestStartMessage(msg) {
return msg.type === const_1.MESSAGE_TYPE_HTTP_REQUEST_START;
}
function isRequestEndMessage(msg) {
return msg.type === const_1.MESSAGE_TYPE_HTTP_REQUEST_END;
}
//# sourceMappingURL=util.js.map