gqty
Version:
The No-GraphQL Client for TypeScript
20 lines (16 loc) • 521 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
function select(node, path, onNext) {
const probedNode = onNext ? onNext(node, path) : node;
if (path.length === 0) {
return node;
} else if (probedNode == null || typeof probedNode !== "object") {
return void 0;
}
if (Array.isArray(probedNode)) {
return probedNode.map((item) => select(item, path, onNext));
}
const [key, ...rest] = path;
return select(probedNode[key], rest, onNext);
}
exports.select = select;