Comparing version 3.2.0 to 3.2.1
22
index.js
const parse = require('regexparam'); | ||
const MAP = { | ||
"": 0, | ||
GET: 1, | ||
HEAD: 2, | ||
PATCH: 3, | ||
OPTIONS: 4, | ||
CONNECT: 5, | ||
DELETE: 6, | ||
TRACE: 7, | ||
POST: 8, | ||
PUT: 9, | ||
}; | ||
module.exports = class Trouter { | ||
@@ -22,3 +35,3 @@ constructor() { | ||
let { keys, pattern } = parse(route, true); | ||
this.routes.push({ keys, pattern, method:'', handlers }); | ||
this.routes.push({ keys, pattern, method: '', handlers, midx: MAP[''] }); | ||
return this; | ||
@@ -30,3 +43,3 @@ } | ||
let handlers = [].concat.apply([], fns); | ||
this.routes.push({ keys, pattern, method, handlers }); | ||
this.routes.push({ keys, pattern, method, handlers, midx: MAP[method] }); | ||
return this; | ||
@@ -36,3 +49,4 @@ } | ||
find(method, url) { | ||
let isHEAD=(method === 'HEAD'); | ||
let midx = MAP[method]; | ||
let isHEAD = (midx === 2); | ||
let i=0, j=0, k, tmp, arr=this.routes; | ||
@@ -42,3 +56,3 @@ let matches=[], params={}, handlers=[]; | ||
tmp = arr[i]; | ||
if (tmp.method.length === 0 || tmp.method === method || isHEAD && tmp.method === 'GET') { | ||
if (tmp.midx === midx || tmp.midx === 0 || (isHEAD && tmp.midx===1) ) { | ||
if (tmp.keys === false) { | ||
@@ -45,0 +59,0 @@ matches = tmp.pattern.exec(url); |
{ | ||
"name": "trouter", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"repository": "lukeed/trouter", | ||
@@ -5,0 +5,0 @@ "description": "🐟 A fast, small-but-mighty, familiar ~fish~ router", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14097
154