Prettify and shape tree structures for printing
Topiary is a utility that shapes tree structures into a prettified format ala
It is used by npm-graph.
Given a tree structure and a key to recurse on, call topiary on that object:
var topiary = require'topiary';var tree =name: "root"deps:name : 'sub1'deps :name : 'sub2'deps : name : 'sub2sub' deps :name : 'sub3'deps :;console.logtopiarytree 'deps';
'deps' string is the key to recurse on, expected to hold an array of objects of the same structure.
A third options object can be supplied to topiary with the following key/value combinations:
If labelling by the default
name key is not working, you can supply your own labeller:
varreturn '#' + objname; // combine stuff from object into a sensible string;console.logtopiarytree 'deps' name: namer ;
You can optionally pass in a function to help filter certain branches or leaf nodes:
varreturn elname !== 'sub2';;console.logtopiarytree 'deps' filter: isNotSub2 ;
You can ask topiary to sort the
recurseName array before starting to work on it. This solves non-deterministic outputs sometimes produced if it is generated in a non-deterministic manner:
console.logtopiarytree 'deps' label: namer sort: true ;
Note that sorting is done lexicographically based on the labels output by the label functions.
$ npm install topiary
$ npm test
MIT-Licensed. See LICENSE file for details.