diff options
author | Chocobozzz <me@florianbigard.com> | 2022-05-31 08:59:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-05-31 10:39:56 +0200 |
commit | f1a0f3b701e005a9533f09b7913c615376e42f32 (patch) | |
tree | 807e5377635bfa30d42ce42bdcd88ff7b1553257 /client/src/root-helpers | |
parent | e5a781ec25191c0dbb4a991f25307732d798619d (diff) | |
download | PeerTube-f1a0f3b701e005a9533f09b7913c615376e42f32.tar.gz PeerTube-f1a0f3b701e005a9533f09b7913c615376e42f32.tar.zst PeerTube-f1a0f3b701e005a9533f09b7913c615376e42f32.zip |
Refactor embed
Diffstat (limited to 'client/src/root-helpers')
-rw-r--r-- | client/src/root-helpers/index.ts | 1 | ||||
-rw-r--r-- | client/src/root-helpers/url.ts | 26 | ||||
-rw-r--r-- | client/src/root-helpers/utils.ts | 10 |
3 files changed, 27 insertions, 10 deletions
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' | |||
5 | export * from './peertube-web-storage' | 5 | export * from './peertube-web-storage' |
6 | export * from './plugins-manager' | 6 | export * from './plugins-manager' |
7 | export * from './string' | 7 | export * from './string' |
8 | export * from './url' | ||
8 | export * from './utils' | 9 | export * from './utils' |
9 | export * from './video' | 10 | 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 @@ | |||
1 | function 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 | |||
7 | function getParamString (params: URLSearchParams, name: string, defaultValue?: string) { | ||
8 | return params.has(name) | ||
9 | ? params.get(name) | ||
10 | : defaultValue | ||
11 | } | ||
12 | |||
13 | function 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 | |||
22 | export { | ||
23 | getParamToggle, | ||
24 | getParamString, | ||
25 | objectToUrlEncoded | ||
26 | } | ||
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 @@ | |||
1 | function objectToUrlEncoded (obj: any) { | ||
2 | const str: string[] = [] | ||
3 | for (const key of Object.keys(obj)) { | ||
4 | str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])) | ||
5 | } | ||
6 | |||
7 | return str.join('&') | ||
8 | } | ||
9 | |||
10 | function copyToClipboard (text: string) { | 1 | function copyToClipboard (text: string) { |
11 | const el = document.createElement('textarea') | 2 | const el = document.createElement('textarea') |
12 | el.value = text | 3 | el.value = text |
@@ -27,6 +18,5 @@ function wait (ms: number) { | |||
27 | 18 | ||
28 | export { | 19 | export { |
29 | copyToClipboard, | 20 | copyToClipboard, |
30 | objectToUrlEncoded, | ||
31 | wait | 21 | wait |
32 | } | 22 | } |