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.5 to 0.1.6

2

bower.json
{
"name": "route-recognizer",
"version": "0.1.1",
"version": "0.1.6",
"homepage": "https://github.com/tildeio/route-recognizer",

@@ -5,0 +5,0 @@ "authors": [

@@ -88,3 +88,3 @@ import map from './route-recognizer/dsl';

function parse(route, names, types) {
function parse(route, names, specificity) {
// normalize route as not starting with a "/". Recognition will

@@ -96,2 +96,23 @@ // also normalize.

// A routes has specificity determined by the order that its different segments
// appear in. This system mirrors how the magnitude of numbers written as strings
// works.
// Consider a number written as: "abc". An example would be "200". Any other number written
// "xyz" will be smaller than "abc" so long as `a > z`. For instance, "199" is smaller
// then "200", even though "y" and "z" (which are both 9) are larger than "0" (the value
// of (`b` and `c`). This is because the leading symbol, "2", is larger than the other
// leading symbol, "1".
// The rule is that symbols to the left carry more weight than symbols to the right
// when a number is written out as a string. In the above strings, the leading digit
// represents how many 100's are in the number, and it carries more weight than the middle
// number which represents how many 10's are in the number.
// This system of number magnitude works well for route specificity, too. A route written as
// `a/b/c` will be more specific than `x/y/z` as long as `a` is more specific than
// `x`, irrespective of the other parts.
// Because of this similarity, we assign each type of segment a number value written as a
// string. We can find the specificity of compound routes by concatenating these strings
// together, from left to right. After we have looped through all of the segments,
// we convert the string to a number.
specificity.val = '';
for (var i=0, l=segments.length; i<l; i++) {

@@ -103,15 +124,18 @@ var segment = segments[i], match;

names.push(match[1]);
types.dynamics++;
specificity.val += '3';
} else if (match = segment.match(/^\*([^\/]+)$/)) {
results.push(new StarSegment(match[1]));
specificity.val += '2';
names.push(match[1]);
types.stars++;
} else if(segment === "") {
results.push(new EpsilonSegment());
specificity.val += '1';
} else {
results.push(new StaticSegment(segment));
types.statics++;
specificity.val += '4';
}
}
specificity.val = +specificity.val;
return results;

@@ -234,25 +258,6 @@ }

// This is a somewhat naive strategy, but should work in a lot of cases
// A better strategy would properly resolve /posts/:id/new and /posts/edit/:id.
//
// This strategy generally prefers more static and less dynamic matching.
// Specifically, it
//
// * prefers fewer stars to more, then
// * prefers using stars for less of the match to more, then
// * prefers fewer dynamic segments to more, then
// * prefers more static segments to more
// Sort the routes by specificity
function sortSolutions(states) {
return states.sort(function(a, b) {
if (a.types.stars !== b.types.stars) { return a.types.stars - b.types.stars; }
if (a.types.stars) {
if (a.types.statics !== b.types.statics) { return b.types.statics - a.types.statics; }
if (a.types.dynamics !== b.types.dynamics) { return b.types.dynamics - a.types.dynamics; }
}
if (a.types.dynamics !== b.types.dynamics) { return a.types.dynamics - b.types.dynamics; }
if (a.types.statics !== b.types.statics) { return b.types.statics - a.types.statics; }
return 0;
return b.specificity.val - a.specificity.val;
});

@@ -335,3 +340,3 @@ }

var currentState = this.rootState, regex = "^",
types = { statics: 0, dynamics: 0, stars: 0 },
specificity = {},
handlers = [], allSegments = [], name;

@@ -344,3 +349,3 @@

var segments = parse(route.path, names, types);
var segments = parse(route.path, names, specificity);

@@ -376,3 +381,3 @@ allSegments = allSegments.concat(segments);

currentState.regex = new RegExp(regex + "$");
currentState.types = types;
currentState.specificity = specificity;

@@ -541,4 +546,4 @@ if (name = options && options.as) {

RouteRecognizer.VERSION = '0.1.5';
RouteRecognizer.VERSION = '0.1.6';
export default RouteRecognizer;

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

function $$route$recognizer$$parse(route, names, types) {
function $$route$recognizer$$parse(route, names, specificity) {
// normalize route as not starting with a "/". Recognition will

@@ -196,2 +196,23 @@ // also normalize.

// A routes has specificity determined by the order that its different segments
// appear in. This system mirrors how the magnitude of numbers written as strings
// works.
// Consider a number written as: "abc". An example would be "200". Any other number written
// "xyz" will be smaller than "abc" so long as `a > z`. For instance, "199" is smaller
// then "200", even though "y" and "z" (which are both 9) are larger than "0" (the value
// of (`b` and `c`). This is because the leading symbol, "2", is larger than the other
// leading symbol, "1".
// The rule is that symbols to the left carry more weight than symbols to the right
// when a number is written out as a string. In the above strings, the leading digit
// represents how many 100's are in the number, and it carries more weight than the middle
// number which represents how many 10's are in the number.
// This system of number magnitude works well for route specificity, too. A route written as
// `a/b/c` will be more specific than `x/y/z` as long as `a` is more specific than
// `x`, irrespective of the other parts.
// Because of this similarity, we assign each type of segment a number value written as a
// string. We can find the specificity of compound routes by concatenating these strings
// together, from left to right. After we have looped through all of the segments,
// we convert the string to a number.
specificity.val = '';
for (var i=0, l=segments.length; i<l; i++) {

@@ -203,15 +224,18 @@ var segment = segments[i], match;

names.push(match[1]);
types.dynamics++;
specificity.val += '3';
} else if (match = segment.match(/^\*([^\/]+)$/)) {
results.push(new $$route$recognizer$$StarSegment(match[1]));
specificity.val += '2';
names.push(match[1]);
types.stars++;
} else if(segment === "") {
results.push(new $$route$recognizer$$EpsilonSegment());
specificity.val += '1';
} else {
results.push(new $$route$recognizer$$StaticSegment(segment));
types.statics++;
specificity.val += '4';
}
}
specificity.val = +specificity.val;
return results;

@@ -334,25 +358,6 @@ }

// This is a somewhat naive strategy, but should work in a lot of cases
// A better strategy would properly resolve /posts/:id/new and /posts/edit/:id.
//
// This strategy generally prefers more static and less dynamic matching.
// Specifically, it
//
// * prefers fewer stars to more, then
// * prefers using stars for less of the match to more, then
// * prefers fewer dynamic segments to more, then
// * prefers more static segments to more
// Sort the routes by specificity
function $$route$recognizer$$sortSolutions(states) {
return states.sort(function(a, b) {
if (a.types.stars !== b.types.stars) { return a.types.stars - b.types.stars; }
if (a.types.stars) {
if (a.types.statics !== b.types.statics) { return b.types.statics - a.types.statics; }
if (a.types.dynamics !== b.types.dynamics) { return b.types.dynamics - a.types.dynamics; }
}
if (a.types.dynamics !== b.types.dynamics) { return a.types.dynamics - b.types.dynamics; }
if (a.types.statics !== b.types.statics) { return b.types.statics - a.types.statics; }
return 0;
return b.specificity.val - a.specificity.val;
});

@@ -435,3 +440,3 @@ }

var currentState = this.rootState, regex = "^",
types = { statics: 0, dynamics: 0, stars: 0 },
specificity = {},
handlers = [], allSegments = [], name;

@@ -444,3 +449,3 @@

var segments = $$route$recognizer$$parse(route.path, names, types);
var segments = $$route$recognizer$$parse(route.path, names, specificity);

@@ -476,3 +481,3 @@ allSegments = allSegments.concat(segments);

currentState.regex = new RegExp(regex + "$");
currentState.types = types;
currentState.specificity = specificity;

@@ -641,3 +646,3 @@ if (name = options && options.as) {

$$route$recognizer$$RouteRecognizer.VERSION = '0.1.5';
$$route$recognizer$$RouteRecognizer.VERSION = '0.1.6';

@@ -644,0 +649,0 @@ var $$route$recognizer$$default = $$route$recognizer$$RouteRecognizer;

@@ -88,3 +88,3 @@ import map from './route-recognizer/dsl';

function parse(route, names, types) {
function parse(route, names, specificity) {
// normalize route as not starting with a "/". Recognition will

@@ -96,2 +96,23 @@ // also normalize.

// A routes has specificity determined by the order that its different segments
// appear in. This system mirrors how the magnitude of numbers written as strings
// works.
// Consider a number written as: "abc". An example would be "200". Any other number written
// "xyz" will be smaller than "abc" so long as `a > z`. For instance, "199" is smaller
// then "200", even though "y" and "z" (which are both 9) are larger than "0" (the value
// of (`b` and `c`). This is because the leading symbol, "2", is larger than the other
// leading symbol, "1".
// The rule is that symbols to the left carry more weight than symbols to the right
// when a number is written out as a string. In the above strings, the leading digit
// represents how many 100's are in the number, and it carries more weight than the middle
// number which represents how many 10's are in the number.
// This system of number magnitude works well for route specificity, too. A route written as
// `a/b/c` will be more specific than `x/y/z` as long as `a` is more specific than
// `x`, irrespective of the other parts.
// Because of this similarity, we assign each type of segment a number value written as a
// string. We can find the specificity of compound routes by concatenating these strings
// together, from left to right. After we have looped through all of the segments,
// we convert the string to a number.
specificity.val = '';
for (var i=0, l=segments.length; i<l; i++) {

@@ -103,15 +124,18 @@ var segment = segments[i], match;

names.push(match[1]);
types.dynamics++;
specificity.val += '3';
} else if (match = segment.match(/^\*([^\/]+)$/)) {
results.push(new StarSegment(match[1]));
specificity.val += '2';
names.push(match[1]);
types.stars++;
} else if(segment === "") {
results.push(new EpsilonSegment());
specificity.val += '1';
} else {
results.push(new StaticSegment(segment));
types.statics++;
specificity.val += '4';
}
}
specificity.val = +specificity.val;
return results;

@@ -234,25 +258,6 @@ }

// This is a somewhat naive strategy, but should work in a lot of cases
// A better strategy would properly resolve /posts/:id/new and /posts/edit/:id.
//
// This strategy generally prefers more static and less dynamic matching.
// Specifically, it
//
// * prefers fewer stars to more, then
// * prefers using stars for less of the match to more, then
// * prefers fewer dynamic segments to more, then
// * prefers more static segments to more
// Sort the routes by specificity
function sortSolutions(states) {
return states.sort(function(a, b) {
if (a.types.stars !== b.types.stars) { return a.types.stars - b.types.stars; }
if (a.types.stars) {
if (a.types.statics !== b.types.statics) { return b.types.statics - a.types.statics; }
if (a.types.dynamics !== b.types.dynamics) { return b.types.dynamics - a.types.dynamics; }
}
if (a.types.dynamics !== b.types.dynamics) { return a.types.dynamics - b.types.dynamics; }
if (a.types.statics !== b.types.statics) { return b.types.statics - a.types.statics; }
return 0;
return b.specificity.val - a.specificity.val;
});

@@ -335,3 +340,3 @@ }

var currentState = this.rootState, regex = "^",
types = { statics: 0, dynamics: 0, stars: 0 },
specificity = {},
handlers = [], allSegments = [], name;

@@ -344,3 +349,3 @@

var segments = parse(route.path, names, types);
var segments = parse(route.path, names, specificity);

@@ -376,3 +381,3 @@ allSegments = allSegments.concat(segments);

currentState.regex = new RegExp(regex + "$");
currentState.types = types;
currentState.specificity = specificity;

@@ -379,0 +384,0 @@ if (name = options && options.as) {

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

@@ -11,3 +11,3 @@ "author": "Yehuda Katz",

"devDependencies": {
"broccoli-compile-modules": "^1.1.0",
"broccoli-compile-modules": "1.0.1",
"broccoli-concat": "0.0.12",

@@ -18,3 +18,3 @@ "broccoli-funnel": "^0.1.6",

"broccoli-merge-trees": "^0.2.1",
"ember-cli": "0.1.7"
"ember-cli": "1.13.1"
},

@@ -21,0 +21,0 @@ "main": "dist/route-recognizer.js",

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