Minimal, fast javascript URL router
PogoScript JavaScript Makefile
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bench
spec
src
test
.gitignore
Makefile
README.md
package.json

README.md

Routism

A minimalist and fast JavaScript router

Install

npm install routism

Usage

routism = require 'routism'

routes = [
  { pattern = "/",              route = 'home' }
  { pattern = "/posts",         route = 'list posts' }
  { pattern = "/posts/:id",     route = 'show post' }
  { pattern = "/stuff/:path*",  route = 'show stuff' }
]
router = routism.compile (routes)

router.recognise('/')             // { route = 'home', params = {} }
router.recognise('/posts')        // { route = 'list posts', params = {} }
router.recognise('/posts/123')    // { route = 'show post',  params = [['id', '123']] }
router.recognise('/stuff/1/2/3')  // { route = 'show stuff', params = [['path', '1/2/3']] }

Builder

routism = require 'routism'

routes = routism.table ()
routes.add ('/', 'home')
routes.add ('/posts', 'list posts')
routes.add ('/posts/:id', 'show post')
router = routes.compile ()

router.recognise('/')           // { route = 'home', params = [] }
router.recognise('/posts')      // { route = 'list posts', params = [] }
router.recognise('/posts/123')  // { route = 'show post', params = [['id', '123']] }

Compile Pattern

routism = require 'routism'
matchesSubpath = new (RegExp ("^#(routism.compilePattern '/posts/:id')"))
matchesSubpath.test '/posts/blah/comments' // true

Connect

See the specs

License

BSD