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 🙏

© 2025 – Pkg Stats / Ryan Hefner

cloak.router

v0.0.7

Published

Cloak.js router module

Downloads

16

Readme

cloak.router

Cloak.js is a collection of modules for building modern web applications. Each module is designed to work with the others, but are decoupled to allow you pick and choose which ones you need. Want views but don't need to deal with models or a complex router? You can do that! First, make sure you have cloak.core which contains some basic utilities for each module. Then, install the modules you want.

$ npm install --save cloak.core
$ npm install --save cloak.view

Then, in your JavaScript, just start using the components. Cloak is designed to work in a CommonJS environment, so any tools that do so will work (like common.js or browserify).

var View = require('cloak.view');

var MyView = module.exports = View.extend({
    
    template: 'views/myview/myview.hbs',

    draw: function() {
        this.elem.innerHTML = this.render();
    }

});

Cloak modules

  • cloak.core - The cloak core: tiny, but used by all the cloak modules
  • cloak.view - Provides the View class
  • cloak.model - Provides the Model and Collection classes for handling data
  • cloak.router - Provides the Router class for all you app routing needs
  • cloak.controller - Provides a super-minimal Controller class for transitioning displaying views
  • cloak.xhr - Provides an easy interface for making HTTP requests by XMLHttpRequest; Also provides an interface to define XHR methods on the Model and Controller classes
  • cloak.localstorage - Provides an easy interface for storing data in local storage; Also provides an interface to use local storage as your main app storage for Model and Collection classes
  • cloak.i18n - Provides a simple internationalization interface for storing translated phrases and determining a client's language
  • cloak.socketio - Provides a socket.io interface for models based on the dagger.js websocket api
  • cloak.animate - Provides animaion methods for controllers and views
  • cloak.forms - Provides an extension to cloak.view for easier handling of forms
  • cloak.nedb - Provides a NeDB (Node Embedded Database) interface for model storage. A faster, more complete local data implementation than cloak.localstorage meant for use in local applications (like node-webkit projects)

Usage

$ npm install --save cloak.core cloak.router
var Router = require('cloak.router');

var MyRouter = module.exports = Router.extend({

    routes: {
        '/':        'welcome',
        '/login':   'login'
    },

    initialize: function() {
        this.on('notfound', this.notfound.bind(this));
    },

    notfound: function() {
        show404Page();
    },

    welcome: function() {
        showHomePage();
    },

    login: function() {
        showLoginPage();
    }

});
var MyRouter = require('./my-router');

var router = new MyRouter();

router.start();

You can use multiple routers together by including one into another; That looks something like this:

var MainRouter = Router.extend({

    routes: {
        // ...
    }

});

// Define another router with some more routes
var RouterA = Router.extend({
    // ...
});

// Define another one for good measure
var RouterB = Router.extend({
    // ...
});

// MainRouter here is the one we will actually interact with directly
var router = new MainRouter();

// Include the other routers, then start
router
    .use(RouterA)
    .use(RouterB)
    .start();

In this example, our MainRouter instance router will now act as if all of RouterA and RouterB's methods were defined directly on MainRotuer, except that they will still be scoped to their original routers (so, for example, RouterA can have it's own private properties and helper functions that are still available through this).