import crypto from 'crypto';
+
import { v4 as uuid } from 'uuid';
export default class Utils {
+ private constructor() {
+ // This is intentional
+ }
+
public static logPrefix(prefixString = ''): string {
return new Date().toLocaleString() + prefixString;
}
return uuid();
}
- public static equals(obj1: unknown, obj2: unknown): boolean {
- return JSON.stringify(obj1) === JSON.stringify(obj2);
- }
-
public static async sleep(milliSeconds: number): Promise<NodeJS.Timeout> {
return new Promise((resolve) => setTimeout(resolve as () => void, milliSeconds));
}
public static secureRandom(): number {
return crypto.randomBytes(4).readUInt32LE() / 0x100000000;
}
+
+ public static JSONStringifyWithMapSupport(
+ obj: Record<string, unknown> | Record<string, unknown>[],
+ space?: number
+ ): string {
+ return JSON.stringify(
+ obj,
+ (key, value: Record<string, unknown>) => {
+ if (value instanceof Map) {
+ return {
+ dataType: 'Map',
+ value: [...value],
+ };
+ }
+ return value;
+ },
+ space
+ );
+ }
}