Comparing version 0.0.0 to 0.1.0
@@ -1,2 +0,34 @@ | ||
module.exports = function () { | ||
const { exec, match, parse } = require('matchit'); | ||
const METHODS = ['GET', 'POST', 'PUT', 'DELETE']; | ||
class Trouter { | ||
constructor(opts) { | ||
this.opts = opts || {}; | ||
this.routes = {}; | ||
this.handlers = {}; | ||
METHODS.forEach(str => { | ||
this[str.toLowerCase()] = this.add.bind(this, str); | ||
this.handlers[str] = {}; | ||
this.routes[str] = []; | ||
}); | ||
} | ||
add(method, pattern, handler) { | ||
// Save decoded pattern info | ||
this.routes[method].push(parse(pattern)); | ||
// Save route handler | ||
this.handlers[method][pattern] = handler; | ||
} | ||
find(method, url) { | ||
let arr = match(url, this.routes[method]); | ||
if (!arr.length) return false; | ||
return { | ||
params: exec(url, arr), | ||
handler: this.handlers[method][arr[0].old] | ||
}; | ||
} | ||
} | ||
module.exports = Trouter; |
{ | ||
"name": "trouter", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "WIP", | ||
@@ -24,2 +24,5 @@ "repository": "lukeed/mri", | ||
"keywords": [], | ||
"dependencies": { | ||
"matchit": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -26,0 +29,0 @@ "tap-spec": "^4.1.1", |
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
2763
29
0
1
+ Addedmatchit@^1.0.0
+ Added@arr/every@1.0.1(transitive)
+ Addedmatchit@1.1.0(transitive)