feat: handle connectors status at stop with evses configuration
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index 9323e4be72b71d22b114a32834d6c49e26d5dc8e..4306d8872e0114928481769feb6bb6daf5ff603e 100644 (file)
@@ -3,7 +3,8 @@ import util from 'node:util';
 
 import clone from 'just-clone';
 
-import { Constants } from './internal';
+// import { Constants } from './internal';
+import { Constants } from './Constants';
 import { WebSocketCloseEventStatusString } from '../types';
 
 export class Utils {
@@ -190,7 +191,7 @@ export class Utils {
   }
 
   public static isCFEnvironment(): boolean {
-    return process.env.VCAP_APPLICATION !== undefined;
+    return !Utils.isNullOrUndefined(process.env.VCAP_APPLICATION);
   }
 
   public static isIterable<T>(obj: T): boolean {
@@ -222,17 +223,11 @@ export class Utils {
   }
 
   public static isEmptyArray(object: unknown | unknown[]): boolean {
-    if (Array.isArray(object) && object.length === 0) {
-      return true;
-    }
-    return false;
+    return Array.isArray(object) && object.length === 0;
   }
 
   public static isNotEmptyArray(object: unknown | unknown[]): boolean {
-    if (Array.isArray(object) && object.length > 0) {
-      return true;
-    }
-    return false;
+    return Array.isArray(object) && object.length > 0;
   }
 
   public static isEmptyObject(obj: object): boolean {
@@ -254,9 +249,9 @@ export class Utils {
    * @param retryNumber - the number of retries that have already been attempted
    * @returns delay in milliseconds
    */
-  public static exponentialDelay(retryNumber = 0): number {
+  public static exponentialDelay(retryNumber = 0, maxDelayRatio = 0.2): number {
     const delay = Math.pow(2, retryNumber) * 100;
-    const randomSum = delay * 0.2 * Utils.secureRandom(); // 0-20% of the delay
+    const randomSum = delay * maxDelayRatio * Utils.secureRandom(); // 0-20% of the delay
     return delay + randomSum;
   }