print-tree
Version:
prints any js data structure as a tree
67 lines (46 loc) • 1.52 kB
Markdown
prints any js data structure as a tree
```js
$ npm install print-tree
const printTree = require('print-tree');
const customTree = {
name: 'head',
children: [
{
name: 'branchA'
children: [
{ name: 'branchC' },
],
},
{ name: 'branchB' },
],
};
printTree(
customTree,
node => node.name.toUpperCase(),
node => node.children,
);
// HEAD
// ├─┬ BRANCHA
// | └── BRANCHC
// └── BRANCHB
```
`printTree(tree, [printNode], [getChildren])`
The object to traverse.
A function to customize the output.
You can pass in either:
- a function that takes the current node and returns the string representation.
- a function that takes the current node and the branchGraphic and returns nothing -
this lets you customize the ouput method
A function to help `print-tree` traverse custom data structures.
It takes the current head of the tree/sub-tree and returns a list of the children
<!-- Definitions -->
[]: https://img.shields.io/travis/alex-e-leon/print-tree.svg
[]: https://travis-ci.org/alex-e-leon/print-tree
[]: https://img.shields.io/codecov/c/github/alex-e-leon/print-tree.svg
[]: https://codecov.io/github/alex-e-leon/print-tree