2013-03-15 205 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

披露:我倉庫