Browse Source

Refactor convertType

Jeremy Tuloup 5 years ago
parent
commit
4f66079128
1 changed files with 12 additions and 14 deletions
  1. 12 14
      src/variables/body/index.tsx

+ 12 - 14
src/variables/body/index.tsx

@@ -114,21 +114,19 @@ const VariableComponent = ({ model }: { model: Variables.Model }) => {
 };
 
 const convertType = (variable: Variables.IVariable) => {
-  const type = variable.type;
-  let value: any = variable.value;
-  if (type === 'int' || type === 'float') {
-    return value * 1;
+  const { type, value } = variable;
+  switch (type) {
+    case 'int':
+      return parseInt(value, 10);
+    case 'float':
+      return parseFloat(value);
+    case 'bool':
+      return value === 'False' ? false : true;
+    case 'str':
+      return value.slice(1, value.length - 1);
+    default:
+      return value;
   }
-  if (type === 'bool') {
-    return value === 'False' ? false : true;
-  }
-  if (type === 'str') {
-    return (value as string)
-      .split('')
-      .slice(1, value.length - 1)
-      .join('');
-  }
-  return value;
 };
 
 const defaultNodeRenderer = ({