Warning, /firebird/firebird-ng/src/app/utils/deep-copy.ts is written in an unsupported language. File is not indexed.
0001 // Taken from https://stackoverflow.com/a/73444663/548894
0002
0003 export const deepCopy = <T, U = T extends Array<infer V> ? V : never>(source: T ): T => {
0004 if (Array.isArray(source)) {
0005 return source.map(item => (deepCopy(item))) as T & U[]
0006 }
0007 if (source instanceof Date) {
0008 return new Date(source.getTime()) as T & Date
0009 }
0010 if (source && typeof source === 'object') {
0011 return (Object.getOwnPropertyNames(source) as (keyof T)[]).reduce<T>((o, prop) => {
0012 Object.defineProperty(o, prop, Object.getOwnPropertyDescriptor(source, prop)!)
0013 o[prop] = deepCopy(source[prop])
0014 return o
0015 }, Object.create(Object.getPrototypeOf(source)))
0016 }
0017 return source
0018 }