Private
_contextPrivate
_keyPrivate
_rootPrivate
_valuePrivate
breakPrivate
changeReadonly
depthThe depth of the current node in the tree, starting from 0 at the root context.
Readonly
pathThe path from the root node to the current node.
This does not represent the path of the traversal, but rather the path to access the node from the root node.
const tree = {
value: 1,
depth: 0,
left: {
value: 2,
depth: 1,
left: { depth: 2, value: 4, left: null, right: null },
right: { depth: 2, value: 5, left: null, right: null },
},
right: {
value: 3,
depth: 1,
left: { depth: 2, value: 6, left: null, right: null },
right: {
depth: 2,
value: 7, // <-- target
left: null,
right: null,
UNIQUE_KEY: "UNIQUE_VALUE",
},
},
} as const;
let path: Readonly<(string | number)[]> | undefined
treeBFS(tree, (ctx) => {
if (ctx.isRecord() && ctx.key === "value" && ctx.value === 7) {
path = ctx.path;
}
});
expect(path).toStrictEqual(["right", "right", "value"]);
Returns an array of ancestors of the current context. An ancestor is a parent or a grandparent of the current context. Each ancestor is represented as a record or an array.
The array of ancestors.
Returns an array of child objects or arrays in the tree context.
The child objects or arrays.
Gets the current context.
Mutating the context's structure may cause unexpected behavior.
The current context, either as a record or an array.
Gets the key of the current context node.
The key of the node.
Gets the parent context of the current node.
The parent context.
Gets the root context of the tree.
The root context.
Gets the value of the current context node.
May cause unexpected behavior in traversal if mutated.
The value of the node.
Sets the value of the current context node.
If the original value or the new value is an object, neither will be traversed through after setting a value.
The new value to be set.
Generated using TypeDoc
Represents the context of a node in a tree structure. Provides methods to interact with the node and its position in the tree.