X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.ts;h=808ef380d170b2a5a11acfeaa96e7d23b49e1040;hb=c2a11566c6855de3b1f48f701be2c8779c0093a6;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..808ef380 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -1,4 +1,4 @@ -import { randomBytes, randomInt, randomUUID } from 'node:crypto'; +import { randomBytes, randomInt, randomUUID, webcrypto } from 'node:crypto'; import { inspect } from 'node:util'; import { @@ -216,11 +216,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 +249,7 @@ function deepClone( ); } return clone as O; -} +}; export const cloneObject = (object: T): T => { return deepClone(object as CloneableData) as T; @@ -354,10 +354,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 = (