(start: any, path: string)
| 78 | } |
| 79 | |
| 80 | static valueOf(start: any, path: string): any { |
| 81 | if (!start) |
| 82 | return undefined; |
| 83 | const pathRegex = /^\.?([a-zA-Z_\-][a-zA-Z0-9_\-]*)/; |
| 84 | const indexRegex = /^\[(\d+)\](?:$|\.)/; |
| 85 | path = path.trim(); |
| 86 | if (!path) |
| 87 | return start; |
| 88 | let current = start; |
| 89 | do { |
| 90 | let target = pathRegex.exec(path); |
| 91 | if (target) { |
| 92 | path = path.substring(target[0].length); |
| 93 | if (current.length && typeof current != "string") { |
| 94 | const found = []; |
| 95 | for (const element of current) { |
| 96 | if (element[0] == target[1]) { |
| 97 | found.push(element[1]); |
| 98 | } |
| 99 | } |
| 100 | if (found.length > 1) { |
| 101 | current = found; |
| 102 | } else if (found.length == 1) { |
| 103 | current = found[0]; |
| 104 | } else return undefined; |
| 105 | } else return undefined; |
| 106 | } else if (path[0] == '@') { |
| 107 | current = [current]; |
| 108 | path = path.substring(1); |
| 109 | } else { |
| 110 | target = indexRegex.exec(path); |
| 111 | if (target) { |
| 112 | path = path.substring(target[0].length); |
| 113 | const i = parseInt(target[1]); |
| 114 | if (current.length && typeof current != "string" && i >= 0 && i < current.length) { |
| 115 | current = current[i]; |
| 116 | } else if (i == 0) { |
| 117 | // empty |
| 118 | } else return undefined; |
| 119 | } else return undefined; |
| 120 | } |
| 121 | path = path.trim(); |
| 122 | } while (path); |
| 123 | return current; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | const tokenRegex = /^\d+/; |
no outgoing calls
no test coverage detected