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/index.ts | 1 + client/src/root-helpers/url.ts | 26 ++++++++++++++++++++++++++ client/src/root-helpers/utils.ts | 10 ---------- 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 client/src/root-helpers/url.ts (limited to 'client/src/root-helpers') diff --git a/client/src/root-helpers/index.ts b/client/src/root-helpers/index.ts index 0492924fd..a19855761 100644 --- a/client/src/root-helpers/index.ts +++ b/client/src/root-helpers/index.ts @@ -5,5 +5,6 @@ export * from './local-storage-utils' export * from './peertube-web-storage' export * from './plugins-manager' export * from './string' +export * from './url' export * from './utils' export * from './video' 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 +} diff --git a/client/src/root-helpers/utils.ts b/client/src/root-helpers/utils.ts index 00bd92411..af94ed6ca 100644 --- a/client/src/root-helpers/utils.ts +++ b/client/src/root-helpers/utils.ts @@ -1,12 +1,3 @@ -function objectToUrlEncoded (obj: any) { - const str: string[] = [] - for (const key of Object.keys(obj)) { - str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])) - } - - return str.join('&') -} - function copyToClipboard (text: string) { const el = document.createElement('textarea') el.value = text @@ -27,6 +18,5 @@ function wait (ms: number) { export { copyToClipboard, - objectToUrlEncoded, wait } -- cgit v1.2.3