(
data: {[propName: string]: any},
key: string | undefined,
canAccessSuper: boolean = true
)
| 1 | import {keyToPath} from './keyToPath'; |
| 2 | |
| 3 | export function getVariable( |
| 4 | data: {[propName: string]: any}, |
| 5 | key: string | undefined, |
| 6 | canAccessSuper: boolean = true |
| 7 | ): any { |
| 8 | if (!data || !key || typeof data !== 'object') { |
| 9 | return undefined; |
| 10 | } else if (canAccessSuper ? key in data : data.hasOwnProperty(key)) { |
| 11 | return data[key]; |
| 12 | } |
| 13 | |
| 14 | return keyToPath(key).reduce( |
| 15 | (obj, key) => |
| 16 | obj && |
| 17 | typeof obj === 'object' && |
| 18 | (canAccessSuper ? key in obj : obj.hasOwnProperty(key)) |
| 19 | ? obj[key] |
| 20 | : undefined, |
| 21 | data |
| 22 | ); |
| 23 | } |
no test coverage detected