🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

object-treeify

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-treeify

Stringify Object as tree structure

1.1.20
Source
npm
Version published
Weekly downloads
2.3M
-11.21%
Maintainers
1
Weekly downloads
 
Created

What is object-treeify?

The object-treeify npm package is designed to convert JavaScript objects into tree-like string representations. This can be particularly useful for visualizing hierarchical data structures, debugging, or logging purposes. It allows developers to easily generate a textual representation of an object's structure, making it more readable and understandable.

What are object-treeify's main functionalities?

Basic tree generation

This feature allows you to generate a basic tree structure from a JavaScript object. The code sample demonstrates how to convert a nested object into a tree-like string representation, categorizing items under 'fruits' and 'vegetables'.

const treeify = require('object-treeify');

const data = {
  fruits: {
    apple: {},
    banana: {},
    cherry: {}
  },
  vegetables: {
    tomato: {},
    cucumber: {},
    carrot: {}
  }
};

console.log(treeify(data));

Customizing options

This feature demonstrates how to customize the appearance of the tree structure using various options. The code sample shows how to adjust the spacing, joining character, and the prefixes used for keys to alter how the tree is displayed.

const treeify = require('object-treeify');

const data = {
  animals: {
    mammals: {
      dog: {},
      cat: {}
    },
    birds: {
      parrot: {},
      sparrow: {}
    }
  }
};

const options = {
  join: '\n',
  spacerNoNeighbour: '  ',
  spacerNeighbour: '│ ',
  keyNoNeighbour: '└─ ',
  keyNeighbour: '├─ '
};

console.log(treeify(data, options));

Other packages similar to object-treeify

Keywords

object

FAQs

Package last updated on 14 Sep 2019

Did you know?

Socket

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.

Install

Related posts