Generates easy to follow text trees for use in terminals and other text based outputs. This project was inspired by dlid/text-treeview but I needed a functional TS compatible module.
├─ Girls
│ ├─ Anna
│ ├─ Lana
│ │ ├─ Branda
│ │ └─ Mai
│ │ └─ Therisa
│ │ └─ Tamala
│ ├─ Lisa
│ └─ Bea
└─ Boys
├─ Kalle
├─ Åre
└─ Asgar
The input for that object looks as follows
[
{
text: 'Girls',
children: [
{
text: 'Anna'
},
{
text: 'Lana',
children: [
{
text: 'Branda',
},
{
text: 'Mai',
children: [
{
text: 'Theresia',
children: [
{
text: 'Tamala'
}
]
}
]
}
]
},
{
text: 'Lisa'
},
{
text: 'Bea'
}
]
},
{
text: 'Boys',
children: [
{
text: 'Kalle'
},
{
text: 'Åre'
},
{
text: 'Asgar'
}
]
}
]
Installation can simply be done via npm
npm i simple-text-tree
A basic example looks as follows
import { treeView } from 'simple-text-tree';
const sample = [
{
text: 'Node1'
children: [
{
text: 'inner Node2'
}
]
}
];
console.log(treeView(sample));
which prints the following
└─ Node1
└─ inner Node2
The function treeView
takes 1 required and 2 optional arguments.
This is the only required argument and consists of an array of treeNode elements.
This is the indent argument and can be used to add a custom indent yourself that gets added infront of the tree.
This can be used to disable drawing the tree lines which causes the tree to be made up of pure whitespace indents.
Apache 2