(
value: MaybeRefDeep<T>,
customize?: (
val: MaybeRefDeep<T>,
key: string,
level: number,
) => T | undefined,
currentKey: string = '',
currentLevel: number = 0,
)
| 20 | // Helper function for cloning deep objects where |
| 21 | // the level and key is provided to the callback function. |
| 22 | function _cloneDeep<T>( |
| 23 | value: MaybeRefDeep<T>, |
| 24 | customize?: ( |
| 25 | val: MaybeRefDeep<T>, |
| 26 | key: string, |
| 27 | level: number, |
| 28 | ) => T | undefined, |
| 29 | currentKey: string = '', |
| 30 | currentLevel: number = 0, |
| 31 | ): T { |
| 32 | if (customize) { |
| 33 | const result = customize(value, currentKey, currentLevel) |
| 34 | if (result === undefined && isRef(value)) { |
| 35 | return result as T |
| 36 | } |
| 37 | if (result !== undefined) { |
| 38 | return result |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | if (Array.isArray(value)) { |
| 43 | return value.map((val, index) => |
| 44 | _cloneDeep(val, customize, String(index), currentLevel + 1), |
| 45 | ) as unknown as T |
| 46 | } |
| 47 | |
| 48 | if (typeof value === 'object' && isPlainObject(value)) { |
| 49 | const entries = Object.entries(value).map(([key, val]) => [ |
| 50 | key, |
| 51 | _cloneDeep(val, customize, key, currentLevel + 1), |
| 52 | ]) |
| 53 | return Object.fromEntries(entries) |
| 54 | } |
| 55 | |
| 56 | return value as T |
| 57 | } |
| 58 | |
| 59 | export function cloneDeep<T>( |
| 60 | value: MaybeRefDeep<T>, |
no test coverage detected
searching dependent graphs…