navigateNode function

Node? navigateNode(
  1. Node? astNode,
  2. String path
)

Implementation

Node? navigateNode(Node? astNode, String path) {
  Node? node;
  if (astNode is ObjectNode) {
    final objectNode = astNode;
    final propertyNode = objectNode.children.firstWhereOrNull((final prop) {
      return prop.key!.value == path;
    });
    if (propertyNode != null) {
      node = propertyNode.value;
    }
  }
  if (astNode is ArrayNode) {
    final arrayNode = astNode;
    final index = int.tryParse(path);
    if (index != null && arrayNode.children.length > index) {
      node = arrayNode.children[index];
    }
  }
  return node;
}