@prostojs/tree
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

Light and easy output in tree library.

ProstoTree
└── Light and easy

Install

npm: npm install @prostojs/tree

Via CDN:

<script src="https://unpkg.com/@prostojs/tree"></script>

Usage

const { ProstoTree } = require('@prostojs/tree')

const tree = new ProstoTree()

tree.print({
    label: 'root node',
    children: [
        { label: 'node with label' },
        'some node',
        {
            label: 'big',
            children: [
                'more',
                'nodes',
                { label: 'nested', children: ['deep', 'deep2'] },
                'nested ends',
            ],
        },
        'small',
    ],
})

Options

const options = {
    label: '<name of prop with label>',
    children: '<name of prop with array of children>',
    renderLabel: (node) => '<render the node content yourself>',
    branchWidth: 2, // the horizontal length of branch tail
    branches: {
        vLine: '│',     // vertical line character
        hLine: '─',     // horizontal line character (repeated <branchWidth> times)
        end: '└',       // ending branch character
        middle: '├',    // middle branch character
    }
}

const tree = new ProstoTree(options)

// render tree to string
const stringResult = tree.render(/* tree, renderOptions? */)

// console.log tree
tree.print(/* tree, renderOptions? */)

Render options

const renderOptions = {
    // limits the output to go as deep as the
    // level value
    level: 3,

    // limits the output count of direct children
    // nodes upto the childrenLimit value
    childrenLimit: 5,

    // when showLast === true the first items
    // over the limit will be hidden
    // when showLast === false the last items
    // over the limit will be hidden
    showLast: true,
})

Readme

Keywords

Package Sidebar

Install

npm i @prostojs/tree

Weekly Downloads

5

Version

0.2.2

License

MIT

Unpacked Size

25.2 kB

Total Files

15

Last publish

Collaborators

  • mav-rik