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 🙏

© 2024 – Pkg Stats / Ryan Hefner

objectree

v1.1.1

Published

Objectree is a javascript node.js module that can convert a javascript or JSON object to a tree and access as a tree structure.

Downloads

4

Readme

objectree

NPM version Downloads apache license

About

Objectree is a javascript node.js module that can convert a javascript or JSON object to a tree and access as a tree structure.

Installation

npm install objectree

Usage

var objectree = require("objectree");

var obj = {
  "a": "test",
  "b": true,
  "c": 20,
  "d": {
    "e": {
      "f": "test_a",
      "g": "test_b"
    }
  }
};

var fullTree = objectree.createTree(obj);
.....

Features

  • A tree structure is created from javascript/json object.
  • tree is a node that contains child and parent concept
  • Loop through the structure with child and parent facilities.
  • Represent a Tree structured node.

Documentation

Methods


createTree()

Create a tree node of the given obj to have the tree structure

Arguments

  • obj - A javascript object that is need to be converted to tree structure.

Returns

  • Tree object

Examples

// obj -> is a javascript object.

var treeObject = objectree.createTree(obj);

newNode()

Explicitly create a new Node to add or remove.

Arguments

  • void

Returns

  • Node

Examples

var newNode = objectree.newNode();

hasChild()

To check if the object has any child

Arguments

  • void

Returns

  • true or false

Examples

var hasChild = treeObject.hasChild();

hasAttribute()

To check if the object has any attributes

Arguments

  • void

Returns

  • true or false

Examples

var hasAttribute = treeObject.hasAttribute();

getName()

Get name of the current node.

Arguments

  • void

Returns

  • string name

Examples

var name = treeObject.getName();

addChild()

Add a node to current node child list

Arguments

  • Node to add as a child

Returns

  • void

Note

  • Get a child from node or create a node with objectree.newNode()

Examples

test.addChild(treeObject.getFirstChild()); 

getChilds()

Get all childs list of current node.

Arguments

  • void No argument

Returns

  • child list

Examples

var childs = test.getChilds(); 

getFirstChild()

Get first child of current node.

Arguments

  • void

Returns

  • Node first child or null

Examples

var firstChild = test.getFirstChild(); 

getChildByIndex()

Get child by index number

Arguments

  • number 0 based

Returns

  • Node child of given index or 'null'

Examples

var child = test.getChildByIndex(2); 

addAttribute()

Add attribute to current node.

Arguments

  • Array or String or Number
  • Object and function are not supported

Returns

  • void

Examples

test.addAttribute('abcd'); 

getAttribute()

Add a node to current node child list

Arguments

  • void

Returns

  • attribute list or null

Examples

var attributes = test.getAttribute(); 

setParent()

Set parent of current node explicitly. ( Not suggested )

Arguments

  • Node

Returns

  • void

Examples

var newParent = objectree.newNode();
treeObject.setParent(newParent);

getParent()

Get parent node of current node.

Arguments

  • void

Returns

  • parent Node or null

Examples

var parent = treeObject.getParent();

setValue()

Set value of current node.

Arguments

  • String or Boolean or Number
  • function and Object is not supported

Returns

  • void

Examples

treeObject.setValue("Hello World");

getValue()

Get value of current node.

Arguments

  • void

Returns

  • Value or null

Examples

var value = treeObject.getValue();

hasChild()

To check if the object has any child

Arguments

  • void

Returns

  • true or false

Examples

var hasChild = treeObject.hasChild();

hasSibling()

To check if current node has any sibling or not

Arguments

  • void

Returns

  • true or false

Examples

var hasSibling = treeObject.hasSibling();

isLeaf()

To check if the object is leaf

Arguments

  • void

Returns

  • true or false

Examples

var isLeaf = treeObject.isLeaf();

serialize()

Serialize the object before sending over or string conversion.

Arguments

  • void

Returns

  • String

Examples

var isLeaf = treeObject.serialize();