8 Commits (74f1f119e16907c9a0ca82ff45f5167de92fc6f6)

Author SHA1 Message Date
Buddy Sandidge ff7d7a252b Update dependencies to fix vulnerabilities 6 years ago
Buddy Sandidge 2784f9d492 Add the ability to pass arguments to the route handler at route time
Arguments passed in to the route method at route time will be passed in
to the handler for that route.

var router = new Router()
router.add('/some/path' function (someParam) {
    // someParam would be 123
})
router.route('/some/path', {args: [123]})
9 years ago
Buddy Sandidge 79fb5395ab Correctly handle not found errors in partial routes
Take care of obvious case. A router with a route to '/foo/bar' but not
for '/foo', should give a not found error.
9 years ago
Buddy Sandidge 62e6469ec7 Add static isNotFound error checker to Router class
If used, it will allow the error message to change without inspecting
the error.message
9 years ago
Buddy Sandidge f89bc55105 Refactor RouteNode → flatten for better readability 9 years ago
Buddy Sandidge 7c34964dff Add support for functions in router
Can add a function as to match a route. The function takes in a string
url segment and returns some value if the route matches or returns null
or undefined for no match.

Example usage:

function toInt(part) {
  var results = /^(\d+)$/.exec(part)
  return results ? parseInt(results[0], 10) : null
}

var router = new Router()
router.add(['/by/order', toInt], function (val) {
  // val === 123
})

router.route('/by/order/123')
9 years ago
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
Buddy Sandidge 10371b7b1e Add Router that only matches exact strings with bootstrapped project
• Add linting with eslint
 • Add unit testing support with mocha with unit tests
 • Add Router class with support for only matching exact strings
 • Add RouteNode class for transversing all routes
9 years ago