@grafana/faro-web-sdk
Version:
Faro instrumentations, metas, transports for web.
36 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertDataAttributeName = convertDataAttributeName;
exports.startTimeout = startTimeout;
exports.isRequestStartMessage = isRequestStartMessage;
exports.isRequestEndMessage = isRequestEndMessage;
var 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) {
var withoutData = userActionDataAttribute.split('data-')[1];
var withUpperCase = withoutData === null || withoutData === void 0 ? void 0 : withoutData.replace(/-(.)/g, function (_, char) { return 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(function () {
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