Download react-hook-form/src/utils/get.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 702 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/utils/get.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/utils/get.ts
-
curl -L -o get.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/utils/get.ts
702 Bytes
| import isKey from './isKey'; | |
| import isNullOrUndefined from './isNullOrUndefined'; | |
| import isObject from './isObject'; | |
| import isUndefined from './isUndefined'; | |
| import stringToPath from './stringToPath'; | |
| export default <T>( | |
| object: T, | |
| path?: string | null, | |
| defaultValue?: unknown, | |
| ): any => { | |
| if (!path || !isObject(object)) { | |
| return defaultValue; | |
| } | |
| const result = (isKey(path) ? [path] : stringToPath(path)).reduce( | |
| (result, key) => | |
| isNullOrUndefined(result) ? result : result[key as keyof {}], | |
| object, | |
| ); | |
| return isUndefined(result) || result === object | |
| ? isUndefined(object[path as keyof T]) | |
| ? defaultValue | |
| : object[path as keyof T] | |
| : result; | |
| }; | |