( obj: ObjectType )
| 15 | } |
| 16 | |
| 17 | export function cloneObject<ObjectType extends Record<string, any>>( |
| 18 | obj: ObjectType |
| 19 | ): ObjectType { |
| 20 | logger.info('cloning object:', obj) |
| 21 | |
| 22 | const enumerableProperties = Object.entries(obj).reduce<Record<string, any>>( |
| 23 | (acc, [key, value]) => { |
| 24 | logger.info('analyzing key-value pair:', key, value) |
| 25 | |
| 26 | // Recursively clone only plain objects, omitting class instances. |
| 27 | acc[key] = isPlainObject(value) ? cloneObject(value) : value |
| 28 | return acc |
| 29 | }, |
| 30 | {} |
| 31 | ) |
| 32 | |
| 33 | return isPlainObject(obj) |
| 34 | ? enumerableProperties |
| 35 | : Object.assign(Object.getPrototypeOf(obj), enumerableProperties) |
| 36 | } |
no test coverage detected
searching dependent graphs…