From f1a0f3b701e005a9533f09b7913c615376e42f32 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 31 May 2022 08:59:30 +0200 Subject: Refactor embed --- client/src/root-helpers/url.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 client/src/root-helpers/url.ts (limited to 'client/src/root-helpers/url.ts') 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 @@ +function getParamToggle (params: URLSearchParams, name: string, defaultValue?: boolean) { + return params.has(name) + ? (params.get(name) === '1' || params.get(name) === 'true') + : defaultValue +} + +function getParamString (params: URLSearchParams, name: string, defaultValue?: string) { + return params.has(name) + ? params.get(name) + : defaultValue +} + +function objectToUrlEncoded (obj: any) { + const str: string[] = [] + for (const key of Object.keys(obj)) { + str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])) + } + + return str.join('&') +} + +export { + getParamToggle, + getParamString, + objectToUrlEncoded +} -- cgit v1.2.3