Directory
- Welcome
File Tree Generator
The File Tree Generator is a powerful utility function that transforms nested object structures into visual file tree representations. Perfect for documentation, directory exploration, and project structure visualization.
Key Features
The generator creates ASCII-style file trees that:
-
Represent nested directory structures
-
Use clear visual hierarchy
-
Support unlimited nesting levels
-
Maintain consistent formatting
Basic Usage
import { generateFileTree } from '@/lib/shared/utils';const tree = generateFileTree({ src: { components: { 'Header.tsx': null, 'Footer.tsx': null, }, styles: { 'global.css': null, }, },});
Output:
src/├── components/│ ├── Header.tsx│ └── Footer.tsx└── styles/ └── global.css
API Reference
Function Signature
type FileTree = { [key: string]: FileTree | null;};
function generateFileTree(tree: FileTree, prefix: string = ''): string;
Function Parameters
Parameter | Type | Default | Description |
---|---|---|---|
tree | FileTree | Object representing directory structure | |
prefix | string | "" | Internal parameter for recursion |
Advanced Features
Syntax Highlighting
When combined with the Expressive Code component, you can highlight specific parts of the tree:
src/ └── components ├── Button.tsx ├── old-component.tsx └── new-component.tsx
Common Use Cases
Project documentation
Directory structure visualization
File system navigation
Code organization examples
Migration guides
Installation instructions
Limited Time Launch Sale
Start organizing and visualizing your project structure with our File Tree Generator. Get our AstroJS starter template now and enhance your documentation.
GET 60% OFF!