Apply dependencies update
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index f62319983507e9dbc038b7032cd8275da7d080b7..8dda95a699b362c66c5bb195e96de4abf30e39c1 100644 (file)
@@ -70,9 +70,10 @@ export default class Utils {
     if (Number.isSafeInteger(value)) {
       return value as number;
     }
-    // Check
+    if (typeof value === 'number') {
+      changedValue = Math.trunc(value);
+    }
     if (Utils.isString(value)) {
-      // Create Object
       changedValue = parseInt(value as string);
     }
     return changedValue;
@@ -83,9 +84,7 @@ export default class Utils {
     if (!value) {
       return 0;
     }
-    // Check
     if (Utils.isString(value)) {
-      // Create Object
       changedValue = parseFloat(value as string);
     }
     return changedValue;
@@ -93,15 +92,17 @@ export default class Utils {
 
   public static convertToBoolean(value: unknown): boolean {
     let result = false;
-    // Check boolean
     if (value) {
       // Check the type
       if (typeof value === 'boolean') {
-        // Already a boolean
         result = value;
-      } else {
-        // Convert
-        result = value === 'true';
+      } else if (
+        Utils.isString(value) &&
+        ((value as string).toLowerCase() === 'true' || value === '1')
+      ) {
+        result = true;
+      } else if (typeof value === 'number' && value === 1) {
+        result = true;
       }
     }
     return result;
@@ -197,6 +198,9 @@ export default class Utils {
   }
 
   public static isEmptyObject(obj: object): boolean {
+    if (obj?.constructor !== Object) {
+      return false;
+    }
     // Iterates over the keys of an object, if
     // any exist, return false.
     for (const _ in obj) {