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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ast-walk

v0.0.5

Published

command-line ast inspector

Readme

ast-walk provides an easy way to inspect the ast created by javascript parsers. The interface provided is a lot like a typical shell, with familiar commands like cd and ls.

From the command line, it will load javascript files from disk and use recast to parse them. You can also provide ast's (potentially from other parsers) via code.

This project is a fork of jwalk which provides essentially the same utility for large JSON objects.

Installation

More documentation (and fewer bugs) coming soon. In the meantime, install it via npm:

npm install -g ast-walk

Running

And then run it like this:

ast-walk somefile.js

It can also handle gzipped files. If the extension is .gz, it will decompress the javscript automatically. (This is a left over feature from jwalk, and unlikely to be useful in the javascript context).

ast-walk somefile.js.gz

Most of the documentation below is unmodified from jwalk, and so discusses json. Just apply the same principles to your ast nodes. New ast specific commands include print and find.

Possible Commands

Given the following json file

{
  "name": "jwalk",
  "version": "0.0.4",
  "description": "command-line json inspector",
  "preferGlobal": "true",
  "repositories": {
    "type": "git",
    "url": "http://github.com/nkohari/jwalk"
  },
  "bin": {
    "jwalk": "bin/jwalk"
  },
  "dependencies": {
    "coffee-script": "1.4.0",
    "colors": "0.6.0-1",
    "filesize": "1.6.6",
    "underscore": "1.4.2"
  },
  "engine": "node >= 0.8.x"
}

Help

Shows this help message

jwalk obj{8} / $ help

cd navigates through nodes in the tree
clear clears the screen
cls clears the screen
exit quit jwalk
find performs a depth first search for the given node type
help shows this help message
keys examines the keys of an object node
ls examines a single node
print prints the ast at this point
quit quit jwalk

Print

Prints the javascript at the current node

ast-walk obj{4} /program/body/0 $ print
function hello(name){
  console.log('hello ' + name);
}

Find

Perform a depth first search for a given node type. The first argument supplied is the desired node type to find and provides autocompletion hints

ast-walk obj{4} / $ print

  var a = 'hello';
  function helloMessage(name){
    return 'hello ' + name;
  }
  function byeMessage(name){
    return 'bye ' + name;
  }
  function hello(name){
    console.log(message(name));
  }

ast-walk obj{4} / $ find ReturnStatement
ast-walk obj{3} /program/body/1/body/body/0 $ print

   return 'hello ' + name;

ast-walk obj{3} /program/body/1/body/body/0 $ cd /
ast-walk obj{4} / $ find FunctionDeclaration 1
ast-walk obj{3} /program/body/2/body/body/0 $ print

  function byeMessage(name){
    return 'bye ' + name;
  }

The optional second argument allows you to skip the first X elements of a given type. find FunctionDeclaration 2 would skip the first 2 FunctionDeclarations returning the third. Note that when a node is "skipped", none of it's children will be searched, this allows a (sorta-kinda) breadth first search. You can create a chain as long as you'd like:

 ast-walk obj{4} / $ find FunctionDeclaration 2 IfStatement 2 IfStatement ReturnStatement

List

Examines the current node

ast-walk obj{8} / $ ls
{ name: 'jwalk',
  version: '0.0.4',
  description: 'command-line json inspector',
  preferGlobal: 'true',
  repositories:
   { type: 'git',
     url: 'http://github.com/nkohari/jwalk' },
  bin: { jwalk: 'bin/jwalk' },
  dependencies:
   { 'coffee-script': '1.4.0',
     colors: '0.6.0-1',
     filesize: '1.6.6',
     underscore: '1.4.2' },
  engine: 'node >= 0.8.x' }

Change Directory

Allows navigation through the JSON tree. Note 'cd' does support autocomplete by pressing the tab key.

ast-walk obj{8} / $ cd dependencies
ast-walk obj{4} /dependencies $ ls
{ 'coffee-script': '1.4.0',
  colors: '0.6.0-1',
  filesize: '1.6.6',
  underscore: '1.4.2' }

Clear

Clears the screen

ast-walk obj{8} / $ clear

or

ast-walk obj{8} / $ cls

Keys

Examines the keys of a node

ast-walk obj{8} / $ keys
[ 'name',
  'version',
  'description',
  'preferGlobal',
  'repositories',
  'bin',
  'dependencies',
  'engine' ]

Quit

Exits the ast-walk application

ast-walk obj{8} / $ exit

or

ast-walk obj{8} / $ quit

Preferences File

You can create a JSON file at ~/.ast-walk to define preferences. Right now, all it supports is defining aliases for commands, like so:

{
  "aliases": {
    "l": "ls"
  }
}

Contributing

Bug reports and pull requests welcome!