Merge dependabot/npm_and_yarn/mikro-orm/mariadb-5.8.2 into combined-prs-branch
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index c29f8d156687139aeefb640ae5e0741add8c2924..808ef380d170b2a5a11acfeaa96e7d23b49e1040 100644 (file)
@@ -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<I extends CloneableData, O extends CloneableData = I>(
+const deepClone = <I extends CloneableData, O extends CloneableData = I>(
   value: I,
   formatKey?: FormatKey,
   refs: Map<I, O> = new Map<I, O>(),
-): O {
+): O => {
   const ref = refs.get(value);
   if (ref !== undefined) {
     return ref;
@@ -249,7 +249,7 @@ function deepClone<I extends CloneableData, O extends CloneableData = I>(
     );
   }
   return clone as O;
-}
+};
 
 export const cloneObject = <T>(object: T): T => {
   return deepClone(object as CloneableData) as T;
@@ -354,10 +354,10 @@ export const promiseWithTimeout = async <T>(
 /**
  * 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 = (