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

js-routing

v1.0.1

Published

Easy client-side routing for vanilla JS sites

Readme

js-routing

Easy client-side routing for vanilla JS sites

When you're building a single-page website without a frontend framework such as React, this small package can help you implement routing with a single function invocation.

Intended to be used when you have several anchors linking to different sections of your website, identified by an id. Only the section whose link is clicked should be visible, while the rest should be hidden. Also ensures that the section displayed is in sync with the url, so that the browser routing (forward and back arrows) work as expected.

Installation

Run npm i js-routing in your terminal. Include import navigate from 'js-routing' in your JS file (if using webpack) or import navigate from '/node_modules/js-routing/index.js' if using es6 modules without webpack.

Usage

Exports a single function which takes 3 parameters - 1 mandatory and 2 optional.

Parameter 1: A string array that contains the ids of the elements that you want to navigate between. These ids should also be the hrefs of anchors that link to those sections. Ids should be passed without the #.

Parameter 2: Optional. The id of the section that should be displayed by default. (Before any links are clicked.) If this parameter is not present, it will default to the first id in the list. Pass null if none of the sections should be displayed before any links are clicked.

Parameter 3: Optional. An array of callback functions. Pass in up to one callback for each id, which will be invoked any time that page is navigated to. Each callback should be in the same array index as its corresponding id. If a callback array is passed but some ids do not have callbacks, the empty spots should be populated with null.

Important Notes

  1. When an element is navigated to, it will be displayed while the other elements whose ids were passed will be hidden. Any element whose id is not in the list (and is not a child of elements whose ids are in the list) will not be hidden by the navigation. This allows a common header, footer, etc. to be shared among all of the pages.
  2. Callbacks will be invoked every time their respective page is navigated to. Callbacks will be invoked exactly as they are passed in with no additional parameters.
  3. The navigate function can be invoked more than once for the same website with a second set of ids, for instance if one page has several links inside of it. See Example 2 for how this works and how it can be useful.

Code Samples:

Example 1:

JS file

example1Js

Supporting html

example1Html

Example 2:

JS file

example2Js

Supporting html

example2Html