
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
This library is meant to be used for creating and manipulating tree-node structures.
The API is designed with ease of use in mind, hence the name Treesy (Tree + Easy - get it? 😂 - I'm sorry).
I created it for a side project I'm working on because I couldn't find a library that has a simple API and is "just" for creating tree structures. Oh and it doesn't have any dependencies :)
Warning! The API is not final and is most likely to change!
yarn add treesy
npm install treesy
Or through a CDN
<script src="https://unpkg.com/treesy"></script>
import { Tree } from "treesy";
const tree = new Tree();
tree.add({ name: "bob" });
console.log(tree.toJson());
[
{
"id": "UUID",
"parentId": null,
"data": {
"name": "bob"
},
"children": []
}
]
tree.add("MY_UNIQUE_ID", { name: "bob" });
console.log(tree.toJSON());
[
{
"id": "MY_UNIQUE_ID",
"parentId": null,
"data": {
"name": "bob"
},
"children": []
}
]
Creates the tree.
You can pass an array of JsonNode's to create a tree with default data. It can be done like this:
const jsonTree = [
{
id: "MY_ID",
data: {
greeting: "Hello",
},
children: [],
},
];
const tree = new Tree(jsonTree);
console.log(tree.toJson()[0].id); // MY_ID
The internal tree itself but exposed.
This is used to add a root node.
Used to search the whole tree for a given node based on the search criteria.
SearchCriteria - There are 3 possible ways to use the search criteria.
data property of the Node. It does a subset comparison therefore the whole data object doesn't have to match exactly, only a subset of the fields.current node.The callback can be used like this:
const node = tree.find(
node => node.data.count === 2)
);
SearchOptions - possible options include:
export type SearchOptions = {
deep?: boolean;
};
If deep is set to tree, the finder will do a recursive search. If it's false, it'll only look at the direct children of the tree (root nodes). The default value is true
Node - Used to set the "from" point on the search. If a node is passed, it'll start the search from there and search its children only.
Generates a JSON representation of the tree.
Creates the new node.
Return the ID of the node
Return the parent ID of the node. Can be null if it's a root node or if it's not part of a tree object yet.
Data object of the node. Can be used to store anything such as state.
Node's children.
The tree itself. This can be a quick way to access the methods on the tree object.
Return the direct parent of a given Node.
Same as the add method on the Tree but this time, you are adding a new node as a child of the current node.
Same as the find method on the Tree but without the Node argument.
Changes the data object of the current Node. This method overrides the current data object so make sure you use something like Object.assign if you don't want to lose any data.
This method can be used if you want to move the current node somewhere else in the tree. criteria works exactly the same as find but this time, you want to use this to find the target node - so the node that you want your current node to be a child of. If you wanted to move it to the root of the tree, you can pass root as the criteria (Note: this is not possible on the find method).
By default, the moved node is added at the bottom of the children but if you wanted to target a specific index in the children's array, you can pass it as the second argument.
This can be used like this:
const rootNode = tree.add({ greeting: "hello" });
const childNode = rootNode.add({ greeting: "hi" });
childNode.move("root");
Can be used to remove the node completely.
const rootNode = tree.add({ greeting: "hello" });
rootNode.remove();
Generates a JSON representation of the node and it's children.
FAQs
An API for creating and manipulating tree-node structures
We found that treesy 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.