# danae

> A very simple Tree data structure implementation

Latest version **1.0.0** (published 2023-10-20) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-10-20 |
| First published | 2023-10-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Andrea Storace |
| Maintainers | phibonachos |
| Keywords | tree |

## Links

- npm: https://www.npmjs.com/package/danae
- Repository: https://github.com/rollingflamingo/driadi.git#main
- Homepage: https://github.com/rollingflamingo/driadi/tree/main/packages/driadi
- Issues: https://github.com/rollingflamingo/driadi/issues
- Funding: https://ko-fi.com/phibonachos
- npm.io page: https://npm.io/package/danae

## Recent versions

- 1.0.0 (latest) — 2023-10-20

## README

# Driadi

Driadi is a small library that implements [The tree data structure](https://en.wikipedia.org/wiki/Tree_(data_structure))

## Usage
### Initialization
```ts
import Tree from "danae";

// creates a new empty Tree<string>
const hazel = new Tree();

// creates a new empty Tree<number>
const oak = new Tree<number>();

// deep copies a tree
const cypress: Tree = new Tree();
const juniper: Tree = Tree.from(cypress);
```
#### Tree literals (works with Tree\<string\> only)
Driadi uses a simple syntax to define trees:
```antlr
tree ::= node | tree "\n" node
node ::= node-position " : " node-payload
node-position ::= node-label node-label | node-label
node-payload ::= string
node-label ::= string
string ::= char | string char+
char ::= [A-Za-z0-9]
```
Or something like this, my BNF is a bit rusty, anyway, if you want to define a tree as a literal you can do it like this:
```typescript
const tree = Tree.treeLit`parent : this represent a parent node
parent child : this represent a child node
parent sibling : this represent a sibling node
`;
```
or like this:
```typescript
const myTree = `parent : this represent a parent node
parent child : this represent a child node
parent sibling : this represent a sibling node
`;
const tree = Tree.parse(myTree);
```
or like this:
```typescript
const myTree = `parent : this represent a parent node
parent child : this represent a child node
parent sibling : this represent a sibling node
`;
const tree = new Tree();
tree.load(myTree);
```

Why so many methods? I was bored at home.
## Methods

### insert
```typescript
const juniper = { label: "juniper", payload: "coniferous trees and shrubs in the genus Juniperus" };
const cypress = { label: "cypress", payload: "common name for various coniferous trees or shrubs" };

const tree = new Tree();
tree.insert(juniper); // adds a child node labeled juniper to root node
tree.insert(cypress, juniper.label); // adds a node labeled cypress to juniper node
```

### remove
```typescript
const juniper = { label: "juniper", payload: "coniferous trees and shrubs in the genus Juniperus" };
const cypress = { label: "cypress", payload: "common name for various coniferous trees or shrubs" };

const tree = new Tree();
tree.insert(juniper);
tree.insert(cypress, juniper.label);

const removed = tree.remove(junper.label); // returns remove node
```

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