-
-
Notifications
You must be signed in to change notification settings - Fork 0
traverse walk()
Eugene Lazutkin edited this page Apr 6, 2026
·
6 revisions
Walks an object tree non-recursively, visiting all values with customizable processors.
This is the foundation traversal module used by clone, assemble, deref, and preprocess. It uses a stack-based approach to avoid recursion limits and handles circular references.
import walk from 'deep6/traverse/walk.js';
const result = [];
walk(
{a: 1, b: {c: 2}},
{
processOther: (v, ctx) => result.push(v),
circular: true
}
);
// result contains all primitive valuesArguments:
-
o— a required object to traverse. It can be anything. -
options— an optional object. The following optional properties are recognized:-
processObject— a function called for each object encountered. -
processOther— a function called for non-object values. -
processCircular— a function called when circular references are detected. -
registry— a flat array of Constructor/handler pairs:[Type1, handler1, Type2, handler2, ...]. Extend withregistry.push(Type, handler). -
filters— an array of predicate functions. Returntrueto indicate the value was handled. -
circular— a boolean flag to enable circular reference detection. -
symbols— a boolean flag to include symbol properties. -
allProps— a boolean flag to include non-enumerable properties. -
context— a custom context object passed to processors.
-
-
Circular— marker class for circular references. -
Command— deferred processing command class. -
processOther— default non-object processor. -
processCircular— default circular reference processor. -
processMap(fn, fnSeen)— creates a Map processor. -
postMapCircular— handles circular references in Maps. -
buildNewMap— builds a new Map from processed values. -
replaceObject— replaces values in stack with an object. -
processObject(fn, fnSeen)— creates an Object processor. -
postObjectCircular— handles circular references in Objects. -
getObjectData— extracts property descriptors and keys. -
buildNewObject— builds a new object from processed values. -
processVariable— processor for Variable instances. -
processCommand— processor for Command objects. -
setObject— sets up circular reference handling. -
registry— default registry of type handlers. -
filters— default filter functions.
Core functions
Environments and variables
Unification
Traverse
Unifiers
Utilities