treeify-data

1.1.9 • Public • Published

treeify-data

treeify-data converts a JS object into a nice, visible depth-indented tree for console printing. The structure generated is similar to what you get by running the tree command on Unixy platforms.

Usage

First you'll want to run this command in your project's root folder:

$ npm install treeify-data

Then proceed to use it in your project:

import treeifyData from "treeify-data";
console.log(
  treeifyData({
    name: 1,                          // 1
    items: [{ name: 2,                // └─  2
                items: [ { name: 3 }, //    ├─ 3
                         { name: 4 }] //    └─ 4
            }]
}));
Prop Description Default Type
prop Used to indicate data output name string
childrenProp Used to specify properties of child elements items string
depth Show depth Infinity number

Example:

import treeifyData from "treeify-data";
console.log(
  treeifyData({
    parent: 1,                           // 1
    childs: [{ parent: 2,                // └─  2
               childs: [ { parent: 3 },  //    ├─ 3
                       { parent: 4 }]    //    └─ 4
            }]
}, 'parent', 'childs'));

Package Sidebar

Install

npm i treeify-data

Weekly Downloads

1

Version

1.1.9

License

MIT

Unpacked Size

4.66 kB

Total Files

4

Last publish

Collaborators

  • alexgreb