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

dumb-router

v1.1.0

Published

path -> handler mapping and execution–that's it

Downloads

28

Readme

dumb-router

Path -> Handler mapping and execution–that's it

Usage

Basic usage

var Router = require('dumb-router');

var router = Router(); //factory; do not use `new`

router.register('/cats', meow);
router.register('/dogs', woof);

function meow() {
  alert('a cat is speaking');
  return 'meow';
}

function woof() {
  alert('a dog is speaking');
  return 'woof';
}

alert(router.execute('/dogs')[0]); // => woof

Route parameters

router.register('/say/:words', say);

function say(path, params) {
  console.log(params.words);
}

router.execute('/say/hello-world');

Nesting routes

router.register('/users/:userId', setUser, function(router) {
  router.register('/edit', showUserForm);
});

router.execute('/users/5/edit');

Scoping routes

router.register('/food', null, function(router) {
  router.register('/cookies', cookies);
  router.register('/cakes', cakes);
});

Return values

When the router executes, it returns an array, with an entry for each route handler.

  • Return values for outer handlers come before those of nested routes.
  • Scoping routes do not add to the array of return values.
  • undefined is added for handlers that do not return anything.

Path building

I lied about dumb-router only doing path -> handler mapping and execution. Being able to validate routes is useful, and we can do it by exposing a bit of the route matching logic.

router.register('/food' null, function(router) {
  router.register('/gourmet', gourmetFood);
  router.register('/fast', fastFood);
});

router.path('food') //throws error, no handler for "/food"
router.path('food', 'gourmet');       // => '/food/gourmet'
router.path('food', 'fast');          // => '/food/fast'
router.path('food', 'home-cooking');  //throws error, no route defined

About

Some context around the origin of this class:

We used this Router class as part of our base Flux Store class, where each Store had an instance of a Router. We only used the Router to provide a convenient DSL for mapping Store private functions (state mutators) to paths. Then, all such Stores would handle "navigate" Actions from the Dispatcher by delegating to the Router's execute method.

This decentralized routing pattern, where each store defined its own response to navigation actions, arose because we wanted to avoid exposing means of mutating store state.

The "single monolithic router" pattern, common in other frameworks, requires that Stores expose some means of mutating their internal State.

Decentralized routing has some drawbacks: duplicated routes, and the need to be loose when matching routes. For example, if two stores have routers, and one store responds to "/users/" and another store responds to "/users/new", and both Stores need to invoke their handlers when navigating to "/users/new", the router has to consider "/users/new" a match for "/users".