Need help with tree-to-string?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

mafintosh
122 Stars 5 Forks MIT License 7 Commits 0 Opened issues

Description

Convert a tree structure into a human friendly string

Services available

!
?

Need anything else?

Contributors list

tree-to-string

npm install tree-to-string

Usage

const treeToString = require('tree-to-string')

const tree = { value: [7], children: [{ value: [3, 5], children: [{ value: [2] }, { value: [4] }, { value: [6] }] }, { value: [8] }] }

console.log(treeToString(tree))

Running the above prints something similar to

[ 2 ]─┐
      │
[ 4 ]─┼─[ 3, 5 ]─┐
      │          │
[ 6 ]─┘          ├─[ 7 ]
                 │
           [ 8 ]─┘

API

const str = treeToString(tree, [format])

Converts a tree to a human friendly string. The tree should have a layout similar to this

{
  value: someJsObject,
  children: [tree, ...]
}

Format defaults to

util.inspect
. Change this to your own method that pretty prints your object if your prefer.

License

MIT

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.