GitHub

@liuli-util/tree

Install using

npm install @liuli-util/tree

Exported Members

You can access these members by importing the module:

import { member } from '@liuli-util/tree';

treeEach

function treeEach < T : object , C : TreeOption<T> > (
   nodeList : T[] ,
   fn : (t: T, path: T[C['id']][]) => void ,
   options : C
) : any

树结构映射 使用深度优先算法

@param:

nodeList

@param:

fn

@param:

options

treeToList

function treeToList < T : object , C : TreeOption<T> & { path: string } , R : T & { [K in C['path']]: NonNullable<T[C['id']]>[] } > (
   nodeList : T[] ,
   options : C
) : R[]

将一个树节点列表压平

@param:

nodeList

@param:

options

treeMap

function treeMap < T : object , C : TreeOption<T> , F : ( t: Omit<T, C['children']> & Record<C['children'], ReturnType<F>[]>, path: T[C['id']][], ) => object > (
   nodeList : T[] ,
   fn : F ,
   options : C
) : ReturnType<F>[]

树结构映射 使用深度优先算法

@param:

nodeList

@param:

fn

@param:

options

treeFilter

function treeFilter < T : object , C : TreeOption<T> > (
   nodeList : T[] ,
   fn : (t: T, path: T[C['id']][]) => boolean ,
   options : C
) : T[]

过滤一个树节点列表

@param:

nodeList

@param:

fn

@param:

options

listToTree

function listToTree < T : object , C : Pick<TreeOption<T>, 'id'> & { parentId: keyof T children: string & keyof R } , R : ReType<T, C['children']> > (
   list : T[] ,
   options : C
) : R[]

将列表转为树

@param:

list

@param:

options