README.md: Fix sections hierarchy
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index c7fd875f8f7f09130164ee3126eaebd192280e00..5b66368fa87f264dc8a2d93c72c2a6c55ad809cc 100644 (file)
@@ -1,7 +1,12 @@
 import crypto from 'crypto';
+
 import { v4 as uuid } from 'uuid';
 
 export default class Utils {
+  private constructor() {
+    // This is intentional
+  }
+
   public static logPrefix(prefixString = ''): string {
     return new Date().toLocaleString() + prefixString;
   }
@@ -10,10 +15,6 @@ export default class Utils {
     return uuid();
   }
 
-  public static equals(obj1: unknown, obj2: unknown): boolean {
-    return JSON.stringify(obj1) === JSON.stringify(obj2);
-  }
-
   public static async sleep(milliSeconds: number): Promise<NodeJS.Timeout> {
     return new Promise((resolve) => setTimeout(resolve as () => void, milliSeconds));
   }
@@ -237,4 +238,23 @@ export default class Utils {
   public static secureRandom(): number {
     return crypto.randomBytes(4).readUInt32LE() / 0x100000000;
   }
+
+  public static JSONStringifyWithMapSupport(
+    obj: Record<string, unknown> | Record<string, unknown>[],
+    space?: number
+  ): string {
+    return JSON.stringify(
+      obj,
+      (key, value: Record<string, unknown>) => {
+        if (value instanceof Map) {
+          return {
+            dataType: 'Map',
+            value: [...value],
+          };
+        }
+        return value;
+      },
+      space
+    );
+  }
 }