Format a tree like structure to a depth indented string
$ npm i -g formatree
const formatree = require('formatree');
const tree = { foo: { bar: 0 }, baz: 1, qux: { quux: 2 } };
formatree(tree);
// .
// ├── foo
// │ └── bar
// ├── baz
// └── qux
// └── quux
//
formatree(tree, { limit: 1, spacing: 1, values: true });
// .
// │
// ├── foo
// │
// ├── baz (1)
// │
// └── qux
//
formatree(tree, { sibling: '|-- ', lastSibling: '`-- ', indent: '| ' });
// .
// |-- foo
// | `-- bar
// |-- baz
// `-- qux
// `-- quux
//
Type: object
The tree structure that needs to be formatted.
Type: Object
Type: number
Default: 0
Limit the tree at a specific branch depth, 0 is no limit.
Type: number
Default: 0
Add some extra lines between the tree branches, 0 is no spacing.
Type: boolean
Default: false
Show the values of the siblings in the tree
Type: string
Default: .
The first line of the tree
Type: string
Default: empty
The last line of the tree
Type: string
Default: ``
Append a string after a parent branch in the tree
Type: string
Default: ├──
Type: string
Default: └──
Type: string
Default: │
Type: string
Default:
{sibling: '|-- ',lastSibling: '`-- ',indent: '| '}
{header: '',sibling: ' ',lastSibling: ' ',indent: ' ',lastIndent: ' ', footer: ''}
{header: '0',sibling: '101 ',lastSibling: '101 ',indent: '1010',lastIndent: '1010'}
{sibling: '─ ',lastSibling: '─ ',indent: '──',lastIndent: '──'}
{header: 'v',sibling: '> ',lastSibling: '> ',indent: '>>',lastIndent: '>>', footer: '^'}
- formatree-cli - CLI for this module
MIT © A1rPun