diff options
author | Vijay A <vraravam@users.noreply.github.com> | 2022-05-15 01:44:18 -0500 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2022-05-15 19:05:55 -0500 |
commit | 082b64b6c40fcab3ecf303f53ce83e7753894a32 (patch) | |
tree | 92626869949cc671effce89cfbcd52092243de5c /src/jsUtils.ts | |
parent | fix: revert "Typescript conversion" (#153) (diff) | |
download | ferdium-app-082b64b6c40fcab3ecf303f53ce83e7753894a32.tar.gz ferdium-app-082b64b6c40fcab3ecf303f53ce83e7753894a32.tar.zst ferdium-app-082b64b6c40fcab3ecf303f53ce83e7753894a32.zip |
Extract utility functions for JSON parsing
Diffstat (limited to 'src/jsUtils.ts')
-rw-r--r-- | src/jsUtils.ts | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/jsUtils.ts b/src/jsUtils.ts index d7ea4eb40..250d595eb 100644 --- a/src/jsUtils.ts +++ b/src/jsUtils.ts | |||
@@ -1,14 +1,9 @@ | |||
1 | export const ifUndefinedString = ( | 1 | export const ifUndefinedString = (source: string | undefined | null, defaultValue: string): string => (source !== undefined && source !== null ? source : defaultValue); |
2 | source: string | undefined | null, | 2 | |
3 | defaultValue: string, | 3 | export const ifUndefinedBoolean = (source: boolean | undefined | null, defaultValue: boolean): boolean => Boolean(source !== undefined && source !== null ? source : defaultValue); |
4 | ): string => (source !== undefined && source !== null ? source : defaultValue); | 4 | |
5 | export const ifUndefinedBoolean = ( | 5 | export const ifUndefinedNumber = (source: number | undefined | null, defaultValue: number): number => Number(source !== undefined && source !== null ? source : defaultValue); |
6 | source: boolean | undefined | null, | 6 | |
7 | defaultValue: boolean, | 7 | export const convertToJSON = (data: string | any | undefined | null) => data && typeof data === 'string' && data.length > 0 ? JSON.parse(data) : data |
8 | ): boolean => | 8 | |
9 | Boolean(source !== undefined && source !== null ? source : defaultValue); | 9 | export const cleanseJSObject = (data: any | undefined | null) => JSON.parse(JSON.stringify(data)) |
10 | export const ifUndefinedNumber = ( | ||
11 | source: number | undefined | null, | ||
12 | defaultValue: number, | ||
13 | ): number => | ||
14 | Number(source !== undefined && source !== null ? source : defaultValue); | ||