(bracketPath: string)
| 1803 | const INDEX_REGEXP = /^\d+$/ |
| 1804 | |
| 1805 | function bracketPathToTokens(bracketPath: string): Array<string | number> { |
| 1806 | // real empty path (from append("", value)) |
| 1807 | if (bracketPath === "") { |
| 1808 | return [""] |
| 1809 | } |
| 1810 | |
| 1811 | const replaced = bracketPath.replace(/\[(.*?)\]/g, ".$1") |
| 1812 | const parts = replaced.split(".") |
| 1813 | // if bracket path started with "[...]" we get ".foo" => ["", "foo"]; drop the synthetic first "" |
| 1814 | const start = replaced.startsWith(".") ? 1 : 0 |
| 1815 | |
| 1816 | return parts |
| 1817 | .slice(start) |
| 1818 | .map((part) => (INDEX_REGEXP.test(part) ? globalThis.Number(part) : part)) |
| 1819 | } |
| 1820 | |
| 1821 | /** |
| 1822 | * Builds a nested tree object from a list of bracket-path entries. |
no test coverage detected