X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.ts;h=5b66368fa87f264dc8a2d93c72c2a6c55ad809cc;hb=d3140adc8c6ad502eb9566aabfc1af8f66d0ef24;hp=9486ca0972b46febddae58d0268a052fcd4199c8;hpb=479f37587d3341fc99ccbc79a7738f7a6847e713;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 9486ca09..5b66368f 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -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 | Record[], + space?: number + ): string { + return JSON.stringify( + obj, + (key, value: Record) => { + if (value instanceof Map) { + return { + dataType: 'Map', + value: [...value], + }; + } + return value; + }, + space + ); + } }