tp

tree-printer

CLI tool to pretty print a tree generated from a collection (array of objects)

Showing:

Popularity

Downloads/wk

10

GitHub Stars

2

Maintenance

Last Commit

5yrs ago

Contributors

1

Package

Dependencies

2

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

tree-printer

CLI module to pretty print a tree generated from a collection (array of objects).

Example

var treePrinter = require('tree-printer

console.log(treePrinter([
    {
        name: 'Foo',
        children: [
            {name: 'Foo-Foo'},
            {name: 'Foo-Bar'},
            {name: 'Foo-Baz'},
        ],
    },
    {
        name: 'Bar',
        children: [
            {name: 'Bar-Foo'},
            {name: 'Bar-Bar'},
            {
                name: 'Bar-Baz',
                children: [
                    {name: 'Bar-Baz-Foo'},
                    {name: 'Bar-Baz-Bar'},
                    {name: 'Bar-Baz-Baz'},
                ],
            },
        ],
    },
    {
        name: 'Baz',
        children: [
            {name: 'Baz-Foo'},
            {name: 'Baz-Bar'},
            {name: 'Baz-Baz'},
        ],
    },
]));

Outputs:

Options

The main treePrinter(tree, options) function takes the collection and an object of options which can be any, all or none of the following:

OptionTypeDefaultDescription
depthNumber0Initial depth of the tree (auto-computed during recursion)
depthsArray[false]Whether each of the depths is on the last item - used to draw the correct '*last' formatter (auto-computed during recursion)
formatObjectsee belowObject of various formatters
format.rootString'┬'Formatter to use when drawing the root node
format.branchNoChildrenString'├── {{name}}'Formatter to use when drawing a branch that has no children
format.branchChildrenString'├─┬ {{name}}'Formatter to use when drawing a branch that has children
format.branchNoChildrenLastString'└── {{name}}'Formatter to use when drawing a branch that has no children and is also the last of the set
format.branchChildrenLastString'└─┬ {{name}}'Formatter to use when drawing a branch that has childre and is also the last of the set
format.depthString'│ 'Formatter to use when drawing a depth marker
format.depthLastString' 'Formatter to use when drawing a depth marker that is also the last of a set
format.eolString'\n'Formatter to use to end a line output
fieldsObjectsee belowObject to indicate which fields should be used during formatting
fields.nameString or Function'name'Which field to draw the nodes name from. If this is a function its called as callback(branch) for each branch and expected to return a string
fields.childrenString'children'Which field to draw the nodes childrens from. This should be an array
autoPrintBooleanfalseWhether to invoke console.log automatically when finished

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial