@jywei/to-tree-string
v1.0.2
Published
Print a filesystem tree string
Downloads
8
Readme
Summary
Generate tree
-style output from JSON.
Use it to quickly generate a string representation of a file tree.
Usage
import { toTreeString, TreeNode } from "to-tree-string";
/*
Easier to visualize this object in YAML, representing a file tree:
my-project:
- src:
- images:
- image-01.jpg
- image-02.jpg
- templates:
- page.html
- post.html
- index.html
- package.json
- README.md
*/
// Transformed into object (or JSON):
const input: TreeNode = {
"my-project": [
{
src: [
{
images: ["image-01.jpg", "image-02.jpg"],
},
{
templates: ["page.html", "post.html"],
},
"index.html",
],
},
"package.json",
"README.md",
],
};
console.log(toTreeString(input));
/*
my-project
├── src
│ ├── images
│ │ ├── image-01.jpg
│ │ └── image-02.jpg
│ ├── templates
│ │ ├── page.html
│ │ └── post.html
│ └── index.html
├── package.json
└── README.md
*/