2019-10-20 16:59:02 +02:00
|
|
|
import queryString from "query-string";
|
2019-04-18 11:42:09 +02:00
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
//@ts-ignore
|
|
|
|
|
export const contextPath = window.ctxPath || "";
|
2018-09-03 16:17:36 +02:00
|
|
|
|
|
|
|
|
export function withContextPath(path: string) {
|
|
|
|
|
return contextPath + path;
|
|
|
|
|
}
|
2018-10-17 17:11:21 +02:00
|
|
|
|
2018-10-18 11:13:14 +02:00
|
|
|
export function withEndingSlash(url: string) {
|
2019-10-20 16:59:02 +02:00
|
|
|
if (url.endsWith("/")) {
|
2018-10-18 11:13:14 +02:00
|
|
|
return url;
|
|
|
|
|
}
|
2019-10-20 16:59:02 +02:00
|
|
|
return url + "/";
|
2018-10-18 11:13:14 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 15:20:30 +02:00
|
|
|
export function concat(base: string, ...parts: string[]) {
|
2018-10-18 11:13:14 +02:00
|
|
|
let url = base;
|
2019-10-19 16:38:07 +02:00
|
|
|
for (let p of parts) {
|
2018-10-18 11:13:14 +02:00
|
|
|
url = withEndingSlash(url) + p;
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 17:11:21 +02:00
|
|
|
export function getPageFromMatch(match: any) {
|
|
|
|
|
let page = parseInt(match.params.page, 10);
|
|
|
|
|
if (isNaN(page) || !page) {
|
|
|
|
|
page = 1;
|
|
|
|
|
}
|
|
|
|
|
return page;
|
|
|
|
|
}
|
2019-04-18 11:42:09 +02:00
|
|
|
|
|
|
|
|
export function getQueryStringFromLocation(location: any) {
|
|
|
|
|
return location.search ? queryString.parse(location.search).q : undefined;
|
|
|
|
|
}
|