# freetree

> A node module for creating a tree from text input

Latest version **0.2.2** (published 2015-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install freetree
pnpm add freetree
yarn add freetree
bun add freetree
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2015-06-23 |
| First published | 2014-07-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Shuping LIU |
| Maintainers | liushuping |
| Keywords | tree, text, ascii, structure, javascript, node |

## Links

- npm: https://www.npmjs.com/package/freetree
- Repository: https://github.com/liushuping/freetree
- Issues: https://github.com/liushuping/freetree/issues
- npm.io page: https://npm.io/package/freetree

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2015-06-23
- 0.2.1 — 2014-07-24
- 0.2.0 — 2014-07-23
- 0.1.1 — 2014-07-16
- 0.1.0 — 2014-07-16

## README

freetree
========

A node module for creating tree data structure from text input

[![build status](https://travis-ci.org/liushuping/freetree.svg)](https://travis-ci.org/liushuping/freetree.svg)

This module takes a simplified tree structured input string and build a JavaScript tree object in memory. 

A simple tree structured input string (input.txt) example:
```
#root node
##node1
###node11
##node2
```
It illustrates a tree as below:
```
root node
 |-- node1
 |    |--node11
 |-- node2
```
## Conventions
Each line represents a node in the tree, it should begins with the leading character (default is \#). The count of leading chracters minus 1 is the level of the node. There should be only 1 root node which has only 1 leading character, and it should be at the first line of the input string.

## Usage
```javascript
var freetree = require('freetree');
var tree = freetree.parse(str, settings);
```
**`settings`** has below listed properties
* `leadingChar`: optional, defines leading character for the tree, defaulted to '#' 
* `compact`: optional, output the object in compact mode.

## Code examples
Prepare an `input.txt` file as above demonstrated.
```JavaScript
var fs = require('fs');
var freetree = require('freetree');
var str = fs.readFileSync('input.txt', 'utf8');
var tree = freetree.parse(str);
```
then, the `tree` object is an in-memory JavaScript object. In this example, the object is in structure:
```JavaScript
{
    "level": 0,
    "value": "root",
    "nodes": [{
        "level": 1,
        "value": "node1",
        "nodes": [{
            "level": 2,
            "value": "node11"
        }]
    }, {
        "level": 1,
        "value": "node2"
    }]
}
```
If the `compact` option is set to `true`, the object will be compressed in below structure:
```javascript
{
    "root": [{
        "node1": [{
            "node11": null
        }]
    }, {
        "node2": null
    }]
}
```

## Test
Make sure `mocha` is installed globally
```
npm install mocha -g
```
Run `npm test` to run unit test
## License
MIT

---
_Source: https://npm.io/package/freetree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
