mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 08:07:12 +01:00
Imported libraries, removed next-basics.
This commit is contained in:
parent
31266cb1ac
commit
113022ed17
44 changed files with 361 additions and 180 deletions
40
src/lib/url.ts
Normal file
40
src/lib/url.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
export function getQueryString(params: object = {}): string {
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (value !== undefined) {
|
||||
searchParams.append(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
return searchParams.toString();
|
||||
}
|
||||
|
||||
export function buildUrl(url: string, params: object = {}): string {
|
||||
const queryString = getQueryString(params);
|
||||
return `${url}${queryString && '?' + queryString}`;
|
||||
}
|
||||
|
||||
export function safeDecodeURI(s: string | undefined | null): string | undefined | null {
|
||||
if (s === undefined || s === null) {
|
||||
return s;
|
||||
}
|
||||
|
||||
try {
|
||||
return decodeURI(s);
|
||||
} catch (e) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
export function safeDecodeURIComponent(s: string | undefined | null): string | undefined | null {
|
||||
if (s === undefined || s === null) {
|
||||
return s;
|
||||
}
|
||||
|
||||
try {
|
||||
return decodeURIComponent(s);
|
||||
} catch (e) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue