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

pp-router.js

v2.1.8

Published

Simple Router for javascript

Downloads

6

Readme

pp-router.js

check the Example

Getting Started

In the web project include pp-router.js with:

<script src="https://cdn.jsdelivr.net/npm/pp-is@latest/pp-is.min.js" ></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/pp-router.min.js" ></script>

Or

Install

npm i pp-router.js --save

Initialize

Simple Router for you Apps Client-Side

<ul>
	<li><a href="#/">Incio</a></li>
</ul>
<ul>
	<li><a href="#/vegetables/artichokes/1">Artichokes</a></li>
	<li><a href="#/vegetables/onion/20">Onion</a></li>
	<li><a href="#/vegetables/carrots/2">Carrots</a></li>
</ul>
<div id="root" ></div>
// Declare root html element
var root = document.getElementById("root");

// Declare router here
var router = new ppRouter(
    // How to use it ?
    {
    "/":{
        controller:function(){
            root.innerHTML = `<h1>Home</h1>`;
        }
    },
    "/route-remove":{
        controller:function(){
            root.innerHTML = `<h1>Route Remove</h1>`;
        }
    }
    }
);

// If you want to add another router
router.addRoute("/vegetables/:name(string)/:id(number)",
    {
        controller:function( params ){				
            root.innerHTML = `<h1>vegetables ${params.name} : ${params.id} </h1>`;
        }
    }
);

// If you want to remove any route
router.removeRoute("/route-remove");

// If you want to default redirect
router.redirect("/");

// If you want to default Function for noFound state

router.noFound = function( location ){
    // Put you code here
}

//getting enjoy you router
router.start();
// if you want
//router.start("/my-url-base");

Methods

router

You can write exact routers, that's easy.

but if you need dynamic routers do it as follows

/customer/:id(number) /customer/:namecustomer(string)/:id(number) /customer/:nameAndId(any)

there are three ways to get it :nameMyVar(number) , :nameMyVar(string) , :nameMyVar(any)

addRoute

receives the name of the url and its object, see the example above

removeRoute

removes routing according to url

redirect

set a url for unmatched urls

noFound

creates a function to execute in case of url mismatches

start

Function that initializes the analizis, you can also set a base url