Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 170x 170x 170x 7119x 7119x 7119x 7119x 6943x 6943x 7150x 7150x 7150x 7149x 7050x 7050x 7045x 99x 77x 77x 73x 22x 22x 22x 20x 6931x | import {type Path, toPath} from '@jsonjoy.com/json-pointer'; import {VecNode, ObjNode, ArrNode} from '../../nodes'; import type {JsonNode} from '../../nodes'; export const find = (startNode: JsonNode, path: string | Path): JsonNode => { const steps = toPath(path); let node: JsonNode | undefined = startNode; const length = steps.length; if (!length) return node; let i = 0; while (i < length && node) { const step = steps[i++]; node = node.container(); if (!node) throw new Error('NOT_CONTAINER'); if (node instanceof ObjNode) { const nextNode = node.get(String(step)) as JsonNode | undefined; if (!nextNode) throw new Error('NOT_FOUND'); node = nextNode; } else if (node instanceof ArrNode) { const nextNode = node.getNode(Number(step)); if (!nextNode) throw new Error('NOT_FOUND'); node = nextNode; } else if (node instanceof VecNode) { const nextNode = node.get(Number(step)) as JsonNode | undefined; if (!nextNode) throw new Error('NOT_FOUND'); node = nextNode; } } return node; }; |