Skip to content

BigBrainAFK/simple-text-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

text-tree

Description

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.

Example output

├─ 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

Installation can simply be done via npm npm i simple-text-tree

Usage

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

Tiny documentation

The function treeView takes 1 required and 2 optional arguments.

tree: treeNode[] (required)

This is the only required argument and consists of an array of treeNode elements.

indent: string = '' (optional)

This is the indent argument and can be used to add a custom indent yourself that gets added infront of the tree.

showLines: boolean = true (optional)

This can be used to disable drawing the tree lines which causes the tree to be made up of pure whitespace indents.

License

Apache 2

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published