All Projects → mafintosh → Tree To String

mafintosh / Tree To String

Licence: mit
Convert a tree structure into a human friendly string

Programming Languages

javascript
184084 projects - #8 most used programming language

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].