
Product
A Fresh Look for the Socket Dashboard
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
A node module for creating tree data structure from text input
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
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.
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.Prepare an input.txt
file as above demonstrated.
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:
{
"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:
{
"root": [{
"node1": [{
"node11": null
}]
}, {
"node2": null
}]
}
Make sure mocha
is installed globally
npm install mocha -g
Run npm test
to run unit test
MIT
FAQs
A node module for creating a tree from text input
The npm package freetree receives a total of 4,522 weekly downloads. As such, freetree popularity was classified as popular.
We found that freetree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
Industry Insights
Terry O’Daniel, Head of Security at Amplitude, shares insights on building high-impact security teams, aligning with engineering, and why AI gives defenders a fighting chance.
Security News
MCP spec updated with structured tool output, stronger OAuth 2.1 security, resource indicators, and protocol cleanups for safer, more reliable AI workflows.