/** * 用于遍历的节点接口 */ export interface INode { children?: Array; [prop: string]: any; } /** * 用于遍历的节点信息 */ export interface INodeInfo { node: T; parent?: T; stack?: Array; nodePath?: string; jsonPath?: string; index?: number; key?: string | number; } export interface TraverseOptions { mode?: 'onlyChildren' | 'onlyArray' | 'anyObject'; depthFirst?: boolean; excludedKeySet?: Set; } /** * 遍历树 * @param func * @param init 初始点信息 * @param options.mode 'onlyChildren' 表示只向下遍历 children 的元素(默认);'onlyArray' 表示只向下遍历 Array 的元素;'anyObject' 表示只要属性为 Object 类型都会遍历 * @param options.depthFirst 默认广度优先搜索,是否深度优先搜索 * @example traverse((current) => console.log(current.node.name), { init: rootNode }); * @example traverse((current) => console.log(current.jsonPath), { init: ast }, { mode: 'anyObject' }); */ export declare function traverse(func: (current: INodeInfo) => any, init: INodeInfo, options?: TraverseOptions): any; export default traverse;