Utilities to simplify interaction with tree data structures
# latest stable
npm install @nextgis/tree
General form for each tree function
treeFunc(item | item[], actionFunc, relationFunc | childrenParamName)
import { treeFilter, treeFind, treeSome, treeEvery } from '@nextgis/tree';
const tree = [
{
name: 'A',
children: [{ name: 'A-a' }, { name: 'A-b', children: [{ name: 'A-b-1' }] }],
},
{
name: 'B',
children: [{ name: 'B-a' }, { name: 'B-b' }],
},
];
// 'children' - is default relation name, this param may be ignored in this case
treeFilter(tree, (item): item.name !== 'A', 'children').map((item) => item.name); // ['B', 'B-a', 'B-b']
treeFind(tree, (item)=> item.name === 'A-b-1', (item) => item.children); // {name: 'A-b-2'}
treeFind(tree, (item)=> item.name === 'A-b-2'); // undefined
treeSome(tree, someFunction, relationFunction | childrenParamName): boolean;
treeEvery(tree, everyFunction, relationFunction | childrenParamName): boolean;
Need to fix a bug or add a feature to @nextgis/tree
? We provide custom development and support for this software. Contact us to discuss options!