aboutsummaryrefslogtreecommitdiffstats
path: root/src/jsUtils.ts
diff options
context:
space:
mode:
authorLibravatar Ricardo Cino <ricardo@cino.io>2022-06-23 18:10:39 +0200
committerLibravatar GitHub <noreply@github.com>2022-06-23 16:10:39 +0000
commit6b2c2b8dfb86245a1747bf7977159f5129461863 (patch)
tree28944f62a962d8a658262ea902f8554d4419fa9e /src/jsUtils.ts
parentchore: featureStore and GlobalErrorStore JS => TS (diff)
downloadferdium-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.ts23
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 @@
1export 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.
2export const ifUndefinedString = (
3 source: string | undefined | null,
4 defaultValue: string,
5): string => (source !== undefined && source !== null ? source : defaultValue);
2 6
3export const ifUndefinedBoolean = (source: boolean | undefined | null, defaultValue: boolean): boolean => Boolean(source !== undefined && source !== null ? source : defaultValue); 7export 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
5export const ifUndefinedNumber = (source: number | undefined | null, defaultValue: number): number => Number(source !== undefined && source !== null ? source : defaultValue); 15 return defaultValue;
16};
6 17
7export const convertToJSON = (data: string | any | undefined | null) => data && typeof data === 'string' && data.length > 0 ? JSON.parse(data) : data 18export const convertToJSON = (data: string | any | undefined | null) =>
19 data && typeof data === 'string' && data.length > 0 ? JSON.parse(data) : data;
8 20
9export const cleanseJSObject = (data: any | undefined | null) => JSON.parse(JSON.stringify(data)) 21export const cleanseJSObject = (data: any | undefined | null) =>
22 JSON.parse(JSON.stringify(data));