(data: T)
| 3 | import isWeb from './isWeb'; |
| 4 | |
| 5 | export default function cloneObject<T>(data: T): T { |
| 6 | if (data instanceof Date) { |
| 7 | return new Date(data) as any; |
| 8 | } |
| 9 | |
| 10 | const isFileListInstance = |
| 11 | typeof FileList !== 'undefined' && data instanceof FileList; |
| 12 | |
| 13 | if (isWeb && (data instanceof Blob || isFileListInstance)) { |
| 14 | return data; |
| 15 | } |
| 16 | |
| 17 | const isArray = Array.isArray(data); |
| 18 | |
| 19 | if (!isArray && !(isObject(data) && isPlainObject(data))) { |
| 20 | return data; |
| 21 | } |
| 22 | |
| 23 | const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data)); |
| 24 | |
| 25 | for (const key in data) { |
| 26 | if (Object.prototype.hasOwnProperty.call(data, key)) { |
| 27 | copy[key] = cloneObject(data[key]); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | return copy; |
| 32 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…