( collection: CollectionType, searchKeyPath: KeyPath<Key>, notSetValue?: GetTypeParameters[2] )
| 16 | * work with plain Objects and Arrays. |
| 17 | */ |
| 18 | export function getIn( |
| 19 | collection: CollectionType, |
| 20 | searchKeyPath: KeyPath<Key>, |
| 21 | notSetValue?: GetTypeParameters[2] |
| 22 | ): ReturnType<GetType> { |
| 23 | const keyPath = coerceKeyPath(searchKeyPath); |
| 24 | let i = 0; |
| 25 | while (i !== keyPath.length) { |
| 26 | // @ts-expect-error keyPath[i++] can not be undefined by design |
| 27 | collection = get(collection, keyPath[i++], NOT_SET); |
| 28 | if (collection === NOT_SET) { |
| 29 | return notSetValue; |
| 30 | } |
| 31 | } |
| 32 | return collection; |
| 33 | } |
no test coverage detected