aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/root-helpers/url.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/root-helpers/url.ts')
-rw-r--r--client/src/root-helpers/url.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/client/src/root-helpers/url.ts b/client/src/root-helpers/url.ts
new file mode 100644
index 000000000..b2f0c8b85
--- /dev/null
+++ b/client/src/root-helpers/url.ts
@@ -0,0 +1,26 @@
1function getParamToggle (params: URLSearchParams, name: string, defaultValue?: boolean) {
2 return params.has(name)
3 ? (params.get(name) === '1' || params.get(name) === 'true')
4 : defaultValue
5}
6
7function getParamString (params: URLSearchParams, name: string, defaultValue?: string) {
8 return params.has(name)
9 ? params.get(name)
10 : defaultValue
11}
12
13function objectToUrlEncoded (obj: any) {
14 const str: string[] = []
15 for (const key of Object.keys(obj)) {
16 str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]))
17 }
18
19 return str.join('&')
20}
21
22export {
23 getParamToggle,
24 getParamString,
25 objectToUrlEncoded
26}