(state: object, complexKey: string)
| 2 | import type { GetIn } from "../types"; |
| 3 | |
| 4 | const getIn: GetIn = (state: object, complexKey: string): any => { |
| 5 | // Intentionally using iteration rather than recursion |
| 6 | const path = toPath(complexKey); |
| 7 | let current: any = state; |
| 8 | for (let i = 0; i < path.length; i++) { |
| 9 | const key = path[i]; |
| 10 | if ( |
| 11 | current === undefined || |
| 12 | current === null || |
| 13 | typeof current !== "object" || |
| 14 | (Array.isArray(current) && isNaN(Number(key))) |
| 15 | ) { |
| 16 | return undefined; |
| 17 | } |
| 18 | current = current[key]; |
| 19 | } |
| 20 | return current; |
| 21 | }; |
| 22 | |
| 23 | export default getIn; |
no test coverage detected
searching dependent graphs…