@suchipi/traverse
Version:
Basic depth-first traversal function
43 lines (42 loc) • 1.44 kB
TypeScript
declare const stop: unique symbol;
declare function traverse(
/**
* The tree structure to traverse.
*/
tree: any,
/**
* Callbacks to call during traversal
*/
callbacks?: {
/**
* If you provide a `before` callback, it will be called on the way *down*
* the traversal stack; this is equivalent to a breadth-first search.
*
* If you return `traverse.stop`, children of the current value will not be
* traversed over.
*/
before?: (value: any, path: Array<string | number>) => void | typeof stop;
/**
* If you provide an `after` callback, it will be called on the way *up*
* the traversal stack; this is equivalent to a depth-first search.
*/
after?: (value: any, path: Array<string | number>) => void;
/**
* If you provide a `filter` callback, it will be called prior to
* traversing a path, and its return value will be used to determine
* whether children of this path should be visited.
*
* This will be called before the `before` callback, if there is a
* `before` callback present.
*
* This defaults to a function which returns true for properties which
* aren't getters.
*/
filter?: (descriptor: PropertyDescriptor, path: Array<string | number>) => boolean;
}): void;
declare namespace traverse {
export var stop: unique symbol;
var _a: typeof traverse;
export { _a as default };
}
export = traverse;