npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

simple-tree-structure

v1.2.2

Published

Create simple tree structure by predefined json data object

Readme

About The Project

First of all i wanna say that this readme file will be updated as soon as I can.

STS library allows you to present fast data tree structures with basic functionalities. It is easy to use and stylize.

Built With

  • JavaScript
  • TypeScript

Getting Started

Installation

  1. Install NPM packages
     npm i simple-tree-structure@latest -g

Usage

As i said earlier STS is easy to use. If you are going to use this library in React/Angular/VueJs project you just need to import it like this in your file:

import { buildTree, getSelectedChildElements } from 'simple-tree-structure/src/simple-tree-structure';

buildTree() accepts 6 parameters:

  1. treeModel - the data we are going to populate our tree with. Here is a sample of how the json model must look like:
{
   "treeModel":[
      {
         "id":1,
         "parentId":0,
         "description":"___1___ Parent",
         "children":[
            {
               "id":2,
               "parentId":1,
               "description":"___1___ Firstborn Child",
               "children":[
                  {
                     "id":3,
                     "parentId":2,
                     "description":"___1___ Firstborn Grand Child",
                     "children":[
                        {
                           "id":4,
                           "parentId":3,
                           "description":"___1___ Firstborn Grand Grand Child",
                           "children":[]
                        },
                        {
                           "id":5,
                           "parentId":3,
                           "description":"___1___ Second-born Grand Grand Child",
                           "children":[]
                        }
                     ]
                  }
               ]
            },
            {
               "id":6,
               "parentId":2,
               "description":"___1___ Second-born Child",
               "children":[]
            }
         ]
      },
      {
         "id":7,
         "parentId":0,
         "description":"___2___ Parent with one child",
         "children":[
            {
               "id":9,
               "parentId":7,
               "description":"___2___ Firstborn Child",
               "children":[]
            }
         ]
      }
   ]
}
  1. rootElementId - this is the id of the html element that is going to 'hold' our STS. In other words this is where we are going to 'paint' it.

  2. isDefaultView - defines whether our STS will be displayed exanded or not.

  3. isParentDescBold - defines whether the description if the element that has children will be displayed as bold.

  4. descriptionSpanClass - this allows you to add your own style to the span element that represents the description part in our STS element.

  5. checkboxClass - this allows you to add your own style to checkbox element.

After we learned this we prepare the container for our STS. In this case the ul element with id='treeRoot' will be our container.

	<h2>Simple Tree Structure</h2>
    <ul id='treeRoot'></ul>
	

The last step is to call buildTree(treeModel, rootElementId, isDefaultView, isParentDescBold, descriptionSpanClass, checkboxClass) with your parameters.

buildTree(treeModel, 'treeRoot', true, true, someStyle, someStyle);

And finally if we want to get the selected elements in our STS we can just call

getSelectedChildElements()

OR

getEverySelectedElement()

depends on which elements we want to get. This functions return the id and description of selected elements.

STS with isDefaultView parameter set to 'true': alt text

STS with isDefaultView parameter set to 'false': alt text

Contact

Aleksandar Datsov - [[email protected]]

Project Link: https://github.com/AleksandarDatsov/simple-tree-structure/tree/master