(src: any)
| 1 | import { isPlainObject } from './is-plain-object'; |
| 2 | |
| 3 | export function cloneDeep(src: any): any { |
| 4 | const type = typeof src; |
| 5 | |
| 6 | let data: any; |
| 7 | if (src === null || src === undefined) { |
| 8 | data = src; |
| 9 | } else if (Array.isArray(src)) { |
| 10 | data = src.map(item => cloneDeep(item)); |
| 11 | } else if (type === 'object' && isPlainObject(src)) { |
| 12 | data = {}; |
| 13 | for (const key in src) { |
| 14 | // eslint-disable-next-line no-prototype-builtins |
| 15 | if (src.hasOwnProperty(key)) { |
| 16 | data[key] = cloneDeep(src[key]); |
| 17 | } |
| 18 | } |
| 19 | } else { |
| 20 | data = src; |
| 21 | } |
| 22 | |
| 23 | return data; |
| 24 | } |
no test coverage detected
searching dependent graphs…