https://github.com/luvies/format-tree
Formats a tree structure into a string that can be printed
https://github.com/luvies/format-tree
deno denoland format javascript node node-js nodejs string tree typescript
Last synced: 3 months ago
JSON representation
Formats a tree structure into a string that can be printed
- Host: GitHub
- URL: https://github.com/luvies/format-tree
- Owner: luvies
- License: mit
- Created: 2018-09-02T21:13:42.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-01-27T10:43:19.000Z (over 7 years ago)
- Last Synced: 2025-02-20T06:47:49.282Z (over 1 year ago)
- Topics: deno, denoland, format, javascript, node, node-js, nodejs, string, tree, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/format-tree
- Size: 131 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Format Tree
This library allows complete formatting of trees with guides and configurability that look similar to how npm and yarn dispay trees. The functions expect the predefined structure as defined in [mod.ts](lib/mod.ts), and the full documentation for that format is also described there. However, some examples are shown here (which are taken from the [test file](test/test.ts))
This library is compatible with [deno](https://github.com/denoland/deno) via the following direct import:
`https://raw.githubusercontent.com/luvies/format-tree/{tag}/lib/mod.ts`
or by using the slightly nicer:
`https://denopkg.com/luvies/format-tree@{tag}/lib/mod.ts`
In both cases, the `{tag}` identifier is the release version you are targeting. I would recommend against using master directly (as, in general, the master branch is not guaranteed to be stable).
## With first item
Source:
```ts
formatTreeString(
{
text: 'first',
extra: 'extra',
children: [
{
text: 'second',
extra: 'another'
},
{
text: 'third',
children: [
{
text: 'fourth',
extra: 'yet'
},
{
text: 'fifth'
},
{
text: 'sixth',
extra: 'another',
children: [
{
text: 'seventh',
extra: 'one'
},
{
text: 'eighth',
extra: 'look',
children: [
{
text: 'ninth',
extra: 'another'
},
{
text: 'tenth',
extra: 'one'
}
]
}
]
}
]
},
{
text: 'eleventh',
extra: 'yay'
}
]
},
{
guideFormat: chalk.dim
}
);
```
Output:

## Without first item
Source:
```ts
formatTreeString(
[
{
text: 'first',
extra: 'extra'
},
{
text: 'second',
extra: 'another'
},
{
text: 'third',
children: [
{
text: 'fourth',
extra: 'yet'
},
{
text: 'fifth'
},
{
text: 'sixth',
extra: 'another',
children: [
{
text: 'seventh',
extra: 'one'
},
{
text: 'eighth',
extra: 'look',
children: [
{
text: 'ninth',
extra: 'another'
},
{
text: 'tenth',
extra: 'one'
}
]
}
]
}
]
},
{
text: 'eleventh',
extra: 'yay'
}
],
{
guideFormat: chalk.dim
}
)
```
Output:
