-import { randomBytes, randomInt, randomUUID } from 'node:crypto';
+import { randomBytes, randomInt, randomUUID, webcrypto } from 'node:crypto';
import { inspect } from 'node:util';
import {
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;
);
}
return clone as O;
-}
+};
export const cloneObject = <T>(object: T): T => {
return deepClone(object as CloneableData) as 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 = (