X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.ts;h=08e87320ce2c83f9ab563c46e53ec01718723cb1;hb=c60af6ca67ad2599e7e3e886f219da6323ead61b;hp=f27f06660227643ebe516f8972ee08206334af22;hpb=69bafbedae4dd101f6bf1a40091cecdb831a64b9;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index f27f0666..08e87320 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -1,5 +1,7 @@ import crypto from 'crypto'; +import clone from 'just-clone'; + import { WebSocketCloseEventStatusString } from '../types/WebSocket'; export default class Utils { @@ -163,8 +165,12 @@ export default class Utils { ); } - public static cloneObject(object: T): T { - return JSON.parse(JSON.stringify(object)) as T; + public static isObject(item: unknown): boolean { + return item && typeof item === 'object' && Array.isArray(item) === false; + } + + public static cloneObject(object: T): T { + return clone(object); } public static isIterable(obj: T): boolean { @@ -253,7 +259,7 @@ export default class Utils { } public static JSONStringifyWithMapSupport( - obj: Record | Record[], + obj: Record | Record[] | Map, space?: number ): string { return JSON.stringify(