import { join } from "path"; import type { ResocketConfig } from "../types"; import { getResocketConfigPath } from "../config"; export const getWorkerFilePath = ( configPath: string | undefined, config: ResocketConfig ) => { let resocketConfigPath: string | undefined = configPath ? configPath : getResocketConfigPath(); if (!resocketConfigPath) throw new Error("unable to find resocket.json"); //now this will always read the core file const workerFilePath = join(resocketConfigPath, "../", config.main); return workerFilePath; }; export function areArraysSimilar(arr1: string[], arr2: string[]): boolean { if (arr1.length !== arr2.length) { return false; } const sortedArr1 = arr1.slice().sort(); const sortedArr2 = arr2.slice().sort(); for (let i = 0; i < sortedArr1.length; i++) { if (sortedArr1[i] !== sortedArr2[i]) { return false; } } return true; } export function removeUndefined>( obj: Record ): T { const result: Record = {}; for (const key in obj) { if (obj[key] !== undefined) { result[key] = obj[key]; } } return result as T; } export function getRandomElement(arr: Array) { const randomIndex = Math.floor(Math.random() * arr.length); return arr[randomIndex]; } export function findDuplicate(array: string[]): string | undefined { const seen: { [key: string]: boolean } = {}; for (const element of array) { if (seen[element]) { return element; // Duplicate found } seen[element] = true; } return undefined; // No duplicates found } export function hasDuplicateKey(arr: any[], key: string) { const seenKeys = new Set(); for (const item of arr) { if (seenKeys.has(item[key])) { return item[key]; // Duplicate found } seenKeys.add(item[key]); } return false; // No duplicates }