X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.ts;h=6a3d30fee9bbcebdc264a6239dfaec8601e1c5eb;hb=61e0f0426f3b5ffb6738bc1f6b61ff9ed789377b;hp=c29f8d156687139aeefb640ae5e0741add8c2924;hpb=661ac64bb0f1aabe9f7473b6b1ee0694589fe8ca;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index c29f8d15..6a3d30fe 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -1,4 +1,5 @@ -import { randomBytes, randomInt, randomUUID } from 'node:crypto'; +import { randomBytes, randomInt, randomUUID, webcrypto } from 'node:crypto'; +import { env } from 'node:process'; import { inspect } from 'node:util'; import { @@ -216,11 +217,11 @@ type CloneableData = type FormatKey = (key: string) => string; -function deepClone( +const deepClone = ( value: I, formatKey?: FormatKey, refs: Map = new Map(), -): O { +): O => { const ref = refs.get(value); if (ref !== undefined) { return ref; @@ -249,7 +250,7 @@ function deepClone( ); } return clone as O; -} +}; export const cloneObject = (object: T): T => { return deepClone(object as CloneableData) as T; @@ -260,7 +261,7 @@ export const hasOwnProp = (object: unknown, property: PropertyKey): boolean => { }; export const isCFEnvironment = (): boolean => { - return !isNullOrUndefined(process.env.VCAP_APPLICATION); + return !isNullOrUndefined(env.VCAP_APPLICATION); }; export const isIterable = (obj: T): boolean => { @@ -354,10 +355,10 @@ export const promiseWithTimeout = async ( /** * Generates a cryptographically secure random number in the [0,1[ range * - * @returns + * @returns A number in the [0,1[ range */ export const secureRandom = (): number => { - return randomBytes(4).readUInt32LE() / 0x100000000; + return webcrypto.getRandomValues(new Uint32Array(1))[0] / 0x100000000; }; export const JSONStringifyWithMapSupport = (