# fast-totree

> fast list to tree O(N)

Latest version **1.2.3** (published 2020-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install fast-totree
pnpm add fast-totree
yarn add fast-totree
bun add fast-totree
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2020-05-21 |
| First published | 2020-05-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | leastcoding |
| Maintainers | leastcoding |
| Keywords | O(N), fast, array, list, to, tree |

## Links

- npm: https://www.npmjs.com/package/fast-totree
- Repository: https://github.com/newthing/fast-totree
- Homepage: https://github.com/newthing/fast-totree#readme
- Issues: https://github.com/newthing/fast-totree/issues
- npm.io page: https://npm.io/package/fast-totree

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.2.3 (latest) — 2020-05-21
- 1.2.1 — 2020-05-20
- 1.2.0 — 2020-05-20
- 1.1.9 — 2020-05-20
- 1.1.8 — 2020-05-20
- 1.1.7 — 2020-05-20
- 1.1.6 — 2020-05-20
- 1.1.5 — 2020-05-20
- 1.1.4 — 2020-05-20
- 1.1.3 — 2020-05-20
- 1.1.2 — 2020-05-20
- 1.1.1 — 2020-05-20
- 1.1.0 — 2020-05-20
- 1.0.2 — 2020-05-20
- 1.0.1 — 2020-05-20
- … 1 more at https://npm.io/package/fast-totree/versions

## README

# fast-totree


## Installation

```bash
$ npm install fast-totree --save
```

## Usage

```js

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
 */
```


## 性能测试
|name|1千条|1万条|10万条|50万条|
|:-|:-:|-:|-:|-:|
|fast-totree|1ms|15ms|95ms|450ms|
|array-to-tree|9ms|溢出|溢出|溢出|
|totree|2ms|溢出|溢出|溢出|
|performant-array-to-tree|1ms|10ms|103ms|500ms|
|list-to-tree|26ms|溢出|溢出|溢出|

---
_Source: https://npm.io/package/fast-totree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
