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

route-recognizer

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

route-recognizer - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

.vscode/launch.json

2

Brocfile.js

@@ -6,3 +6,3 @@ var compileModules = require('broccoli-compile-modules');

var concat = require('broccoli-concat');
var replace = require('broccoli-replace');
var replace = require('broccoli-string-replace');

@@ -9,0 +9,0 @@ /**

@@ -33,9 +33,11 @@ import map from './route-recognizer/dsl';

StaticSegment.prototype = {
eachChar: function(callback) {
eachChar: function(currentState) {
var string = this.string, ch;
for (var i=0, l=string.length; i<l; i++) {
for (var i=0; i<string.length; i++) {
ch = string.charAt(i);
callback({ validChars: ch });
currentState = currentState.put({ invalidChars: undefined, repeat: false, validChars: ch });
}
return currentState;
},

@@ -54,4 +56,4 @@

DynamicSegment.prototype = {
eachChar: function(callback) {
callback({ invalidChars: "/", repeat: true });
eachChar: function(currentState) {
return currentState.put({ invalidChars: "/", repeat: true, validChars: undefined });
},

@@ -70,4 +72,4 @@

StarSegment.prototype = {
eachChar: function(callback) {
callback({ invalidChars: "", repeat: true });
eachChar: function(currentState) {
return currentState.put({ invalidChars: "", repeat: true, validChars: undefined });
},

@@ -86,3 +88,5 @@

EpsilonSegment.prototype = {
eachChar: function() {},
eachChar: function(currentState) {
return currentState;
},
regex: function() { return ""; },

@@ -97,3 +101,4 @@ generate: function() { return ""; }

var segments = route.split("/"), results = [];
var segments = route.split("/");
var results = new Array(segments.length);

@@ -121,18 +126,18 @@ // A routes has specificity determined by the order that its different segments

for (var i=0, l=segments.length; i<l; i++) {
for (var i=0; i<segments.length; i++) {
var segment = segments[i], match;
if (match = segment.match(/^:([^\/]+)$/)) {
results.push(new DynamicSegment(match[1]));
results[i] = new DynamicSegment(match[1]);
names.push(match[1]);
specificity.val += '3';
} else if (match = segment.match(/^\*([^\/]+)$/)) {
results.push(new StarSegment(match[1]));
specificity.val += '2';
results[i] = new StarSegment(match[1]);
specificity.val += '1';
names.push(match[1]);
} else if(segment === "") {
results.push(new EpsilonSegment());
specificity.val += '1';
results[i] = new EpsilonSegment();
specificity.val += '2';
} else {
results.push(new StaticSegment(segment));
results[i] = new StaticSegment(segment);
specificity.val += '4';

@@ -167,2 +172,6 @@ }

this.nextStates = [];
this.charSpecs = {};
this.regex = undefined;
this.handlers = undefined;
this.specificity = undefined;
}

@@ -172,5 +181,9 @@

get: function(charSpec) {
if (this.charSpecs[charSpec.validChars]) {
return this.charSpecs[charSpec.validChars];
}
var nextStates = this.nextStates;
for (var i=0, l=nextStates.length; i<l; i++) {
for (var i=0; i<nextStates.length; i++) {
var child = nextStates[i];

@@ -181,3 +194,6 @@

if (isEqual) { return child; }
if (isEqual) {
this.charSpecs[charSpec.validChars] = child;
return child;
}
}

@@ -219,3 +235,3 @@ },

for (var i=0, l=nextStates.length; i<l; i++) {
for (var i=0; i<nextStates.length; i++) {
child = nextStates[i];

@@ -306,10 +322,12 @@

for (var i=0, l=handlers.length; i<l; i++) {
result.length = handlers.length;
for (var i=0; i<handlers.length; i++) {
var handler = handlers[i], names = handler.names, params = {};
for (var j=0, m=names.length; j<m; j++) {
for (var j=0; j<names.length; j++) {
params[names[j]] = captures[currentCapture++];
}
result.push({ handler: handler.handler, params: params, isDynamic: !!names.length });
result[i] = { handler: handler.handler, params: params, isDynamic: !!names.length };
}

@@ -320,16 +338,10 @@

function addSegment(currentState, segment) {
segment.eachChar(function(ch) {
var state;
currentState = currentState.put(ch);
});
return currentState;
}
function decodeQueryParamPart(part) {
// http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
part = part.replace(/\+/gm, '%20');
return decodeURIComponent(part);
var result;
try {
result = decodeURIComponent(part);
} catch(error) {result = '';}
return result;
}

@@ -349,7 +361,7 @@

specificity = {},
handlers = [], allSegments = [], name;
handlers = new Array(routes.length), allSegments = [], name;
var isEmpty = true;
for (var i=0, l=routes.length; i<l; i++) {
for (var i=0; i<routes.length; i++) {
var route = routes[i], names = [];

@@ -361,3 +373,3 @@

for (var j=0, m=segments.length; j<m; j++) {
for (var j=0; j<segments.length; j++) {
var segment = segments[j];

@@ -370,16 +382,15 @@

// Add a "/" for the new segment
currentState = currentState.put({ validChars: "/" });
currentState = currentState.put({ invalidChars: undefined, repeat: false, validChars: "/" });
regex += "/";
// Add a representation of the segment to the NFA and regex
currentState = addSegment(currentState, segment);
currentState = segment.eachChar(currentState);
regex += segment.regex();
}
var handler = { handler: route.handler, names: names };
handlers.push(handler);
handlers[i] = handler;
}
if (isEmpty) {
currentState = currentState.put({ validChars: "/" });
currentState = currentState.put({ invalidChars: undefined, repeat: false, validChars: "/" });
regex += "/";

@@ -401,7 +412,10 @@ }

handlersFor: function(name) {
var route = this.names[name], result = [];
var route = this.names[name];
if (!route) { throw new Error("There is no route named " + name); }
for (var i=0, l=route.handlers.length; i<l; i++) {
result.push(route.handlers[i]);
var result = new Array(route.handlers.length);
for (var i=0; i<route.handlers.length; i++) {
result[i] = route.handlers[i];
}

@@ -422,3 +436,3 @@

for (var i=0, l=segments.length; i<l; i++) {
for (var i=0; i<segments.length; i++) {
var segment = segments[i];

@@ -450,3 +464,3 @@

keys.sort();
for (var i = 0, len = keys.length; i < len; i++) {
for (var i = 0; i < keys.length; i++) {
key = keys[i];

@@ -459,3 +473,3 @@ var value = params[key];

if (isArray(value)) {
for (var j = 0, l = value.length; j < l; j++) {
for (var j = 0; j < value.length; j++) {
var arrayPair = key + '[]' + '=' + encodeURIComponent(value[j]);

@@ -529,3 +543,3 @@ pairs.push(arrayPair);

for (i=0, l=path.length; i<l; i++) {
for (i=0; i<path.length; i++) {
states = recognizeChar(states, path.charAt(i));

@@ -538,3 +552,3 @@ if (!states.length) { break; }

var solutions = [];
for (i=0, l=states.length; i<l; i++) {
for (i=0; i<states.length; i++) {
if (states[i].handlers) { solutions.push(states[i]); }

@@ -541,0 +555,0 @@ }

@@ -64,3 +64,3 @@ function Target(path, matcher, delegate) {

var len = 0;
for (var i=0, l=routeArray.length; i<l; i++) {
for (var i=0; i<routeArray.length; i++) {
len += routeArray[i].path.length;

@@ -67,0 +67,0 @@ }

@@ -66,3 +66,3 @@ (function() {

var len = 0;
for (var i=0, l=routeArray.length; i<l; i++) {
for (var i=0; i<routeArray.length; i++) {
len += routeArray[i].path.length;

@@ -134,9 +134,11 @@ }

$$route$recognizer$$StaticSegment.prototype = {
eachChar: function(callback) {
eachChar: function(currentState) {
var string = this.string, ch;
for (var i=0, l=string.length; i<l; i++) {
for (var i=0; i<string.length; i++) {
ch = string.charAt(i);
callback({ validChars: ch });
currentState = currentState.put({ invalidChars: undefined, repeat: false, validChars: ch });
}
return currentState;
},

@@ -155,4 +157,4 @@

$$route$recognizer$$DynamicSegment.prototype = {
eachChar: function(callback) {
callback({ invalidChars: "/", repeat: true });
eachChar: function(currentState) {
return currentState.put({ invalidChars: "/", repeat: true, validChars: undefined });
},

@@ -171,4 +173,4 @@

$$route$recognizer$$StarSegment.prototype = {
eachChar: function(callback) {
callback({ invalidChars: "", repeat: true });
eachChar: function(currentState) {
return currentState.put({ invalidChars: "", repeat: true, validChars: undefined });
},

@@ -187,3 +189,5 @@

$$route$recognizer$$EpsilonSegment.prototype = {
eachChar: function() {},
eachChar: function(currentState) {
return currentState;
},
regex: function() { return ""; },

@@ -198,3 +202,4 @@ generate: function() { return ""; }

var segments = route.split("/"), results = [];
var segments = route.split("/");
var results = new Array(segments.length);

@@ -222,18 +227,18 @@ // A routes has specificity determined by the order that its different segments

for (var i=0, l=segments.length; i<l; i++) {
for (var i=0; i<segments.length; i++) {
var segment = segments[i], match;
if (match = segment.match(/^:([^\/]+)$/)) {
results.push(new $$route$recognizer$$DynamicSegment(match[1]));
results[i] = new $$route$recognizer$$DynamicSegment(match[1]);
names.push(match[1]);
specificity.val += '3';
} else if (match = segment.match(/^\*([^\/]+)$/)) {
results.push(new $$route$recognizer$$StarSegment(match[1]));
specificity.val += '2';
results[i] = new $$route$recognizer$$StarSegment(match[1]);
specificity.val += '1';
names.push(match[1]);
} else if(segment === "") {
results.push(new $$route$recognizer$$EpsilonSegment());
specificity.val += '1';
results[i] = new $$route$recognizer$$EpsilonSegment();
specificity.val += '2';
} else {
results.push(new $$route$recognizer$$StaticSegment(segment));
results[i] = new $$route$recognizer$$StaticSegment(segment);
specificity.val += '4';

@@ -268,2 +273,6 @@ }

this.nextStates = [];
this.charSpecs = {};
this.regex = undefined;
this.handlers = undefined;
this.specificity = undefined;
}

@@ -273,5 +282,9 @@

get: function(charSpec) {
if (this.charSpecs[charSpec.validChars]) {
return this.charSpecs[charSpec.validChars];
}
var nextStates = this.nextStates;
for (var i=0, l=nextStates.length; i<l; i++) {
for (var i=0; i<nextStates.length; i++) {
var child = nextStates[i];

@@ -282,3 +295,6 @@

if (isEqual) { return child; }
if (isEqual) {
this.charSpecs[charSpec.validChars] = child;
return child;
}
}

@@ -320,3 +336,3 @@ },

for (var i=0, l=nextStates.length; i<l; i++) {
for (var i=0; i<nextStates.length; i++) {
child = nextStates[i];

@@ -407,10 +423,12 @@

for (var i=0, l=handlers.length; i<l; i++) {
result.length = handlers.length;
for (var i=0; i<handlers.length; i++) {
var handler = handlers[i], names = handler.names, params = {};
for (var j=0, m=names.length; j<m; j++) {
for (var j=0; j<names.length; j++) {
params[names[j]] = captures[currentCapture++];
}
result.push({ handler: handler.handler, params: params, isDynamic: !!names.length });
result[i] = { handler: handler.handler, params: params, isDynamic: !!names.length };
}

@@ -421,16 +439,10 @@

function $$route$recognizer$$addSegment(currentState, segment) {
segment.eachChar(function(ch) {
var state;
currentState = currentState.put(ch);
});
return currentState;
}
function $$route$recognizer$$decodeQueryParamPart(part) {
// http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
part = part.replace(/\+/gm, '%20');
return decodeURIComponent(part);
var result;
try {
result = decodeURIComponent(part);
} catch(error) {result = '';}
return result;
}

@@ -450,7 +462,7 @@

specificity = {},
handlers = [], allSegments = [], name;
handlers = new Array(routes.length), allSegments = [], name;
var isEmpty = true;
for (var i=0, l=routes.length; i<l; i++) {
for (var i=0; i<routes.length; i++) {
var route = routes[i], names = [];

@@ -462,3 +474,3 @@

for (var j=0, m=segments.length; j<m; j++) {
for (var j=0; j<segments.length; j++) {
var segment = segments[j];

@@ -471,16 +483,15 @@

// Add a "/" for the new segment
currentState = currentState.put({ validChars: "/" });
currentState = currentState.put({ invalidChars: undefined, repeat: false, validChars: "/" });
regex += "/";
// Add a representation of the segment to the NFA and regex
currentState = $$route$recognizer$$addSegment(currentState, segment);
currentState = segment.eachChar(currentState);
regex += segment.regex();
}
var handler = { handler: route.handler, names: names };
handlers.push(handler);
handlers[i] = handler;
}
if (isEmpty) {
currentState = currentState.put({ validChars: "/" });
currentState = currentState.put({ invalidChars: undefined, repeat: false, validChars: "/" });
regex += "/";

@@ -502,7 +513,10 @@ }

handlersFor: function(name) {
var route = this.names[name], result = [];
var route = this.names[name];
if (!route) { throw new Error("There is no route named " + name); }
for (var i=0, l=route.handlers.length; i<l; i++) {
result.push(route.handlers[i]);
var result = new Array(route.handlers.length);
for (var i=0; i<route.handlers.length; i++) {
result[i] = route.handlers[i];
}

@@ -523,3 +537,3 @@

for (var i=0, l=segments.length; i<l; i++) {
for (var i=0; i<segments.length; i++) {
var segment = segments[i];

@@ -551,3 +565,3 @@

keys.sort();
for (var i = 0, len = keys.length; i < len; i++) {
for (var i = 0; i < keys.length; i++) {
key = keys[i];

@@ -560,3 +574,3 @@ var value = params[key];

if ($$route$recognizer$$isArray(value)) {
for (var j = 0, l = value.length; j < l; j++) {
for (var j = 0; j < value.length; j++) {
var arrayPair = key + '[]' + '=' + encodeURIComponent(value[j]);

@@ -630,3 +644,3 @@ pairs.push(arrayPair);

for (i=0, l=path.length; i<l; i++) {
for (i=0; i<path.length; i++) {
states = $$route$recognizer$$recognizeChar(states, path.charAt(i));

@@ -639,3 +653,3 @@ if (!states.length) { break; }

var solutions = [];
for (i=0, l=states.length; i<l; i++) {
for (i=0; i<states.length; i++) {
if (states[i].handlers) { solutions.push(states[i]); }

@@ -642,0 +656,0 @@ }

@@ -33,9 +33,11 @@ import map from './route-recognizer/dsl';

StaticSegment.prototype = {
eachChar: function(callback) {
eachChar: function(currentState) {
var string = this.string, ch;
for (var i=0, l=string.length; i<l; i++) {
for (var i=0; i<string.length; i++) {
ch = string.charAt(i);
callback({ validChars: ch });
currentState = currentState.put({ invalidChars: undefined, repeat: false, validChars: ch });
}
return currentState;
},

@@ -54,4 +56,4 @@

DynamicSegment.prototype = {
eachChar: function(callback) {
callback({ invalidChars: "/", repeat: true });
eachChar: function(currentState) {
return currentState.put({ invalidChars: "/", repeat: true, validChars: undefined });
},

@@ -70,4 +72,4 @@

StarSegment.prototype = {
eachChar: function(callback) {
callback({ invalidChars: "", repeat: true });
eachChar: function(currentState) {
return currentState.put({ invalidChars: "", repeat: true, validChars: undefined });
},

@@ -86,3 +88,5 @@

EpsilonSegment.prototype = {
eachChar: function() {},
eachChar: function(currentState) {
return currentState;
},
regex: function() { return ""; },

@@ -97,3 +101,4 @@ generate: function() { return ""; }

var segments = route.split("/"), results = [];
var segments = route.split("/");
var results = new Array(segments.length);

@@ -121,18 +126,18 @@ // A routes has specificity determined by the order that its different segments

for (var i=0, l=segments.length; i<l; i++) {
for (var i=0; i<segments.length; i++) {
var segment = segments[i], match;
if (match = segment.match(/^:([^\/]+)$/)) {
results.push(new DynamicSegment(match[1]));
results[i] = new DynamicSegment(match[1]);
names.push(match[1]);
specificity.val += '3';
} else if (match = segment.match(/^\*([^\/]+)$/)) {
results.push(new StarSegment(match[1]));
specificity.val += '2';
results[i] = new StarSegment(match[1]);
specificity.val += '1';
names.push(match[1]);
} else if(segment === "") {
results.push(new EpsilonSegment());
specificity.val += '1';
results[i] = new EpsilonSegment();
specificity.val += '2';
} else {
results.push(new StaticSegment(segment));
results[i] = new StaticSegment(segment);
specificity.val += '4';

@@ -167,2 +172,6 @@ }

this.nextStates = [];
this.charSpecs = {};
this.regex = undefined;
this.handlers = undefined;
this.specificity = undefined;
}

@@ -172,5 +181,9 @@

get: function(charSpec) {
if (this.charSpecs[charSpec.validChars]) {
return this.charSpecs[charSpec.validChars];
}
var nextStates = this.nextStates;
for (var i=0, l=nextStates.length; i<l; i++) {
for (var i=0; i<nextStates.length; i++) {
var child = nextStates[i];

@@ -181,3 +194,6 @@

if (isEqual) { return child; }
if (isEqual) {
this.charSpecs[charSpec.validChars] = child;
return child;
}
}

@@ -219,3 +235,3 @@ },

for (var i=0, l=nextStates.length; i<l; i++) {
for (var i=0; i<nextStates.length; i++) {
child = nextStates[i];

@@ -306,10 +322,12 @@

for (var i=0, l=handlers.length; i<l; i++) {
result.length = handlers.length;
for (var i=0; i<handlers.length; i++) {
var handler = handlers[i], names = handler.names, params = {};
for (var j=0, m=names.length; j<m; j++) {
for (var j=0; j<names.length; j++) {
params[names[j]] = captures[currentCapture++];
}
result.push({ handler: handler.handler, params: params, isDynamic: !!names.length });
result[i] = { handler: handler.handler, params: params, isDynamic: !!names.length };
}

@@ -320,16 +338,10 @@

function addSegment(currentState, segment) {
segment.eachChar(function(ch) {
var state;
currentState = currentState.put(ch);
});
return currentState;
}
function decodeQueryParamPart(part) {
// http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
part = part.replace(/\+/gm, '%20');
return decodeURIComponent(part);
var result;
try {
result = decodeURIComponent(part);
} catch(error) {result = '';}
return result;
}

@@ -349,7 +361,7 @@

specificity = {},
handlers = [], allSegments = [], name;
handlers = new Array(routes.length), allSegments = [], name;
var isEmpty = true;
for (var i=0, l=routes.length; i<l; i++) {
for (var i=0; i<routes.length; i++) {
var route = routes[i], names = [];

@@ -361,3 +373,3 @@

for (var j=0, m=segments.length; j<m; j++) {
for (var j=0; j<segments.length; j++) {
var segment = segments[j];

@@ -370,16 +382,15 @@

// Add a "/" for the new segment
currentState = currentState.put({ validChars: "/" });
currentState = currentState.put({ invalidChars: undefined, repeat: false, validChars: "/" });
regex += "/";
// Add a representation of the segment to the NFA and regex
currentState = addSegment(currentState, segment);
currentState = segment.eachChar(currentState);
regex += segment.regex();
}
var handler = { handler: route.handler, names: names };
handlers.push(handler);
handlers[i] = handler;
}
if (isEmpty) {
currentState = currentState.put({ validChars: "/" });
currentState = currentState.put({ invalidChars: undefined, repeat: false, validChars: "/" });
regex += "/";

@@ -401,7 +412,10 @@ }

handlersFor: function(name) {
var route = this.names[name], result = [];
var route = this.names[name];
if (!route) { throw new Error("There is no route named " + name); }
for (var i=0, l=route.handlers.length; i<l; i++) {
result.push(route.handlers[i]);
var result = new Array(route.handlers.length);
for (var i=0; i<route.handlers.length; i++) {
result[i] = route.handlers[i];
}

@@ -422,3 +436,3 @@

for (var i=0, l=segments.length; i<l; i++) {
for (var i=0; i<segments.length; i++) {
var segment = segments[i];

@@ -450,3 +464,3 @@

keys.sort();
for (var i = 0, len = keys.length; i < len; i++) {
for (var i = 0; i < keys.length; i++) {
key = keys[i];

@@ -459,3 +473,3 @@ var value = params[key];

if (isArray(value)) {
for (var j = 0, l = value.length; j < l; j++) {
for (var j = 0; j < value.length; j++) {
var arrayPair = key + '[]' + '=' + encodeURIComponent(value[j]);

@@ -529,3 +543,3 @@ pairs.push(arrayPair);

for (i=0, l=path.length; i<l; i++) {
for (i=0; i<path.length; i++) {
states = recognizeChar(states, path.charAt(i));

@@ -538,3 +552,3 @@ if (!states.length) { break; }

var solutions = [];
for (i=0, l=states.length; i<l; i++) {
for (i=0; i<states.length; i++) {
if (states[i].handlers) { solutions.push(states[i]); }

@@ -541,0 +555,0 @@ }

@@ -64,3 +64,3 @@ function Target(path, matcher, delegate) {

var len = 0;
for (var i=0, l=routeArray.length; i<l; i++) {
for (var i=0; i<routeArray.length; i++) {
len += routeArray[i].path.length;

@@ -67,0 +67,0 @@ }

{
"name": "route-recognizer",
"version": "0.1.9",
"version": "0.1.10",
"description": "A lightweight JavaScript library that matches paths against registered routes.",

@@ -15,5 +15,7 @@ "author": "Yehuda Katz",

"broccoli-jshint": "~0.5.1",
"broccoli-replace": "~0.1.6",
"broccoli-merge-trees": "^0.2.1",
"ember-cli": "1.13.1"
"broccoli-string-replace": "~0.1.0",
"do-you-even-bench": "^1.0.2",
"ember-cli": "1.13.1",
"glob": "^6.0.4"
},

@@ -31,5 +33,6 @@ "main": "dist/route-recognizer.js",

"start": "ember test --server",
"build": "ember build"
"build": "ember build",
"bench": "ember build && node ./bench/index.js"
},
"license": "MIT"
}

@@ -88,5 +88,5 @@ [![Build Status](https://travis-ci.org/tildeio/route-recognizer.png)](https://travis-ci.org/tildeio/route-recognizer)

```javascript
router.add({ path: "/posts/edit", handler: editPost });
router.add({ path: "/posts/:id", handler: showPost });
router.add({ path: "/posts/new", handler: newPost });
router.add([{ path: "/posts/edit", handler: editPost }]);
router.add([{ path: "/posts/:id", handler: showPost }]);
router.add([{ path: "/posts/new", handler: newPost }]);

@@ -93,0 +93,0 @@ var result1 = router.recognize("/posts/edit");

Sorry, the diff of this file is not supported yet

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