0.0.22 • Published 5 years ago
tree-utils v0.0.22
This lib provides some useful functionalities for tree operations. walk, buildTree and TreeAgent
buildTree
import { buildTree } from 'tree-utils'
const flatData = [
{ key: '0', parent: null },
{ key: '0-1', parent: '0' },
{ key: '0-1-0', parent: '0-1' },
{ key: '1', parent: null }
]
const tree = buildTree(flatData)The tree will be build as:
[{
key: '0',
parent: null,
children: [{
key: '0-1',
parent: '0',
children: [{
key: '0-1-0',
parent: '0-1',
children: null
}]
}]
}, {
key: '1',
parent: null,
children: null
}]You don't need to provide your flatData with fixed prop name like key, parent and children, you can have your own prop names, and use build options to let buildTree knows how to read the connection among nodes.
const flatData = [
{ _k: '0', _p: null },
{ _k: '0-1', _p: '0' },
{ _k: '0-1-0', _p: '0-1' },
{ _k: '1', _p: null }
]
const options = {
keyPropName: '_k', // default value is 'key'
parentPropName: '_p', // default value is 'parent'
childrenPropName: '_c' // default value is 'children'
}
const tree = buildTree(flatData, options)Tree will be build as:
[{
_k: '0',
_p: null,
_c: [{
_k: '0-1',
_p: '0',
_c: [{
_k: '0-1-0',
_p: '0-1',
_c: null
}]
}]
}, {
_k: '1',
_p: null,
_c: null
}]walk
TODO
TreeAgent
TreeAgent provides plenty of functions to do tree query and manipulation.
import { buildTree, TreeAgent } from 'tree-utils'
const tree = buildTree(yourFlatData)
const treeAgent = new TreeAgent(tree)TreeAgent API
TODO
0.0.22
5 years ago
0.0.21
5 years ago
0.0.20
5 years ago
0.0.19
5 years ago
0.0.18
5 years ago
0.0.17
5 years ago
0.0.16
5 years ago
0.0.15
5 years ago
0.0.14
7 years ago
0.0.13
7 years ago
0.0.12
7 years ago
0.0.10
7 years ago
0.0.9
7 years ago
0.0.8
7 years ago
0.0.7
7 years ago
0.0.6
7 years ago
0.0.4
7 years ago
0.0.3
7 years ago
0.0.2
7 years ago
0.0.1
7 years ago