* It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z'] * * @param {string} name - The name of the property to get. * * @returns An array of strings.
(name)
| 23 | * @returns An array of strings. |
| 24 | */ |
| 25 | function parsePropPath(name) { |
| 26 | // foo[x][y][z] |
| 27 | // foo.x.y.z |
| 28 | // foo-x-y-z |
| 29 | // foo x y z |
| 30 | const path = []; |
| 31 | const pattern = /\w+|\[(\w*)]/g; |
| 32 | let match; |
| 33 | |
| 34 | while ((match = pattern.exec(name)) !== null) { |
| 35 | throwIfDepthExceeded(path.length); |
| 36 | path.push(match[0] === '[]' ? '' : match[1] || match[0]); |
| 37 | } |
| 38 | |
| 39 | return path; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Convert an array to an object. |
no test coverage detected