Library exposing a Tree object with parent and child relationship.

Usage no npm install needed!

<script type="module">
  import varatnarOikosDoru from 'https://cdn.skypack.dev/@varatnar/oikos-doru';


Oikos Doru

build codecov

Oikos doru, simplification of ancient greek meaning family tree.

This library exposes an object that contains any type of data and can have parent-child relationships. It is also iterable and contains some utility functions.


Create a new container with the data that you want associated with it.

const container = new TreeElement("content");

You can add children to this container.

container.addChild(new TreeElement("otherContent"));

You can retrieve the children of a container.


You can clear the children of a container.


You can access the parent of a child.


You can retrieve the data of a container.


It is also possible to attempt to cast it (may cause an exception).

const container = new TreeElement<string | number>("text");

container.getData<string>().includes("text"); // true and typescript will not complain

You can check if the container is the root (has no parent).


You can print the string value of the container (which is the string value of its data)


The container is iterable by default, it will iterate through the children. The iteration goes through every child as if it was all a pile.

for (const child of container) {
    // do something with child

container.foreach(child => {
   // do something with child

Example :

const container = new TreeElement("content");
const childOne = container.addChild("data 1");
const childTwo = container.addChild("data 2");
const childOneOne = childOne.addChild("data 1 1");

container.forEach(child => console.log(child.toString());

// data 1
// data 1 1
// data 2



  1. Run the yarn command to install all the dependencies.

       $ yarn
  2. Build the project by calling yarn build

       $ yarn build

The built artifacts are available at projectRoot/bin


  1. Run the tests by calling yarn test

       $ yarn test