Download react-hook-form/src/utils/deepMerge.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 663 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/utils/deepMerge.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/utils/deepMerge.ts
-
curl -L -o deepMerge.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/utils/deepMerge.ts
663 Bytes
| import isObject from './isObject'; | |
| import isPrimitive from './isPrimitive'; | |
| export default function deepMerge< | |
| T extends Record<keyof T, any>, | |
| U extends Record<keyof U, any>, | |
| >(target: T, source: U): T & U { | |
| if (isPrimitive(target) || isPrimitive(source)) { | |
| return source; | |
| } | |
| for (const key in source) { | |
| const targetValue = target[key]; | |
| const sourceValue = source[key]; | |
| try { | |
| target[key] = | |
| (isObject(targetValue) && isObject(sourceValue)) || | |
| (Array.isArray(targetValue) && Array.isArray(sourceValue)) | |
| ? deepMerge(targetValue, sourceValue) | |
| : sourceValue; | |
| } catch {} | |
| } | |
| return target; | |
| } | |