pg-proto-parser
Version:
The LaunchQL Proto parser
2 lines (1 loc) • 1.25 kB
TypeScript
export declare const nestedObjCode = "\nexport default {\n get<T>(obj: Record<string, any>, path: string): T | undefined {\n const keys = path.replace(/[(w+)]/g, '.$1').split('.');\n let result: any = obj;\n for (const key of keys) {\n if (result == null) {\n return undefined;\n }\n result = result[key];\n }\n return result as T;\n },\n \n set(obj: Record<string, any>, path: string, value: any): void {\n if (value === undefined) {\n return;\n }\n \n const keys = path.replace(/[(w+)]/g, '.$1').split('.');\n let current = obj;\n for (let i = 0; i < keys.length - 1; i++) {\n const key = keys[i];\n if (typeof current[key] !== 'object') {\n current[key] = {};\n }\n current = current[key];\n }\n current[keys[keys.length - 1]] = value;\n },\n \n has(obj: Record<string, any>, path: string): boolean {\n const keys = path.replace(/[(w+)]/g, '.$1').split('.');\n let current = obj;\n for (const key of keys) {\n if (current == null || !(key in current)) {\n return false;\n }\n current = current[key];\n }\n return true;\n }\n };\n \n";