form-tree
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Tree-Util

Build tree with simple API.

Install

npm install form-tree

Usage

import { buildTree } from 'form-tree'

// This first element should not have parentId as it is the root of tree
const { addNode, tree, getNode } = buildTree([
  { id: 'root', someData: 'root node' },
  { id: 'foo', parentId: 'root' },
])
console.log(tree)
/*
  {
    id: 'root',
    someData: 'root node',
    children: [
      {
        id: 'foo',
        children: []
      }
    ]
  }
*/
console.log(getNode('foo'))
/*
  {
    id: 'foo',
    children: []
  }
*/

addNode({ id: 'baz', parentId: 'foo', data: 'new node' })
console.log(getNode('foo'))
/*
  {
    id: 'foo',
    children: [
      {
        id: 'baz',
        data: 'new node',
        children: []
      }
    ]
  }
*/

Readme

Keywords

Package Sidebar

Install

npm i form-tree

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

11 kB

Total Files

9

Last publish

Collaborators

  • plumbiu