(path: PathType)
| 9 | const simplePathStrRe = /^[a-zA-Z_][a-zA-Z0-9_]*$/; |
| 10 | |
| 11 | function formatPath(path: PathType): string { |
| 12 | if (path.length == 0) { |
| 13 | return "$"; |
| 14 | } |
| 15 | let pathStr = "$"; |
| 16 | for (const pathPart of path) { |
| 17 | if (typeof pathPart === "string") { |
| 18 | if (simplePathStrRe.test(pathPart)) { |
| 19 | pathStr += "." + pathPart; |
| 20 | } else { |
| 21 | pathStr += "[" + JSON.stringify(pathPart) + "]"; |
| 22 | } |
| 23 | } else if (typeof pathPart === "number") { |
| 24 | pathStr += "[" + pathPart + "]"; |
| 25 | } else { |
| 26 | pathStr += ".*"; |
| 27 | } |
| 28 | } |
| 29 | return pathStr; |
| 30 | } |
| 31 | |
| 32 | function isArray(obj: any): boolean { |
| 33 | return obj != null && Array.isArray(obj); |
no outgoing calls
no test coverage detected