{ } qjs-modules

deep

Source: quickjs-deep.c — module exports a function list, DeepIterator, and a default object.

Deep (recursive) traversal and manipulation of nested objects/arrays, addressing nodes by a path (array of keys or a Pointer).

Module functions

FunctionArgsDescription
find(root, predicate)2Returns the first value (deeply) matching predicate.
select(root, predicate)2Returns all values matching predicate.
get(root, path)2Reads the value at path.
set(root, path, value)3Writes value at path, creating intermediate nodes.
unset(root, path)2Deletes the value at path.
flatten(root)1Produces a flat map of path → value.
pathOf(root, value)2Returns the path at which value occurs.
equals(a, b)2Deep structural equality.
iterate(root)1Returns a DeepIterator over all nodes.
forEach(root, fn)2Invokes fn(value, path, root) for every node.
clone(root)1Deep copy.

DeepIterator

new DeepIterator(root[, ...])   // length 1
MemberArgsKindDescription
next()0methodIterator step; yields [value, path].
return()0methodEnds iteration.
leave()0methodAscends out of the current subtree.
skip()0methodSkips descending into the current node.
path—getterPath of the current node.
[Symbol.iterator]()0methodReturns itself.