Skip to content

briter06/tree-prettier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tree-prettier

Pretty print any tree-like structure. Only provide the functions to retrieve the value of a node and its child nodes.

Usage

import { prettierTree } from 'tree-prettier'

export type CustomNode = {
  value: string;
  children: CustomNode[];
};

const tree: CustomNode = {
  value: "Node1",
  children: [
    {
      value: "Node2",
      children: [
        {
          value: "Node4",
          children: [],
        },
      ],
    },
    {
      value: "Node3",
      children: [],
    },
  ],
};

console.log(prettierTree(tree, node => node.value, node => node.children))

This prints the following tree:

Node1
│─── Node2
│    └─── Node4
└─── Node3

The fourth argument of the prettierTree function is a configuration object, which ahs the following properties:

Option Type Default value
lengthOfEdge number 4

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published