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

scrumpy

v2.1.3

Published

Scrumps all of the juiciest nodes from your trees!

Downloads

49

Readme

scrumpy

Build status Package status Downloads License

Scrumps the juiciest ~~berries~~ nodes from your trees!

You what?

Scrumpy traverses arbitrary tree structures, visiting every node and either invoking a callback function or returning subtrees that match some criteria.

What's it useful for?

One use is discoverng nodes in abstract syntax trees.

For instance, if you want to find nodes representing particular tokens in the Mozilla-format AST, you have to walk the tree and interrogate every node.

Instead of writing that code manually, scrumpy does it for you.

How do I install it?

Via npm:

npm i scrumpy --save

Or if you just want the git repo:

git clone https://gitlab.com/philbooth/scrumpy.git

How do I use it?

The package exports one function, called scrump:

import { scrump, VisitorPhase } from 'scrumpy';

To visit every node and invoke your own callback, pass it the source tree and a visitor function:

const results = scrump(tree, visitor);

function visitor(context) {
  // context.key: string or number, the key for the node
  // context.value: the node
  // context.depth: number, indicates how far down the tree structure the node is
  // context.path: array of keys for all ancestors from the root down to the current node
  // context.parent: the parent node
  // context.phase: `VisitorPhase.entering` or `VisitorPhase.exiting`
  // context.root: the root node
  // optionally return `true` to push the current node into results array
}

Alternatively, you can tell it to return all nodes that match a criteria subtree:

const criteria = {
  foo: 'foo',
  bar: {
    baz: 'baz',
    qux: 'qux',
  },
};

const results = scrump(tree, criteria);

With both approaches, you can also pass a third options argument, which controls the search algorithm:

const results = scrump(tree, visitor, {
  recursive: false,  // Set to false to only search the root level for matches
  array: false,      // Set to false to ignore array items when searching
  all: false,        // Set to false to only return the first match
  depthFirst: false, // Set to false to search breadth-first instead of depth-first
  phases: new Set([
    VisitorPhase.entering, // Set to invoke visitor when nodes are entered
    VisitorPhase.exiting,  // Set to invoke visitor when nodes are exited
  ]),
});

All boolean options default to true if not set. Default for the phases option is new Set([ VisitorPhase.entering ]).

Can I see some examples?

Find import statements in an abstract syntax tree, using a predicate criteria:

const results = scrump(ast, ({ value }) => {
  return value.type === 'ImportDefaultSpecifier' ||
    value.type === 'ImportNamespaceSpecifier' ||
    value.type === 'ImportSpecifier'
})

Find returns from a function, ignoring any nested functions, using a subtree criteria:

const results = scrump(functionNode.body.body, {
  type: 'ReturnStatement'
}, {
  recursive: false,
})

Find the first const declaration (depth-first):

const [result] = scrump(ast, {
  type: 'VariableDeclaration',
  kind: 'const'
}, {
  all: false,
})

Find the first const declaration (breadth-first):

const [result] = scrump(ast, {
  type: 'VariableDeclaration',
  kind: 'const'
}, {
  all: false,
  depthFirst: false,
})

Does it handle recursive/circular tree structures?

Yep.

Are there types?

Yes.

import { scrump, type VisitorContext } from 'scrumpy';

const results = scrump(tree, visitor);

function visitor(context: VisitorContext): boolean {
  // ...
}

Is there a change log?

Yes.

How do I set up the dev environment?

To install the dependencies:

npm i

To run the tests:

npm t

To lint the code:

npm run lint

What license is it released under?

MIT.