diff options
author | Ricardo Cino <ricardo@cino.io> | 2022-06-23 18:10:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-23 16:10:39 +0000 |
commit | 6b2c2b8dfb86245a1747bf7977159f5129461863 (patch) | |
tree | 28944f62a962d8a658262ea902f8554d4419fa9e /src/jsUtils.ts | |
parent | chore: featureStore and GlobalErrorStore JS => TS (diff) | |
download | ferdium-app-6b2c2b8dfb86245a1747bf7977159f5129461863.tar.gz ferdium-app-6b2c2b8dfb86245a1747bf7977159f5129461863.tar.zst ferdium-app-6b2c2b8dfb86245a1747bf7977159f5129461863.zip |
chore: servicesStore + models into typescript (#344)
Diffstat (limited to 'src/jsUtils.ts')
-rw-r--r-- | src/jsUtils.ts | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/jsUtils.ts b/src/jsUtils.ts index 250d595eb..f5b39a000 100644 --- a/src/jsUtils.ts +++ b/src/jsUtils.ts | |||
@@ -1,9 +1,22 @@ | |||
1 | export const ifUndefinedString = (source: string | undefined | null, defaultValue: string): string => (source !== undefined && source !== null ? source : defaultValue); | 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); | ||
2 | 6 | ||
3 | export const ifUndefinedBoolean = (source: boolean | undefined | null, defaultValue: boolean): boolean => Boolean(source !== undefined && source !== null ? source : defaultValue); | 7 | export const ifUndefined = <T>( |
8 | source: undefined | null | T, | ||
9 | defaultValue: T, | ||
10 | ): T => { | ||
11 | if (source !== undefined && source !== null) { | ||
12 | return source; | ||
13 | } | ||
4 | 14 | ||
5 | export const ifUndefinedNumber = (source: number | undefined | null, defaultValue: number): number => Number(source !== undefined && source !== null ? source : defaultValue); | 15 | return defaultValue; |
16 | }; | ||
6 | 17 | ||
7 | export const convertToJSON = (data: string | any | undefined | null) => data && typeof data === 'string' && data.length > 0 ? JSON.parse(data) : data | 18 | export const convertToJSON = (data: string | any | undefined | null) => |
19 | data && typeof data === 'string' && data.length > 0 ? JSON.parse(data) : data; | ||
8 | 20 | ||
9 | export const cleanseJSObject = (data: any | undefined | null) => JSON.parse(JSON.stringify(data)) | 21 | export const cleanseJSObject = (data: any | undefined | null) => |
22 | JSON.parse(JSON.stringify(data)); | ||