Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ascii-tree

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ascii-tree - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

5

ascii-tree.js

@@ -9,3 +9,6 @@ var freetree = require('freetree');

var levels = [];
var tree = freetree.parse(str);
var settings = {
leadingChar: str[0]
};
var tree = freetree.parse(str, settings);
return _generate(tree, true, levels);

@@ -12,0 +15,0 @@ }

4

package.json
{
"name": "ascii-tree",
"version": "0.2.0",
"version": "0.3.0",
"description": "A node module for generating a text tree in ASCII",

@@ -27,3 +27,3 @@ "main": "ascii-tree.js",

"dependencies": {
"freetree": "0.2.0"
"freetree": "0.2.2"
},

@@ -30,0 +30,0 @@ "devDependencies": {

@@ -8,7 +8,28 @@ ascii-tree

Editing an ASCII tree manually is not easy, the [freetree](https://github.com/liushuping/freetree) module provides an easy way for creating in-memory tree data structure from simple bullet items. This [ascii-tree](https://github.com/liushuping/ascii-tree module leverages) module leverages [freetree](https://github.com/liushuping/freetree) and outputs formatted tree in ascii characters.
This module generates an ascii tree representation for a given string bullet list.
## Code Example
Prepare an input file (input.txt) using bullets representing a tree e.g.
## 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(str);
```
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(str);
```
The line break charachters `\r\n` are required.
## Generate from an input file
First prepare an input file using bullets representating a tree
```
#root node

@@ -19,4 +40,4 @@ ##node1

```
and then process the file content with ascii-tree to generate the ascii tree.
```
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');

@@ -28,9 +49,3 @@ var asciitree = require('ascii-tree');

```
Then the output.txt will have below contents
```
root node
├─ node1
│ └─ node11
└─ node2
```
## Test

@@ -45,2 +60,2 @@ Make sure `mocha` is installed globally

## License
MIT
MIT

@@ -14,2 +14,8 @@ var assert = require('assert');

var inputs2 = [
'*root',
'*root\r\n**level1_1\r\n**level1_2\r\n**level1_3',
'*root\r\n**level1_1\r\n***level2_1\r\n**level1_2'
];
var outputs = [

@@ -28,2 +34,9 @@ 'root',

});
inputs2.forEach(function(input, index) {
it('should should accept different leading character when parsing trees for all input ' + index, function() {
var result = asciitree.generate(input);
assert.ok(result.trim() == outputs[index].trim());
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc