Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

trouter

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trouter - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

34

lib/index.js

@@ -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;

5

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc