tree-to-string
Convert a tree structure into a human friendly string
Last updated 8 years ago by mafintosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install tree-to-string 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.1                                ...           latest (8 years ago)

3 Versions

  • 1.1.1                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Total 10
Today 0
This Week 0
This Month 6
Last Day 0
Last Week 0
Last Month 2
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE