/** * Expand `~` to the user's home directory in all string values of an object tree. * * Used by both cli/ and local-server/ when loading config.json. */ import * as os from 'os'; import * as path from 'path'; // eslint-disable-next-line @typescript-eslint/no-explicit-any export function expandTilde(obj: any): any { if (typeof obj === 'string') { return obj.startsWith('~/') || obj === '~' ? path.join(os.homedir(), obj.slice(1)) : obj; } if (Array.isArray(obj)) return obj.map(expandTilde); if (obj !== null && typeof obj === 'object') { // eslint-disable-next-line @typescript-eslint/no-explicit-any const result: any = {}; for (const [k, v] of Object.entries(obj)) { result[k] = expandTilde(v); } return result; } return obj; }