# print-tree

> prints any js data structure as a tree

Latest version **0.1.5** (published 2018-12-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install print-tree
pnpm add print-tree
yarn add print-tree
bun add print-tree
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2018-12-18 |
| First published | 2017-07-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | alex leon |
| Maintainers | alex-e-leon |
| Keywords | console, tree, print, pretty |

## Links

- npm: https://www.npmjs.com/package/print-tree
- Repository: https://github.com/alex-e-leon/print-tree
- Homepage: https://github.com/alex-e-leon/print-tree#readme
- Issues: https://github.com/alex-e-leon/print-tree/issues
- npm.io page: https://npm.io/package/print-tree

## Recent versions

- 0.1.5 (latest) — 2018-12-18
- 0.1.4 — 2017-09-29
- 0.1.3 — 2017-09-27
- 0.1.2 — 2017-07-16
- 0.1.1 — 2017-07-16
- 0.1.0 — 2017-07-16

## README

# print-tree [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status]

prints any js data structure as a tree

## Usage

```js
$ npm install print-tree
const printTree = require('print-tree');

const customTree = {
  name: 'head',
  children: [
    {
      name: 'branchA'
      children: [
        { name: 'branchC' },
      ],
    },
    { name: 'branchB' },
  ],
};

printTree(
  customTree,
  node => node.name.toUpperCase(),
  node => node.children,
);

// HEAD
// ├─┬ BRANCHA
// | └── BRANCHC
// └── BRANCHB
```

`printTree(tree, [printNode], [getChildren])`

## Arguments

### tree: T

The object to traverse.

### printNode: function<T>(node: T, branch: string): ?string

A function to customize the output.
You can pass in either:

- a function that takes the current node and returns the string representation.
- a function that takes the current node and the branchGraphic and returns nothing -
    this lets you customize the ouput method

### getChildren: function<T>(node: T): Array<T>

A function to help `print-tree` traverse custom data structures.
It takes the current head of the tree/sub-tree and returns a list of the children

<!-- Definitions -->

[build-badge]: https://img.shields.io/travis/alex-e-leon/print-tree.svg

[build-status]: https://travis-ci.org/alex-e-leon/print-tree

[coverage-badge]: https://img.shields.io/codecov/c/github/alex-e-leon/print-tree.svg

[coverage-status]: https://codecov.io/github/alex-e-leon/print-tree

---
_Source: https://npm.io/package/print-tree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
