1.0.1 • Published 7 years ago

list-to-tree2 v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

tree.js

Build tree from list using id key and parent key. Default id key value is _id, parent key - _parent

Install

Install with npm

npm install list-to-tree2

Install with yarn

yarn add list-to-tree2

Tests

npm test

Usage

Also you can open example.js to see usage

const listToTree = require('list-to-tree2');
const list = [{
			_id: 1,
			_parent: null,
			prop: 'qwerty',
		}, {
			_id: 2,
			_parent: 1,
			prop: 'asdfg',
		}, {
			_id: 3,
			_parent: null,
			prop: '13sdf',
		}];
    
const tree = listToTree(list);

Parameters

  • list - Array of objects with Id key and parentId key. Required
  • idKey - Name of id key in list elements. Default - _id
  • parentKey - Name of parentId key. Default - _parent
1.0.1

7 years ago

1.0.0

7 years ago