forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperFunctions.ts
More file actions
35 lines (31 loc) · 1.03 KB
/
Copy pathhelperFunctions.ts
File metadata and controls
35 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export function isElementFullScreen(mediaId: string): boolean {
if (document.fullscreenElement) {
return document.fullscreenElement.id === mediaId;
}
return false;
}
// URLSearchParams is not supported in IE
// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
export function addUrlParam(url: string, key: string, value: string) {
const urlParams = parseUrlParams(url);
urlParams[key] = value;
return `${url}?${urlParamsToString(urlParams)}`;
}
export function parseUrlParams(url: string): Record<string, string> {
const params: Record<string, string> = {};
const urlParams = url.split('?')[1];
if (!urlParams) return params;
urlParams.split('&').forEach((p) => {
const param = p.split('=');
params[param[0]] = param[1];
});
return params;
}
function urlParamsToString(urlParams: Record<string, string>) {
// convert an object of url parameters to a string
let params = '';
Object.keys(urlParams).forEach((p) => {
params += `${p}=${urlParams[p]}&`;
});
return params.slice(0, -1);
}