2013-03-15 204 views

回答

31

npm使用Unicode box drawing characters(U + 2500-2800)绘制树的漂亮线条。

要在您自己的应用程序中绘制类似的树,最好的路线可能是使用与npm本身使用的模块相同的模块– archy

var archy = require('archy'); 
var s = archy({ 
    label : 'beep', 
    nodes : [ 
    'ity', 
    { 
     label : 'boop', 
     nodes : [ 
     { 
      label : 'o_O', 
      nodes : [ 
      { 
       label : 'oh', 
       nodes : [ 'hello', 'puny' ] 
      }, 
      'human' 
      ] 
     }, 
     'party\ntime!' 
     ] 
    } 
    ] 
}); 
console.log(s); 

输出

beep 
├── ity 
└─┬ boop 
    ├─┬ o_O 
    │ ├─┬ oh 
    │ │ ├── hello 
    │ │ └── puny 
    │ └── human 
    └── party 
     time! 
0

你也使用console2它做几乎同样的事情archy做,但给你喜欢改进的堆栈跟踪,对象检查和更实用的附加功能:

enter image description here

Feature screenshot

披露:我仓库