1.2.0 • Published 10 years ago

routism v1.2.0

Weekly downloads
3
License
BSD
Repository
github
Last release
10 years ago

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

1.2.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.2

12 years ago

0.0.1

12 years ago