# stringify-tree

> Turn a tree structure into an ascii tree

Latest version **1.1.1** (published 2020-05-18) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2020-05-18 |
| First published | 2018-12-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 26.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jessica Kerr |
| Maintainers | jessitron |
| Keywords | ascii, stringify |

## Links

- npm: https://www.npmjs.com/package/stringify-tree
- Repository: https://github.com/jessitron/stringify-tree
- Homepage: https://github.com/jessitron/stringify-tree#readme
- Issues: https://github.com/jessitron/stringify-tree/issues
- npm.io page: https://npm.io/package/stringify-tree

## Dependencies (2)

- [lodash.flatten](https://npm.io/package/lodash.flatten.md) ^4.4.0
- [@types/lodash.flatten](https://npm.io/package/@types/lodash.flatten.md) ^4.4.4

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.1.1 (latest) — 2020-05-18
- 1.1.0 — 2020-05-18
- 1.0.3 — 2020-05-18
- 1.0.2 — 2019-01-20
- 1.0.1 — 2018-12-21
- 1.0.0 — 2018-12-21

## README

# stringify-tree

Convert a tree structure to an ASCII tree, in approximately the style of `npm ls`

This is in TypeScript, which helps since you pass it some functions.

## install

`npm install stringify-tree`

## trivial example

```typescript
import { stringifyTree } from "stringify-tree";

const tree = {
        name: "Grandmarti", children: [
            {
                name: "Cyndi", children: [
                    {
                        name: "Jess", children: [
                            { name: "Evelyn", children: [] },
                            { name: "Linda", children: [] },
                        ],
                    },
                ],
            },
            { name: "Celia", children: [] },
        ],
    };
    console.log(stringifyTree(tree, t => t.name, t => t.children));
```

```
┬ Grandmarti
├─┬ Cyndi
│ └─┬ Jess
│   ├── Evelyn
│   └── Linda
└── Celia
```

## real-life example

```typescript
import { stringifyTree } from "stringify-tree";

function treeNodeName(tn: TreeNode) {
    const endOffset = tn.$value ? ", " + (tn.$offset + tn.$value.length) : "";
    return `[${tn.$offset}${endOffset}] ${tn.$name}`;
}
function treeNodeChildren(tn: TreeNode): TreeNode[] {
    return tn.$children || [];
}

// parser stuff from Atomist. trust me, it makes a TreeNode with fields like the above

const ast = await Java9FileParser.toAst(p.findFileSync(path));
console.log(stringifyTree<TreeNode>(ast, treeNodeName, treeNodeChildren));
```

```

```

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