@jywei/to-tree-string
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

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 }));

Package Sidebar

Install

npm i @jywei/to-tree-string

Weekly Downloads

0

Version

2.0.1

License

MIT

Unpacked Size

5.5 kB

Total Files

5

Last publish

Collaborators

  • jywei