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qBAAM;oBACL,MAAM,CAAC,MAAI,CAAC,GAAG,KAAK,CAAC;iBACtB;aACF;SACF;KACF;IAED,kBAAkB,CAAC,GAAG,EAAE,CAAC;IAEzB,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Simple deep merge function. Takes all arguments and returns a deep copy of the objects merged\n * together in the order provided. If an object creates a circular reference, it will assign the\n * original reference.\n */\nexport function merge<T = {}>(target: Partial<T>, ...args: (Partial<T> | null | undefined | false)[]): T {\n for (const arg of args) {\n _merge(target || {}, arg as Partial<T>);\n }\n\n return target as T;\n}\n\n/**\n * The _merge helper iterates through all props on source and assigns them to target.\n * When the value is an object, we will create a deep clone of the object. However if\n * there is a circular reference, the value will not be deep cloned and will persist\n * the reference.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction _merge<T extends Object>(target: T, source: T, circularReferences: any[] = []): T {\n circularReferences.push(source);\n\n for (let name in source) {\n if (source.hasOwnProperty(name)) {\n if (name !== '__proto__' && name !== 'constructor' && name !== 'prototype') {\n const value: T[Extract<keyof T, string>] = source[name];\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n const isCircularReference = circularReferences.indexOf(value) > -1;\n target[name] = (isCircularReference\n ? value\n : _merge(target[name] || {}, value, circularReferences)) as T[Extract<keyof T, string>];\n } else {\n target[name] = value;\n }\n }\n }\n }\n\n circularReferences.pop();\n\n return target;\n}\n"]}
\No newline at end of file