un-flatten-tree
A small module for converting trees to lists and vice versa. Can be used in browser and Node.
Installation
$ npm i un-flatten-tree
Usage
flatten
Converts tree to list.
var uft = ; var tree = name: 'A' items: name: 'B' name: 'C' name: 'D' items: name: 'E' items: ; var list = uft;
list
should be ['A', 'B', 'C', 'D', 'E']
unflatten
Converts list to tree.
var uft = ; var list = id: 1 pid: null id: 2 pid: null id: 3 pid: 2 id: 4 pid: 3 id: 5 pid: 4; var tree = uft;
tree
should be
id: 1 items: id: 2 items: id: 3 items: id: 4 items: id: 5 items:
More complex examples of usage can be found in tests
folder.
Typescript
This module also contains type declarations.
; // or ;