@nextgis/tree
TypeScript icon, indicating that this package has built-in type declarations

2.3.0 • Public • Published

Tree

size version

Utilities to simplify interaction with tree data structures

Installation

# latest stable
npm install @nextgis/tree

General form for each tree function

treeFunc(item | item[], actionFunc, relationFunc | childrenParamName)

Usage

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;

Commercial support

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!

http://nextgis.com

Readme

Keywords

Package Sidebar

Install

npm i @nextgis/tree

Weekly Downloads

34

Version

2.3.0

License

MIT

Unpacked Size

150 kB

Total Files

21

Last publish

Collaborators

  • rendrom
  • maximdubinin
  • karavanjo