Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@casd/print-tree

casdijkman34GPL-3.0-only0.0.7TypeScript support: included

Create a plain text tree, like the tree command common on UNIX-like systems

print, tree, print tree, tree command, tree utility, tree string, unix tree, linux tree, posix tree, macOS tree

readme

Print tree

Create a plain text tree, like the tree command commonly found on UNIX-like opertating systems.

How to install

Using npm:
npm install --save-dev @casd/print-tree

Using yarn:
yarn add --dev @casd/print-tree

How to use

printTreesFromString()
Generate tree string from input string
import { printTreesFromString } from '@casd/print-tree';
// or using require()
// const { printTreesFromString } = require('@casd/print-tree');

// Default indentation is two spaces per level
const inputString = `
Root
  Child
    Grandchild`;

const treeString = printTreesFromString(inputString)

/* Value of treeString:

Root
└── Child
    └── Grandchild

*/
printTrees()
Generate tree string from input nodes, supports multiple trees
import { printTrees } from '@casd/print-tree';

const inputNodes = [
  { value: 'Root', children: [{ value: 'Child', children: [{ value: 'Grandchild' }] }] }
];

const treeString = printTrees(inputNodes);
// treeString is the same value as the example above
printTree()
Generate tree string from input node
import { printTree } from '@casd/print-tree';

const inputNode = { value: 'Root', children: [{ value: 'Child', children: [{ value: 'Grandchild' }] }] };

const treeString = printTree(inputNode);
// treeString is the same value as the example above