mixdown-router
Advanced tools
Comparing version 4.0.5 to 4.1.0
var _ = require('lodash'); | ||
var regexSplit = /(\?|\/)([^\?^\/]+)/g; | ||
module.exports = function(s, params) { | ||
module.exports = function (s, params) { | ||
s = s || ''; | ||
@@ -10,2 +10,5 @@ | ||
// this is here so that we can detect when a literal router is being used so we can match a url with or without a trailing slash. | ||
var bHasParsableRestParams = false; | ||
if (!restParams || restParams.length === 0) { | ||
@@ -16,4 +19,4 @@ restParams = [s]; | ||
// replace named params with corresponding regexs and build paramMap. | ||
_.each(restParams, function(str, i) { | ||
var param = _.find(params, function(p, name) { | ||
_.each(restParams, function (str, i) { | ||
var param = _.find(params, function (p, name) { | ||
return str.substring(1) === ':' + name; | ||
@@ -23,2 +26,5 @@ }); | ||
if (param) { | ||
bHasParsableRestParams = true; // we found a parseable param | ||
var rstr = param.regex.toString(); | ||
@@ -36,2 +42,7 @@ var optChar = (str[0] === '?' ? '?' : ''); | ||
// push optional trailing slash to the regex. | ||
if (!bHasParsableRestParams) { | ||
urlformat.push('\\/?'); | ||
} | ||
return { | ||
@@ -38,0 +49,0 @@ urlformat: new RegExp('^' + urlformat.join('') + '$'), |
{ | ||
"name": "mixdown-router", | ||
"version": "4.0.5", | ||
"version": "4.1.0", | ||
"description": "Router for mixdown.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
71165
1709