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

monarch-routes

v1.0.2

Published

Simple functional url state router for isomorphic JavaScript applications.

Downloads

5

Readme

#Monarch Router

Functional style universal JavaScript router(yes, another one). I wrote this with the intention to practice some functional programming concepts, and to use it in my own isomorphic apps.

#Why another router?

I have been experimenting with isomorphic JavaScript for a while now, and so far none of the current routing solutions has quite convinced me. React-Router is nice, but it is coupled to React and it's API is not as simple as I would like to. Other routing solution add history and hash events management, which ,in my opinion, are out of the responsibility of a router. The prior also makes difficult integration with server side routing.

I wanted a simple url/state pattern mapping tool that executes a function and returns results. And here it is.

#install

$ npm install -S monarch-routes

#Use it

import routes from 'monarch-routes';

const routingTable = {
    "/users": ()=> "This should return a bunch of people...",
    "/users/:id": ({params})=> {DB.getUser(params.id)}
}

const monarch = routes(routingTable);

monarch('/users'); // This should return a bunch of people...

That's it. I don't think it could be simpler.

#API

monarch-routes takes a routing table in the form of a JavaScript object with the keys being the route pattern to match ,and the value being a handler function for that route pattern. It will return a monarch function which is our new router.

monarch takes a string path or url and returns whatever the matched handler result is. The handler is invoked with a context object with the url that matched, the params of the pathname, and the query string variables.

The router uses the same path matcher algorithm than ExpressJS, so integrating with any express-ish app is easy.

#Conribute/Fork

Clone this repo and run npm install and after that run the tests npm test.