@grafana/faro-web-sdk
Version:
Faro instrumentations, metas, transports for web.
30 lines • 1.25 kB
JavaScript
import { MESSAGE_TYPE_HTTP_REQUEST_END, MESSAGE_TYPE_HTTP_REQUEST_START } from './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.
*/
export 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, '');
}
export 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;
}
export function isRequestStartMessage(msg) {
return msg.type === MESSAGE_TYPE_HTTP_REQUEST_START;
}
export function isRequestEndMessage(msg) {
return msg.type === MESSAGE_TYPE_HTTP_REQUEST_END;
}
//# sourceMappingURL=util.js.map