Treeify

treeify

converts a JS object into a nice and readable tree structure for the console

Say, you an object that has the dependencies of a node module and you want to represent it as a tree structure or may you have a filesystem hierarchy to display on CLI, it's kina tough right? Well...here is treeify for you!

Get it: npm install treeify

Sample usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var treeify = require('treeify');

var deps = {
    "npm@2.1.12": {
        "archy@1.0.0": null,
        "abbrev@1.0.5": null,
        "char-spinner@1.0.1": null,
        "block-stream@0.0.7": "inherits@2.0.1"
    }
};

console.log(
   treeify.asTree(deps, true)
);

//or

treeify.asLines(deps, true, function(line){
  console.log(line);
});

Both would output:

1
2
3
4
5
└─ npm@2.1.12
   ├─ archy@1.0.0
   ├─ abbrev@1.0.5
   ├─ char-spinner@1.0.1
   └─ block-stream@0.0.7: inherits@2.0.1

GIF FTW:

treeify

Thanks to Luke Plaster for making our life a bit more easier on the CLI.

Suggest a module

Comments