(path: string)
| 8 | } |
| 9 | |
| 10 | export function jsonPath(path: string): Result { |
| 11 | const tree = getViewState().tree; |
| 12 | const json = tree.toJSON(); |
| 13 | |
| 14 | try { |
| 15 | const pointers: string[] = |
| 16 | JSONPath({ |
| 17 | path, |
| 18 | json, |
| 19 | resultType: "pointer", |
| 20 | wrap: true, |
| 21 | }) ?? []; |
| 22 | |
| 23 | const values = pointers.map((p) => { |
| 24 | const id = rootMarker + p; |
| 25 | return tree.stringifyNode(tree.node(id)); |
| 26 | }); |
| 27 | |
| 28 | // flatten result to a single value |
| 29 | const output = values.length <= 1 ? values[0] : `[${values.join(",")}]`; |
| 30 | |
| 31 | return { output, error: undefined }; |
| 32 | } catch (e) { |
| 33 | return { output: undefined, error: e }; |
| 34 | } |
| 35 | } |
no test coverage detected