Route your data through a series of middleware functions.
$ npm install switched
var router = ;router;router;router;router;;
Features
- Express-like routing capabilties for data.
- Gives you more control over how data is handled.
- Attach
Switched
instances to otherSwitched
instances. - Support for "wildcard" (*) and Regular Expression matching.
API
Router
Get the Router
class.
var Router = ;
The use
and on
methods are equivalent. They also can be chained.
var router = ;
Router#()
Make a Router
instance
var router = ;
Router#use(fn:Function, ...)
Attach a function
to the router.
router;
You can pass in multiple function
s.
var { };var { };var { }; router;
You can pass in a function that accepts an Error
object.
router;
Router#use(event:String, fn:Function, ...)
Bind the function
to the event
.
router;
You can also pass in multiple function
s for handling the event
.
var { };var { };var { }; router;
Router#use(event:RegExp, fn:Function, ...)
Bind the function
using a RegExp
pattern to match the event
.
router;
You can also pass in multiple function
s for handling the event
.
var { };var { };var { }; router;
Router#use(router:Router, ...)
You can attach another Router
instance to your Router
instance.
var another = ;another; router;
Attach multiple routers in a single call.
var foo = ;foo; var bar = ;bar; var baz = ;baz; router;
Router#use(name:String, router:Router, ...)
Just like attaching a function
to the router given the event
. You can attach Router
instance as well to the event
.
var foo = ;foo; router;
Attach multiple routers in a single call to the event
too.
var foo = ;foo; var bar = ;bar; var baz = ;baz; router;
Router#use(fns:Array, ...)
Attach an Array
of Fuction
's or Router
instances, or an Array
or Array
s .
var middleware = { ; } { ; } { ; } ; var { ; } router;
Router#use(name:String, fns:Array, ...)
Attach everything to an event.
var middleware = { ; } { ; } { ; } ; var { ; } router;
Router#on(...)
This is an alias to to the use
method. It does the same thing.
router;
Installation and Environment Setup
Install node.js (See download and install instructions here: http://nodejs.org/).
Clone this repository
> git clone git@github.com:turbonetix/switched.git
cd into the directory and install the dependencies
> cd switched
> npm install && npm shrinkwrap --dev
Running Tests
Install coffee-script
> npm install coffee-script -g
Tests are run using grunt. You must first globally install the grunt-cli with npm.
> sudo npm install -g grunt-cli
Unit Tests
To run the tests, just run grunt
> grunt spec