{ } qjs-modules

tree-walker

Source: quickjs-tree-walker.c — module exports TreeWalker and TreeIterator

DOM-style traversal over an arbitrary nested JS value (objects/arrays treated as a tree of nodes).

TreeWalker

new TreeWalker(root[, filter, flags])   // length 1
MethodArgsDescription
firstChild()0Descend to the first child of the current node.
lastChild()0Descend to the last child.
nextNode()0Advance to the next node in document order.
nextSibling()0Move to the next sibling.
parentNode()0Move up to the parent.
previousNode()0Move to the previous node in document order.
previousSibling()0Move to the previous sibling.
toString()0String representation of the walker.

Properties

PropertyKindDescription
rootgetterThe traversal root.
currentNodegetterThe node currently pointed at.
currentKeygetterKey/index of the current node within its parent.
currentPathgetterPath from the root to the current node.
depthgetterCurrent nesting depth.
indexgetter/setterIndex of the current node among its siblings.
lengthgetterNumber of children of the current node.
tagMaskgetter/setterBitmask of node types to visit.
filtergetterThe node filter (enumerable).
flagsgetter/setterTraversal flags.

TreeIterator

new TreeIterator(root[, ...])   // length 1

Iterable form of the walker: exposes next(), [Symbol.iterator]() and tags itself "TreeIterator".