New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

trek-router

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trek-router - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

382

lib/Router.js

@@ -9,4 +9,8 @@ /*!

exports.__esModule = true;
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

@@ -62,14 +66,17 @@

Node.prototype.findChild = function findChild(c) {
var i = 0;
var l = this.children.length;
var e = undefined;
_createClass(Node, [{
key: 'findChild',
value: function findChild(c) {
var i = 0;
var l = this.children.length;
var e = undefined;
for (; i < l; ++i) {
e = this.children[i];
// Compare charCode
if (e.label === c) return e;
for (; i < l; ++i) {
e = this.children[i];
// Compare charCode
if (e.label === c) return e;
}
return undefined;
}
return undefined;
};
}]);

@@ -92,3 +99,3 @@ return Node;

Object.defineProperty(_this, m, {
get: function get() {
get() {
return function verb(path, handler) {

@@ -113,209 +120,214 @@ return this.add(m.toUpperCase(), path, handler);

Router.prototype.add = function add(method, path, handler) {
var i = 0;
var l = path.length;
var pnames = []; // Param names
var ch = undefined,
j = undefined;
_createClass(Router, [{
key: 'add',
value: function add(method, path, handler) {
var i = 0;
var l = path.length;
var pnames = []; // Param names
var ch = undefined,
j = undefined;
for (; i < l; ++i) {
ch = path.charCodeAt(i);
if (ch === COLON) {
j = i + 1;
for (; i < l; ++i) {
ch = path.charCodeAt(i);
if (ch === COLON) {
j = i + 1;
this.insert(method, path.substring(0, i));
for (; i < l && path.charCodeAt(i) !== SLASH; ++i) {}
this.insert(method, path.substring(0, i));
for (; i < l && path.charCodeAt(i) !== SLASH; ++i) {}
pnames.push(path.substring(j, i));
path = path.substring(0, j) + path.substring(i);
i = j;
l = path.length;
pnames.push(path.substring(j, i));
path = path.substring(0, j) + path.substring(i);
i = j;
l = path.length;
if (i === l) {
this.insert(method, path.substring(0, i), handler, pnames);
if (i === l) {
this.insert(method, path.substring(0, i), handler, pnames);
return;
}
this.insert(method, path.substring(0, i));
} else if (ch === STAR) {
this.insert(method, path.substring(0, i));
this.insert(method, path.substring(0, l), handler, pnames);
return;
}
this.insert(method, path.substring(0, i));
} else if (ch === STAR) {
this.insert(method, path.substring(0, i));
this.insert(method, path.substring(0, l), handler, pnames);
return;
}
this.insert(method, path, handler, pnames);
}
this.insert(method, path, handler, pnames);
};
/**
* Insert new route
*
* @method insert
* @private
* @param {String} method
* @param {String} path
* @param {Function|GeneratorFunction} [handler]
* @param {Array} [pnames]
*/
/**
* Insert new route
*
* @method insert
* @private
* @param {String} method
* @param {String} path
* @param {Function|GeneratorFunction} [handler]
* @param {Array} [pnames]
*/
}, {
key: 'insert',
value: function insert(method, path, handler, pnames) {
var cn = this.trees[method]; // Current node as root
var search = path;
var sl = undefined,
pl = undefined,
l = undefined,
n = undefined,
c = undefined;
Router.prototype.insert = function insert(method, path, handler, pnames) {
var cn = this.trees[method]; // Current node as root
var search = path;
var sl = undefined,
pl = undefined,
l = undefined,
n = undefined,
c = undefined;
while (true) {
sl = search.length;
pl = cn.prefix.length;
l = lcp(search, cn.prefix);
while (true) {
sl = search.length;
pl = cn.prefix.length;
l = lcp(search, cn.prefix);
if (l === 0) {
// At root node
cn.label = search.charCodeAt(0);
cn.prefix = search;
if (handler) {
cn.handler = handler;
cn.pnames = pnames;
}
} else if (l < pl) {
// Split node
n = new Node(cn.prefix.substring(l), cn.children, cn.handler, cn.pnames);
cn.children = [n]; // Add to parent
if (l === 0) {
// At root node
cn.label = search.charCodeAt(0);
cn.prefix = search;
if (handler) {
cn.handler = handler;
cn.pnames = pnames;
}
} else if (l < pl) {
// Split node
n = new Node(cn.prefix.substring(l), cn.children, cn.handler, cn.pnames);
cn.children = [n]; // Add to parent
// Reset parent node
cn.label = cn.prefix.charCodeAt(0);
cn.prefix = cn.prefix.substring(0, l);
cn.handler = undefined;
cn.pnames = undefined;
// Reset parent node
cn.label = cn.prefix.charCodeAt(0);
cn.prefix = cn.prefix.substring(0, l);
cn.handler = undefined;
cn.pnames = undefined;
if (l === sl) {
// At parent node
cn.handler = handler;
cn.pnames = pnames;
} else {
if (l === sl) {
// At parent node
cn.handler = handler;
cn.pnames = pnames;
} else {
// Create child node
n = new Node(search.substring(l), [], handler, pnames);
cn.children.push(n);
}
} else if (l < sl) {
search = search.substring(l);
c = cn.findChild(search.charCodeAt(0));
if (c !== undefined) {
// Go deeper
cn = c;
continue;
}
// Create child node
n = new Node(search.substring(l), [], handler, pnames);
n = new Node(search, [], handler, pnames);
cn.children.push(n);
} else {
// Node already exists
if (handler) {
cn.handler = handler;
cn.pnames = pnames;
}
}
} else if (l < sl) {
search = search.substring(l);
c = cn.findChild(search.charCodeAt(0));
if (c !== undefined) {
// Go deeper
cn = c;
continue;
}
// Create child node
n = new Node(search, [], handler, pnames);
cn.children.push(n);
} else {
// Node already exists
if (handler) {
cn.handler = handler;
cn.pnames = pnames;
}
return;
}
return;
}
};
/**
* Find route by method and path
*
* @method find
* @param {String} method
* @param {String} path
* @return {Array} result
* @property {Undefined|Function|GeneratorFunction} result[0]
* @property {Array} result[1]
*/
/**
* Find route by method and path
*
* @method find
* @param {String} method
* @param {String} path
* @return {Array} result
* @property {Undefined|Function|GeneratorFunction} result[0]
* @property {Array} result[1]
*/
}, {
key: 'find',
value: function find(method, path, cn, n, result) {
cn = cn || this.trees[method]; // Current node as root
n = n || 0; // Param count
result = result || [undefined, []];
var search = path;
var params = result[1]; // Params
var pl = undefined,
l = undefined,
leq = undefined,
c = undefined;
var preSearch = undefined; // Pre search
Router.prototype.find = function find(method, path, cn, n, result) {
cn = cn || this.trees[method]; // Current node as root
n = n || 0; // Param count
result = result || [undefined, []];
var search = path;
var params = result[1]; // Params
var pl = undefined,
l = undefined,
leq = undefined,
c = undefined;
var preSearch = undefined; // Pre search
// Search order static > param > match-any
if (search.length === 0 || search === cn.prefix) {
// Found
result[0] = cn.handler;
if (cn.handler !== undefined) {
var pnames = cn.pnames;
if (pnames !== undefined) {
var _i = 0;
var _l = pnames.length;
for (; _i < _l; ++_i) {
params[_i].name = pnames[_i];
// Search order static > param > match-any
if (search.length === 0 || search === cn.prefix) {
// Found
result[0] = cn.handler;
if (cn.handler !== undefined) {
var pnames = cn.pnames;
if (pnames !== undefined) {
var _i = 0;
var _l = pnames.length;
for (; _i < _l; ++_i) {
params[_i].name = pnames[_i];
}
}
}
return result;
}
return result;
}
pl = cn.prefix.length;
l = lcp(search, cn.prefix);
leq = l === pl;
pl = cn.prefix.length;
l = lcp(search, cn.prefix);
leq = l === pl;
if (leq) {
search = search.substring(l);
}
preSearch = search;
if (leq) {
search = search.substring(l);
}
preSearch = search;
// Static node
c = cn.findChild(search.charCodeAt(0));
if (c !== undefined) {
this.find(method, search, c, n, result);
if (result[0] !== undefined) return result;
search = preSearch;
}
// Static node
c = cn.findChild(search.charCodeAt(0));
if (c !== undefined) {
this.find(method, search, c, n, result);
if (result[0] !== undefined) return result;
search = preSearch;
}
// Not found node
if (!leq) {
return result;
}
// Not found node
if (!leq) {
return result;
}
// Param node
c = cn.findChild(COLON);
if (c !== undefined) {
l = search.length;
for (var i = 0; i < l && search.charCodeAt(i) !== SLASH; ++i) {}
// Param node
c = cn.findChild(COLON);
if (c !== undefined) {
l = search.length;
for (var i = 0; i < l && search.charCodeAt(i) !== SLASH; ++i) {}
params[n] = {
value: search.substring(0, i)
};
params[n] = {
value: search.substring(0, i)
};
n++;
preSearch = search;
search = search.substring(i);
n++;
preSearch = search;
search = search.substring(i);
this.find(method, search, c, n, result);
if (result[0] !== undefined) return result;
this.find(method, search, c, n, result);
if (result[0] !== undefined) return result;
n--;
params.shift();
search = preSearch;
}
n--;
params.shift();
search = preSearch;
}
// Match-any node
c = cn.findChild(STAR);
if (c !== undefined) {
params[n] = {
name: '_*',
value: search
};
search = ''; // End search
this.find(method, search, c, n, result);
// Match-any node
c = cn.findChild(STAR);
if (c !== undefined) {
params[n] = {
name: '_*',
value: search
};
search = ''; // End search
this.find(method, search, c, n, result);
}
return result;
}
}]);
return result;
};
return Router;

@@ -326,3 +338,3 @@ })();

var i = 0;
var max = min(a.length, b.length);
const max = min(a.length, b.length);
for (; i < max && a.charCodeAt(i) === b.charCodeAt(i); ++i) {}

@@ -329,0 +341,0 @@ return i;

{
"name": "trek-router",
"version": "0.5.0",
"version": "0.5.1",
"description": "A fast HTTP router",

@@ -18,6 +18,6 @@ "repository": "trekjs/router",

"benchmark": "node benchmarks",
"compile": "babel src --out-dir lib --copy-files",
"prepublish": "npm run compile",
"test": "mocha --require babel/register --require should --reporter spec --bail --check-leaks test/**/*.test.js",
"test-ci": "babel-node node_modules/.bin/isparta cover node_modules/.bin/_mocha --report lcovonly -- --require should --reporter spec --check-leaks test/**/*.test.js",
"build": "babel src --out-dir lib",
"prepublish": "npm run build",
"test": "mocha --require babel/register --reporter spec --bail --check-leaks test/**/*.test.js",
"test-ci": "babel-node node_modules/.bin/isparta cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/**/*.test.js",
"test-cov": "babel-node node_modules/.bin/isparta cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/**/*.test.js"

@@ -30,10 +30,10 @@ },

"isparta": "^3.x",
"istanbul": "^0.3.20",
"istanbul": "^0.4.0",
"lodash": "^3.10.1",
"mocha": "^2.3.2",
"mocha": "^2.3.3",
"path-to-regexp": "^1.2.1",
"power-assert": "^1.0.1",
"route-recognizer": "^0.1.7",
"route-trie": "^1.0.1",
"routington": "^1.0.3",
"should": "^7.1.0",
"supertest": "^1.1.0"

@@ -47,8 +47,17 @@ },

"engines": {
"iojs": "*",
"node": ">= 0.8.0"
"node": ">= 4"
},
"dependencies": {
"methods": "^1.1.1"
},
"babel": {
"blacklist": [
"regenerator",
"es6.constants",
"es6.properties.computed",
"es6.properties.shorthand",
"es6.tailCall",
"es6.templateLiterals"
]
}
}
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