aboutsummaryrefslogtreecommitdiffstats
path: root/src/jsUtils.ts
diff options
context:
space:
mode:
authorLibravatar Vijay A <vraravam@users.noreply.github.com>2022-05-15 01:44:18 -0500
committerLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2022-05-15 19:05:55 -0500
commit082b64b6c40fcab3ecf303f53ce83e7753894a32 (patch)
tree92626869949cc671effce89cfbcd52092243de5c /src/jsUtils.ts
parentfix: revert "Typescript conversion" (#153) (diff)
downloadferdium-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.ts23
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 @@
1export const ifUndefinedString = ( 1export const ifUndefinedString = (source: string | undefined | null, defaultValue: string): string => (source !== undefined && source !== null ? source : defaultValue);
2 source: string | undefined | null, 2
3 defaultValue: string, 3export 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
5export const ifUndefinedBoolean = ( 5export 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, 7export 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); 9export const cleanseJSObject = (data: any | undefined | null) => JSON.parse(JSON.stringify(data))
10export const ifUndefinedNumber = (
11 source: number | undefined | null,
12 defaultValue: number,
13): number =>
14 Number(source !== undefined && source !== null ? source : defaultValue);