(object: Object, path: Array<string | number>)
| 608 | } |
| 609 | |
| 610 | export function getInObject(object: Object, path: Array<string | number>): any { |
| 611 | return path.reduce((reduced: Object, attr: any): any => { |
| 612 | if (reduced) { |
| 613 | if (hasOwnProperty.call(reduced, attr)) { |
| 614 | return reduced[attr]; |
| 615 | } |
| 616 | if (typeof reduced[Symbol.iterator] === 'function') { |
| 617 | // Convert iterable to array and return array[index] |
| 618 | // |
| 619 | // TRICKY |
| 620 | // Don't use [...spread] syntax for this purpose. |
| 621 | // This project uses @babel/plugin-transform-spread in "loose" mode which only works with Array values. |
| 622 | // Other types (e.g. typed arrays, Sets) will not spread correctly. |
| 623 | return Array.from(reduced)[attr]; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | return null; |
| 628 | }, object); |
| 629 | } |
| 630 | |
| 631 | export function deletePathInObject( |
| 632 | object: Object, |
no outgoing calls
no test coverage detected