Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/liushuping/ascii-tree
A node module for generating tree structure in ASCII
https://github.com/liushuping/ascii-tree
Last synced: 3 months ago
JSON representation
A node module for generating tree structure in ASCII
- Host: GitHub
- URL: https://github.com/liushuping/ascii-tree
- Owner: liushuping
- License: mit
- Created: 2014-07-15T04:28:01.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-12T08:29:22.000Z (over 8 years ago)
- Last Synced: 2024-11-03T10:34:14.248Z (3 months ago)
- Language: JavaScript
- Homepage: http://blog.liushuping.com/ascii-tree/
- Size: 29.3 KB
- Stars: 37
- Watchers: 4
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ascii - ascii-tree
README
ascii-tree
==========A node module for generating a text tree in ASCII
[![build status](https://travis-ci.org/liushuping/ascii-tree.svg)](https://travis-ci.org/liushuping/ascii-tree.svg)
This module generates an ascii tree representation for a given string bullet list.
## Generate for a given string bullet list.
```javascript
var asciitree = require('ascii-tree');
var input = '#root node\r\n##node1\r\n###\r\nnode1\r\n##node2';
var tree = asciitree.generate(input);
```
the output string `tree` will be in below representation
```
root node
├─ node1
│ └─ node11
└─ node2
```
The leading character is not necessary to be `#`, but can be any character, this is helpful to resolve the confliction between the leading character and actual content character.
```javascript
var asciitree = require('ascii-tree');
var input = '*root node\r\n**node1\r\n***\r\nnode1\r\n**node2';
var tree = asciitree.generate(input);
```
The line break characters `\r\n` are required.## Generate from an input file
First prepare an input file using bullets representating a tree
```
#root node
##node1
###node11
##node2
```
again, the leading character is not necessary to be `#` but can be any character. Then process the file content with ascii-tree to generate the ascii tree
```javascript
var fs = require('fs');
var asciitree = require('ascii-tree');
var str = fs.readFileSync('input.txt', 'utf8');
var tree = asciitree.generate(str);
fs.writeFile('output.txt', tree, 'utf8');
```## Test
Make sure `mocha` is installed globally
```
npm install mocha -g
```
Run `npm test` to run unit test
## Dependencies
ascii-tree uses [freetree](https://github.com/liushuping/freetree) for creating tree data structure from inputting text
## License
MIT