Public
Render a Val Town project's file tree as an ASCII tree string
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

renderValTree

Render any Val Town val's file structure as an ASCII tree string.

Usage

import renderValTree from "https://esm.town/v/nbbaier/renderValTree/main.ts"; // Render the current val's own tree const tree = await renderValTree(); console.log(tree); // Render another val by username + name const tree2 = await renderValTree( { username: "stevekrouse", name: "dateme" }, "dateme", ); console.log(tree2); // Render using a meta import URL directly const tree3 = await renderValTree( "https://esm.town/v/stevekrouse/dateme@1-main", ); console.log(tree3);

Example output

Here's the tree for this val, rendered with:

import renderValTree from "https://esm.town/v/nbbaier/renderValTree/main.ts"; const tree = await renderValTree(import.meta.url, "renderValTree");
renderValTree
├── .vtignore
├── biome.json
├── deno.json
├── main.ts
└── README.md

Named exports

ExportDescription
renderValTree (default)Fetch files and render the full tree. Accepts a ValRef, a meta import URL string, or nothing (defaults to the calling val). Optional header string is printed at the top.
getFileEntries(metaImportUrl?)Returns FileEntry[] — flat list of file/directory paths.
createFileTree(entries)Converts FileEntry[] into a nested FileTree object.
renderTree({ tree, indent?, header? })Renders a FileTree object into an ASCII string.

Types

  • FileTree{ [key: string]: FileTree }, directories end with / in their key
  • FileEntry{ path: string; type: "file" | "directory" }
  • ValRef{ username: string; name: string }