README.md: Fix sections hierarchy
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index 1ad1a7924bb0b5e4eb5e8fc7778a9d89f953eda6..5b66368fa87f264dc8a2d93c72c2a6c55ad809cc 100644 (file)
@@ -238,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
+    );
+  }
 }