diff options
author | Ricardo Cino <ricardo@cino.io> | 2022-11-28 16:53:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-28 15:53:04 +0000 |
commit | d5d685aaf4e796faf612c6d0fea0f0cc9ea49614 (patch) | |
tree | 72f027dc2d57f00c366d61570fd76ed6a0fcb27a /src/jsUtils.ts | |
parent | 6.2.1-nightly.52 [skip ci] (diff) | |
download | ferdium-app-d5d685aaf4e796faf612c6d0fea0f0cc9ea49614.tar.gz ferdium-app-d5d685aaf4e796faf612c6d0fea0f0cc9ea49614.tar.zst ferdium-app-d5d685aaf4e796faf612c6d0fea0f0cc9ea49614.zip |
fix: ensure default values are working for the all fields in all settings screens (#750)
Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'src/jsUtils.ts')
-rw-r--r-- | src/jsUtils.ts | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/src/jsUtils.ts b/src/jsUtils.ts index ba7542eab..b93d6db5b 100644 --- a/src/jsUtils.ts +++ b/src/jsUtils.ts | |||
@@ -1,19 +1,7 @@ | |||
1 | // TODO: ifUndefinedString can be removed after ./src/webview/recipe.js is converted to typescript. | ||
2 | export const ifUndefinedString = ( | ||
3 | source: string | undefined | null, | ||
4 | defaultValue: string, | ||
5 | ): string => (source !== undefined && source !== null ? source : defaultValue); | ||
6 | |||
7 | export const ifUndefined = <T>( | 1 | export const ifUndefined = <T>( |
8 | source: undefined | null | T, | 2 | source: undefined | null | T, |
9 | defaultValue: T, | 3 | defaultValue: T, |
10 | ): T => { | 4 | ): T => (source !== undefined && source !== null ? source : defaultValue); |
11 | if (source !== undefined && source !== null) { | ||
12 | return source; | ||
13 | } | ||
14 | |||
15 | return defaultValue; | ||
16 | }; | ||
17 | 5 | ||
18 | export const convertToJSON = (data: string | any | undefined | null) => | 6 | export const convertToJSON = (data: string | any | undefined | null) => |
19 | data && typeof data === 'string' && data.length > 0 ? JSON.parse(data) : data; | 7 | data && typeof data === 'string' && data.length > 0 ? JSON.parse(data) : data; |