build(ui): switch to pnpm
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index ab2a8a5f26302bf23d52aa3bf0a21e407d29ace8..7195ce09ecfff2bfab6ed5c5016b876190830c8b 100644 (file)
@@ -3,10 +3,11 @@ import util from 'node:util';
 
 import clone from 'just-clone';
 
-import Constants from './Constants';
-import { WebSocketCloseEventStatusString } from '../types/WebSocket';
+// import { Constants } from './internal';
+import { Constants } from './Constants';
+import { WebSocketCloseEventStatusString } from '../types';
 
-export default class Utils {
+export class Utils {
   private constructor() {
     // This is intentional
   }
@@ -128,8 +129,7 @@ export default class Utils {
     if (max - min === Infinity) {
       throw new RangeError('Invalid interval');
     }
-    const randomPositiveFloat = crypto.randomBytes(4).readUInt32LE() / 0xffffffff;
-    return randomPositiveFloat * (max - min) + min;
+    return (crypto.randomBytes(4).readUInt32LE() / 0xffffffff) * (max - min) + min;
   }
 
   public static getRandomInteger(max = Constants.MAX_RANDOM_INTEGER, min = 0): number {
@@ -186,6 +186,14 @@ export default class Utils {
     return clone<T>(object);
   }
 
+  public static hasOwnProp(object: unknown, property: PropertyKey): boolean {
+    return Utils.isObject(object) && Object.hasOwn(object as object, property);
+  }
+
+  public static isCFEnvironment(): boolean {
+    return process.env.VCAP_APPLICATION !== undefined;
+  }
+
   public static isIterable<T>(obj: T): boolean {
     return !Utils.isNullOrUndefined(obj) ? typeof obj[Symbol.iterator] === 'function' : false;
   }
@@ -215,13 +223,11 @@ export default class Utils {
   }
 
   public static isEmptyArray(object: unknown | unknown[]): boolean {
-    if (!Array.isArray(object)) {
-      return true;
-    }
-    if (object.length > 0) {
-      return false;
-    }
-    return true;
+    return Array.isArray(object) && object.length === 0;
+  }
+
+  public static isNotEmptyArray(object: unknown | unknown[]): boolean {
+    return Array.isArray(object) && object.length > 0;
   }
 
   public static isEmptyObject(obj: object): boolean {