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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsroute

v1.0.1

Published

JSRoute is a the tiniest, lightweight, and simplest Hash Router made with Pure Vanilla JavaScript. Unlike React or Vue, JSRoute can work with existing DOM without any component. You can customize the router for your own demand.

Downloads

3

Readme

JSRoute is a tiny, lightweight, and simple Hash Router made with Pure Vanilla JavaScript for modern browsers. JSRoute is mainly targeted for Lazy WordPress plugin developers. Unlike React or Vue, JSRoute can work with existing DOM without any components.

Install

Using NPM

npm i -D jsroute

Using CDN

<script src="https://unpkg.com/jsroute/jsroute.min.js"></script>

Manual download

  • [x] Download from GIT and extract the zip
  • [x] Copy jsroute.min.js to your working directory
  • [x] Link the jsroute.min.js file to your HTML

Use Router

In HTML

<a href="#"> Home </a>
<a href="#about"> About </a>
<a href="#profile"> Profile </a>

<div data-content="/">Home page</div>
<div data-content="/about">About page</div>
<div data-content="/profile">Profile page</div>

In JavaScript (ES6)

import JSRoute from "jsroute"

window.JSRoute = JSRoute //recommended 

JSRoute.init()

In JavaScript (CDN)

const JSRoute = window.JSRoute

JSRoute.init()

NOTE: Load JavaScript at footer, NOT as defered or async

Advanced

Configuration

const routes = {
    // path : title (to update dom title), path supports regular expression
    "/" :                       { title: "Home page" },
    "/about" :                  { title: "About page" },
    "/contact" :                { title: "Contact page" }, 
    "/profile/[a-zA-Z0-9]" :    { title: "User Profile" },
}

const configs = {
    default: "/",                       // default route after loaded the page
    componentAttribute: "data-content", // the selector attribute of screens
    fallback: "fallback",               // fallback screen value [data-content='fallback']
    shownDisplay: "inherit",            // style.display = 'inherit'
    hiddenDisplay: "none",              // style.display = 'none'
    routes                              
}

// init configuration by passing through `use` method
JSRoute.use(configs).init()

Handle Route

You can easily set route programmatically

// Use anywhere
JSRoute.route('about')
// immediately changes path to #/about

Custom Events

JSRoute has three custom event you can use with your app

JSRoute.init

Triggers when Router is initialized

document.addEventListener("JSRoute.init", (e) => {
    const route = e.detail.route
    
    console.log(route)
})

JSRoute.change

Triggers when Router is updated

document.addEventListener("JSRoute.change", (e) => {
    const route = e.detail.route
    
    console.log(route)
})

JSRoute.error

Triggers when a wrong path is requested

document.addEventListener("JSRoute.error", (e) => {
    const route = e.detail.route
    
    console.log(route)
})

Debug Router

Enable logs on every action happening on the Router

JSRoute.debug(true).init()