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

ruut

v1.1.0

Published

A tiny and fast route parsing library, supporting parameters and more.

Downloads

24

Readme

ruut

ruut

A tiny and fast route parsing library, supporting parameters and more.

ruut

This module can be used on both server and client sides. For a demo using this on the client side see the demo page.

Installation

$ npm i ruut

Example

// Dependencies
var Ruut = require("ruut");

// Create the router
var router = Ruut([
    function (route) {
        console.log("This is the home page.", route);
        return "This is the home page"
    }
  , {
       ":user": ["user-profile", {
            ":project": {
                "build": "build"
              , "editor": [null, {}, "editor_file" ]
            }
        }]
      , "blog": ["Blog homepage", {
            "page": {
                ":page": "Blog page"
            }
          , ":article": ["Blog article", {
                "comments": ["comments", {
                    ":id": "Current comment"
                }]
            }]
        }]
        // Route: /signup
      , "signup": "Sign up route"
      , "users": ["Users list", {
            ":user": "User profile"
        }]
    }
]);

console.log(router("/"));
// => { data: 'This is the home page', params: {} }

console.log(router("/blog"));
// => { data: 'Blog homepage', params: {} }

console.log(router("/blog/page/10"));
// => { data: 'Blog page', params: { page: '10' } }

console.log(router("/blog/some-article"));
// => { data: 'Blog article', params: { article: 'some-article' } }

console.log(router("/blog/some-article/comments"));
// => { data: 'comments', params: { article: 'some-article' } }

console.log(router("/blog/some-article/comments/my-comment"));
// => { data: 'Current comment', params: { article: 'some-article', id: 'my-comment' } }

console.log(router("/signup"));
// => { data: 'Sign up route', params: {} }

console.log(router("/users"));
// => { data: 'Users list', params: {} }

console.log(router("/users/ionicabizau"));
// => { data: 'User profile', params: { user: 'ionicabizau' } }

console.log(router("/ionicabizau/my-project/editor/edit/some/file.js"));
// => { data: 'editor_file', params: { user: 'ionicabizau', project: 'my-project' } }

Documentation

Ruut(routes)

Creates a new router.

Params

  • Array|Object routes: An array or an object representing routes: If it's an array, then the format is:

  • 0 (Function|Non-null-values): If function, then it will be called and the data will be the returned value, otherwise the non-null value.

  • 1 (Array|Object): A route object/array (recursive definition).

  • 2 (Function|Non-null-values): This value/function is returned/called when no other routes were found.

If the routes value is an object it should be in the following format:

{
    // /some
    "some": {
        // /some/route
        "route": {
            // /some/route/with
            "with": {
                // /some/route/with/anything-you-want
                ":dynamic": {
                    // /some/route/with/anything-you-want/value
                    "value": function (params) {
                        return "This can be a function or a non-null value. The dynamic value is: " + params.dynamic;
                    }
                }
            }
        }
    }
}

Return

  • Function The check function getting the pathname as argument.

check(routes, pathname)

search Searches the pathname in the routes object, recursively. This is used internally.

Params

  • Routes routes: The routes to check the pathname in.
  • String pathname: The pathname.

Return

  • Object An object containing:
  • is_valid (Boolean): true if the route was foud, false otherwise.
  • _ (Function|Non-null-value): The route data.
  • params (Object): The dynamic parameters.

check(routes, pathname)

Searches the pathname in the routes object and prepares the final object. This is used internally.

Params

  • Routes routes: The routes to check the pathname in.
  • String pathname: The pathname.

Return

  • Object The found route containing data and params fields or null otherwise.

How to contribute

Have an idea? Found a bug? See how to contribute.

License

See the LICENSE file.