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

hashmux

v2.3.2

Published

A light URL hash to JavaScript function router.

Readme

Hashmux

A light URL hash to JavaScript function router.

Hashmux is a bit like HTTP multiplexers such as gorilla/mux, but it's client-side. Instead of routing HTTP requests, Hashmux routes changes in the hash part of the URL to JavaScript functions.

Examples

Once you've installed and included hashmux, you can create a Hashmux object and add some routes

var router = new Hashmux()
router.handle("/", indexHandler)
router.handle("/products", listProductsHandler)
router.handle("/blog", blogHandler)

// Call router.listen() to activate the router.
router.listen()

Variables

Hashmux supports more advanced routing too. The variables are given to the function as a map (well, actually an array with string keys).

function getBlogPostHandler(params) {
	// params["name"]
	// params.name
}

router.handle("/products/{id:[0-9]+}", getProductHandler)
router.handle("/blog/post/{name}", getBlogPostHandler)

Variable variables

If you want to allow anything after a certain path, you can simply add a trailing slash. Everything after the trailing slash in requests is put in the params array with numeric indexes.

If you want to handle some specific paths separately, be sure to leave the more generic handler last.

function helpHandler(params) {
	// Request path: example.com/#/help/foo/bar
	// params: {0: "foo", 1: "bar"}
}

function idHelpHandler(params) {
	// Request path: example.com/#/help/123/bar
	// params: {name: "123", 0: bar}
}

router.handle("/help/{id:[0-9]+}/", idHelpHandler)
router.handle("/help/", helpHandler)

Changing pages and redirecting

To go to another page using JS, simply change the window.location.hash value.

window.location.hash = "#/products"

You can also use the History API for more precise control. To go to another page without leaving the current page in history, you can use

history.replaceState(undefined, undefined, "#/blog")
// or
router.redirect("#/blog")

If you just need to redirect one Hashmux path to another, you can use the handleRedirect function in the router.

router.handleRedirect("/blog", "#/blog/page/1")
// You can also have a function to provide the redirect target
router.handleRedirect("/products/{id:[0-9]+}", ({id}) => `#/products/${getNewID(id)}`)

Query parameters

Since 2.3.0, Hashmux has basic support for query parameters. Using them requires no extra configuration.

function filterHandler(params, query) {
	// Request path: example.com/#/blog/filter?search=layout&tag=qwerty&tag=dvorak
	query.get("search") // "layout"
	if (query.has("tag")) {
		query.getAll("tag") // ["qwerty", "dvorak"]
	}
	query.get("author") // undefined
}

router.handle("/blog/filter", filterHandler)

Error handling

If Hashmux doesn't find any suitable path handler for a specific request path, it calls the 404 error handler. You can change and add error handlers with router.handleError(errorCode, handlerFunc).

The argument is an object. It will always contain the page variable if the error was triggered from within Hashmux.

You can also trigger errors from elsewhere using router.error(errorCode, data)

router.handleError(404, function(data) {
	console.log("Oh noes!", data.page, "was not found")
})

...

router.error(404, {page: "/foo/bar"})