README.md: Fix sections hierarchy
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index 9486ca0972b46febddae58d0268a052fcd4199c8..5b66368fa87f264dc8a2d93c72c2a6c55ad809cc 100644 (file)
@@ -1,4 +1,5 @@
 import crypto from 'crypto';
+
 import { v4 as uuid } from 'uuid';
 
 export default class Utils {
@@ -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
+    );
+  }
 }