npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

term-tree

v0.0.4

Published

Tree structure utils for terminal printing and file traversing.

Readme

term-tree

Tree structure utils for terminal printing and file traversing.

Install

$ npm install term-tree

Usage

Node.js

Create and print filenames from array.

import { createTreeFromFiles, renderTree } from 'term-tree'

const files = ['package/src/foo/bar.ts', /* ... */];
const tree = createTreeFromFiles(files);
const graph = renderTree(source);
console.log(graph);
package
├── src
│   ├── foo
│   │   ├── bar.ts
│   │   └── baz.ts
│   └── shared
│       ├── context.ts
│       └── vendors/ansi.ts
├── tests/foo
│   ├── bar.ts
│   └── baz.ts
└── package.json

Walk directory to read files:

import fs from 'fs/promises';
import { walkDirectory } from 'term-tree';

const files = {};

for await (const [name, stats] of walkDirectory('./')) {
  if (stats.isFile) {
    files[name] = await fs.readFile(name, 'utf8');
  }
}

Command Line

$ npm install -g term-tree
$ term-tree --size

/Users/Asuka109/repositories/term-tree (82.21 kB)
├── README.md (5.52 kB)
├── bin.js (132 B)
├── package.json (762 B)
├── pnpm-lock.yaml (48.53 kB)
├── src (9.85 kB)
│   ├── cli.ts (3.32 kB)
│   ├── fs.ts (1.25 kB)
│   ├── index.ts (122 B)
│   ├── node.ts (2.5 kB)
│   ├── render.ts (1.96 kB)
│   ├── types.ts (202 B)
│   └── utils.ts (213 B)
├── tests (5.4 kB)
│   ├── fs.test.ts (1.44 kB)
│   ├── node.test.ts (3.73 kB)
│   └── tsconfig.json (82 B)
├── tsconfig.json (11.33 kB)
└── vitest.config.ts (174 B)
$ term-tree --help
Usage: term-tree [options] [dir]

Tree structure utils for terminal printing and file traversing.

Arguments:
  dir                         directory to list (default: "./")

Options:
  -V, --version               output the version number
  -d, --depth [depth]         depth of the tree to search (default: 5)
  -s, --size                  show file size
  -S, --symbols <symbols>     symbols of tree (default: "ansi")
  -a, --absolute              print absolute path
  --combine                   combine files and directories (default: true)
  --no-combine
  -l, --follow-symlink        follow symlink
  -D, --include-dots          include dot files
  -M, --include-node-modules  include node_modules
  -r, --review                print and review the options
  -j, --json                  output as json
  -h, --help                  display help for command

API

Table of Contents

arrayFromAsyncGenerator

src/utils.ts:2-10

Create an array from async generator.

Parameters

  • generator AsyncGenerator<T>

Returns Promise<Array<T>>

visitTree

src/node.ts:6-13

Visit the tree node and its children in DFS.

Parameters

  • source TreeNode
  • handler function (src: TreeNode, parent: TreeNode): void
  • parent TreeNode?

createTreeFromFiles

src/node.ts:23-84

Create a tree from a list of files.

Parameters

  • files any
  • options CreateTreeFromFilesOptions (optional, default {})

symbols

src/render.ts:25-25

The symbols to use for rendering the tree.

Type: (TreeSymbols | "ansi" | "ascii")

renderTree

src/render.ts:68-83

Render the tree node into terminal graph.

Parameters

  • source TreeNode
  • options RenderTreeOptions (optional, default {})

walkDirectory

src/fs.ts:13-48

Generate and walk the directory tree.

Parameters

  • dir string
  • options WalkDirectoryOptions?

Returns AsyncGenerator<[string, fs.Stats]>