tree-to-string

Convert a tree structure into a human friendly string

  • Owner: mafintosh/tree-to-string
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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

Main metrics

Overview
Name With Ownermafintosh/tree-to-string
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2018-06-20 11:50:27
Pushed At2018-06-21 13:31:01
Last Commit At2018-06-21 15:30:30
Release Count3
Last Release Namev1.1.1 (Posted on 2018-06-21 15:30:30)
First Release Namev1.0.0 (Posted on 2018-06-20 13:50:45)
用户参与
Stargazers Count121
Watchers Count3
Fork Count5
Commits Count7
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count1
Pull Requests Open Count0
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private