You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Buddy Sandidge a317aa86a8 Add support for regular expressions with capture groups
Router
    • add can take either a string or array
        • An array will check each item, for a string will be converted
          to an array

RouteNode
    • rename this._exact → this._children
        • exact matches will not have a '/' in a key because we split on
          the '/' character and RegExp will have a '/' in it
    • If an exact match can't be found first, check every regex on a node
        • Exact match will have preference over RegExp

utils
    • add forEach helper
    • add isArray and isRegExp checker
9 years ago
lib Add support for regular expressions with capture groups 9 years ago
test Add support for regular expressions with capture groups 9 years ago
.eslintrc Add Router that only matches exact strings with bootstrapped project 9 years ago
.gitignore Initial commit 9 years ago
LICENSE Initial commit 9 years ago
README.md Add Router that only matches exact strings with bootstrapped project 9 years ago
package.json Add Router that only matches exact strings with bootstrapped project 9 years ago

README.md

routing-buddy

Yet another routing library in JavaScript. This project was created after looking at and trying several JavaScript routing libraries out there and not finding one that really worked that way I wanted it to work. I wanted a library that could be used both on the client and server side without feeling like it was designed for one side with the other bolted on like it was an afterthought. I also wanted a library that gave more flexibility for defining routes.

Status

NOTE: This is currently a Work in progress. I'm not yet sure if this will be the routing library I want.

Design

The main class exported in this library is Router. Router is a wrapper around RouteNode. A RouteNode is a tree structure to define all routes.

For development

To run unit tests:

$ # run unit tests and lint
$ npm test
$ # run unit tests only
$ mocha
$ # run linter only
$ eslint

See unit tests for more details.

Usage:

var Router = require('routing-buddy')

var router = new Router()

// Define a handler to be called when routed to the url
router.add('/some/path/here', function () {
  // do something for '/some/path/here'
})

// Get the handler for '/some/path/here' and call it.
// Call the callback after finding the route
router.route('/some/path/here', function (err, maybeResults) {
  // `err` will be either null or Error.
  //    null: everything was fine
  //    Error: missing route or any other error that might happen
  // maybeResults: The return value from the hander from add
})