Socket
Socket
Sign inDemoInstall

object-treeify

Package Overview
Dependencies
Maintainers
1
Versions
51
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


Version published
Weekly downloads
1.7M
increased by1.6%
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

FAQs

Package last updated on 13 Dec 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc