* Parses the path. Splits it into * keys for objects and indices for arrays.
(path: string)
| 69 | * keys for objects and indices for arrays. |
| 70 | */ |
| 71 | function tokenize (path: string): Array<string | number> { |
| 72 | const tokens: Array<string | number> = [] |
| 73 | |
| 74 | const parts = path.split('.') |
| 75 | |
| 76 | for (let i = 0; i < parts.length; i++) { |
| 77 | const part = parts[i].trim() |
| 78 | |
| 79 | if (part.length === 0) { |
| 80 | continue |
| 81 | } |
| 82 | |
| 83 | const arrayIndexes: string[] = part.split(SPLIT_REG_EXP) |
| 84 | |
| 85 | if (arrayIndexes.length === 0) { |
| 86 | // TODO |
| 87 | continue |
| 88 | } |
| 89 | |
| 90 | if (FORBIDDEN_KEYS.has(arrayIndexes[0])) { |
| 91 | throw new Error(`invalid path: forbidden key '${arrayIndexes[0]}'`) |
| 92 | } |
| 93 | |
| 94 | tokens.push(arrayIndexes[0]) |
| 95 | |
| 96 | for (let j = 1; j < arrayIndexes.length; j++) { |
| 97 | if (arrayIndexes[j].length === 0) { |
| 98 | continue |
| 99 | } |
| 100 | |
| 101 | tokens.push(Number(arrayIndexes[j])) |
| 102 | } |
| 103 | } |
| 104 | return tokens |
| 105 | } |
no test coverage detected