trek-router
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -14,5 +14,5 @@ 'use strict'; | ||
const SNODE = 0; // static route | ||
const PNODE = 1; // param route | ||
const ANODE = 2; // all star route | ||
const SNODE = 0; // Static node | ||
const PNODE = 1; // Param node | ||
const ANODE = 2; // Catch-all node | ||
@@ -59,5 +59,3 @@ let Node = (function () { | ||
Router.prototype.add = function add(method, path, handler) { | ||
var i = 0, | ||
l = path.length; | ||
for (; i < l; i++) { | ||
for (let i = 0, l = path.length; i < l; i++) { | ||
// `:` | ||
@@ -143,4 +141,4 @@ if (path.charCodeAt(i) === 58) { | ||
let n = 0; // Param count | ||
let result = [null]; | ||
let params = []; | ||
let result = [null, []]; | ||
let params = result[1]; | ||
@@ -160,32 +158,31 @@ while (true) { | ||
search = search.substring(l); | ||
switch (cn.has) { | ||
case PNODE: | ||
cn = cn.edges[0]; | ||
var i = 0; | ||
l = search.length; | ||
// `/` | ||
for (; i < l && search.charCodeAt(i) !== 47; i++) {} | ||
if (cn.has === PNODE) { | ||
// Param node | ||
cn = cn.edges[0]; | ||
var i = 0; | ||
l = search.length; | ||
// `/` | ||
for (; i < l && search.charCodeAt(i) !== 47; i++) {} | ||
params[n] = { | ||
name: cn.prefix.substring(1), | ||
value: search.substring(0, i) | ||
}; | ||
n++; | ||
params[n] = { | ||
name: cn.prefix.substring(1), | ||
value: search.substring(0, i) | ||
}; | ||
n++; | ||
search = search.substring(i); | ||
search = search.substring(i); | ||
} else if (cn.has === ANODE) { | ||
// Catch-all node | ||
params[n] = { | ||
name: cn.prefix.substring(1), | ||
value: search.substring(0, i) | ||
}; | ||
search = ''; // End search | ||
} | ||
if (i === l) { | ||
// All params read | ||
continue; | ||
} | ||
break; | ||
case ANODE: | ||
params[n] = { | ||
name: cn.prefix.substring(1), | ||
value: search.substring(0, i) | ||
}; | ||
search = ''; // End search | ||
continue; | ||
if (search.length === 0) { | ||
continue; | ||
} | ||
// Dig more | ||
let e = cn.findEdge(search[0]); | ||
@@ -192,0 +189,0 @@ if (!e) { |
{ | ||
"name": "trek-router", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "A fast HTTP router router", | ||
@@ -5,0 +5,0 @@ "repository": "trekjs/router", |
9125
183