1.2.3 • Published 5 years ago

fast-totree v1.2.3

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

fast-totree

Installation

$ npm install fast-totree --save

Usage

require('fast-totree');

let list = [

  {id:1,name:'max1',parentId:0},
  {id:2,name:'max2',parentId:0},
  {id:3,name:'max3',parentId:1},
  {id:4,name:'max4',parentId:1},
  {id:5,name:'max5',parentId:2},
];

//如果数据格式与上述一致,比较键为id、parentId
let tree = list.toTree();

//如果不一致,则重置配置文件,示例数据格式 {_id:1,name:'max',_pid:0}
const config = {

    key:'_id',
    pid:'_pid',        
    chidren:'_chidren',
    value:'0'
}

let tree2 = list.toTree(config);

/*
 * Output:
 *
 * item 0
 *   item 2 
 *   item 3
 * item 1
 *   item 4
 */

性能测试

name1千条1万条10万条50万条
fast-totree1ms15ms95ms450ms
array-to-tree9ms溢出溢出溢出
totree2ms溢出溢出溢出
performant-array-to-tree1ms10ms103ms500ms
list-to-tree26ms溢出溢出溢出
1.2.3

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago