2.0.1 • Published 8 months ago

@jywei/to-tree-string v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

to-tree-string

A TypeScript library that converts indented string representations of file system hierarchies to tree-like string outputs similar to the tree command.

Installation

npm install @jywei/to-tree-string

Usage

import { toTreeString } from "@jywei/to-tree-string";

// Basic example
const input = `src
  app
    index.js
  public
    image-01.jpg
    image-02.jpg
index.html
package.json`;

console.log(toTreeString(input));

Output:

.
├── src
│   ├── app
│   │   └── index.js
│   └── public
│       ├── image-01.jpg
│       └── image-02.jpg
├── index.html
└── package.json

Configuration Options

You can customize the behavior using options:

// Using custom indentation size
const input = `root
    level1
        level2
            file1.txt
`;

// Specify 4 spaces per indentation level
console.log(toTreeString(input, { spacesPerIndent: 4 }));
2.0.1

8 months ago

2.0.0

8 months ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.2

3 years ago