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

protolus-router

v0.0.3-alpha

Published

a lightweight URL router supporting a wide variety of usage patterns

Downloads

4

Readme

protolus-router.js

a lightweight URL router supporting a wide variety of usage patterns.

Creation

var ProtolusRouter = require('protolus-router');
var router = new ProtolusRouter({});

Options are:

  1. argumentNames : an array of strings to be used as keys when using the regex to function mode
  2. onMissing : a callback for when no route is found
  3. ini : preload a particular INI file
  4. simpleSelectors : set this to false to prevent the simpleSelector and instead treat the stings as complete regex selectors

Function to Function

Use two functions, one to match the URL and the other to perform the action, arguments may be handled manually in either function. the action function also may return a value which is passed to the callback of the parse function (if a callback is passed).

router.addRoute(function(url){
    //return a truthy value representing whether this url has been selected
}, function(returnedValue){
    //use the incoming truthy value to either:
    //1) serve the request
    //2) return a value which will be passed to .route()s callback
});

Regex to Function

Use two functions, one to match the URL and the other to perform the action, arguments may be handled manually in either function. This function may also return a value for the optional parse callback.

router.addRoute(/(users)\/([A-Za-z][A-Za-z0-9]{3,16})\/([0-9]+)/, function(user, id, postId){
    //serve or return
});

or, if I had set argumentNames = ['user', 'id', 'postId'];

router.addRoute(/(users)\/([A-Za-z][A-Za-z0-9]{3,16})\/([0-9]+)/, function(args){
    // args = {user:'', id:'', postId:''}
    //serve or return
});

INI Parsed

You may also specify an INI file which acts as a list of rewrite rules, each line is of the form:

articles/*/# = "articles?name=*&page=*"

You can either use the option in the constructor or call the INI function with or without a callback(any routes will be queued until the async load is complete)

router.INI('my/awesome/config.ini', function(){
    //it's done!
});

This will always require the callback to be used on the routed function, which will pass back the routed URL

router.route(url, function(routedURL){
    //do stuff here
});

This style may also be added directly as a route:

router.addRoute('articles/*/#', 'articles?name=*&page=*');

Groups

Routing rules also support 'groups' which are arbitrary assignments, which give some context to the rule

If I were to route this way:

router.addRoute(/(users)\/([A-Za-z][A-Za-z0-9]{3,16})\/([0-9]+)/, ['get', 'post'], function(user, id, postId){
    //serve or return
});

because I wanted to mark it to only be active on a get or post request I would then access the route:

router.route(url, 'get', function(routedURL){
    //do stuff here
});

Keep in mind this is a purely textual feature and your app will need to set these values to make it work

You can mix modes at will.

Enjoy,

-Abbey Hawk Sparrow