What is archy?
The 'archy' npm package is used to generate ASCII trees, which are useful for visualizing hierarchical data structures in a text-based format. It is simple to use and can be integrated into various Node.js applications to display tree structures in a readable manner.
What are archy's main functionalities?
Basic Tree Structure
This feature allows you to create a basic tree structure with a root node and child nodes. The code sample demonstrates how to create a tree with a root labeled 'root', a direct child 'leaf1', and a branch 'branch1' with its own children 'leaf2' and 'leaf3'.
const archy = require('archy');
const tree = archy({
label: 'root',
nodes: [
'leaf1',
{
label: 'branch1',
nodes: [
'leaf2',
'leaf3'
]
}
]
});
console.log(tree);
Nested Tree Structure
This feature allows you to create more complex, nested tree structures. The code sample demonstrates a tree with multiple levels of branches and leaves, showing how to nest nodes within other nodes.
const archy = require('archy');
const tree = archy({
label: 'root',
nodes: [
{
label: 'branch1',
nodes: [
{
label: 'sub-branch1',
nodes: [
'leaf1',
'leaf2'
]
},
'leaf3'
]
},
'leaf4'
]
});
console.log(tree);
Custom Node Labels
This feature allows you to customize the labels of each node in the tree. The code sample demonstrates a tree with a root node labeled 'root' and two branches 'branch1' and 'branch2', each with their own leaves.
const archy = require('archy');
const tree = archy({
label: 'root',
nodes: [
{ label: 'branch1', nodes: ['leaf1'] },
{ label: 'branch2', nodes: ['leaf2', 'leaf3'] }
]
});
console.log(tree);
Other packages similar to archy
cli-tree
The 'cli-tree' package is another tool for generating ASCII trees in the command line. It offers similar functionality to 'archy' but with a focus on command-line usage and additional customization options for tree appearance.
asciitree
The 'asciitree' package provides a way to create ASCII tree diagrams from nested data structures. It is similar to 'archy' but offers more flexibility in terms of input data formats and customization of the tree output.
treeify
The 'treeify' package converts JavaScript objects into a tree structure. It is similar to 'archy' but focuses on converting complex objects into a readable tree format, making it useful for debugging and data visualization.
archy
Render nested hierarchies npm ls
style with unicode pipes.
example
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);
output
beep
├── ity
└─┬ boop
├─┬ o_O
│ ├─┬ oh
│ │ ├── hello
│ │ └── puny
│ └── human
└── party
time!
methods
var archy = require('archy')
archy(obj, prefix='', opts={})
Return a string representation of obj
with unicode pipe characters like how
npm ls
looks.
obj
should be a tree of nested objects with 'label'
and 'nodes'
fields.
'label'
is a string of text to display at a node level and 'nodes'
is an
array of the descendents of the current node.
If a node is a string, that string will be used as the 'label'
and an empty
array of 'nodes'
will be used.
prefix
gets prepended to all the lines and is used by the algorithm to
recursively update.
If 'label'
has newlines they will be indented at the present indentation level
with the current prefix.
To disable unicode results in favor of all-ansi output set opts.unicode
to
false
.
install
With npm do:
npm install archy
license
MIT