routism
A JavaScript router
Last updated 5 years ago by refractalize .
BSD · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install routism 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.2.0                                ...           latest (5 years ago)

8 Versions

  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.2                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (10)

Copyright 2014 - 2016 © taobao.org |