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

route-node

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

route-node - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

10

CHANGELOG.md

@@ -0,1 +1,11 @@

<a name="1.0.2"></a>
## [1.0.2](https://github.com/troch/route-node/compare/v1.0.1...v1.0.2) (2016-01-06)
### Bug Fixes
* fix ordering of children when matching routes ([c917f6f](https://github.com/troch/route-node/commit/c917f6f))
<a name="1.0.1"></a>

@@ -2,0 +12,0 @@ ## [1.0.1](https://github.com/troch/route-node/compare/v1.0.0...v1.0.1) (2016-01-05)

33

dist/amd/route-node.js

@@ -275,4 +275,3 @@ define('RouteNode', function () { 'use strict';

// Check if exact match
var matched = this._urlMatch(path, new RegExp('^' + source + (this.hasQueryParams ? '\\?.*$' : '$')));
var matched = this._urlMatch(path, new RegExp('^' + source + (this.hasQueryParams ? '(\\?.*$|$)' : '$')));
// If no match, or no query params, no need to go further

@@ -466,22 +465,24 @@ if (!matched || !this.hasQueryParams) return matched;

// Push greedy spats to the bottom of the pile
this.children.sort(function (a, b) {
this.children.sort(function (left, right) {
var leftPath = left.path.split('?')[0];
var rightPath = right.path.split('?')[0];
// '/' last
if (a.path === '/') return 1;
if (b.path === '/') return -1;
var aHasParams = a.parser.hasUrlParams || a.parser.hasSpatParam;
var bHasParams = b.parser.hasUrlParams || b.parser.hasSpatParam;
if (leftPath === '/') return 1;
if (rightPath === '/') return -1;
var leftHasParams = left.parser.hasUrlParams || left.parser.hasSpatParam;
var rightHasParams = right.parser.hasUrlParams || right.parser.hasSpatParam;
// No params first, sort by length descending
if (!aHasParams && !bHasParams) {
return a.path && b.path ? a.path.length < b.path.length ? 1 : -1 : 0;
if (!leftHasParams && !rightHasParams) {
return leftPath && rightPath ? leftPath.length < rightPath.length ? 1 : -1 : 0;
}
// Params last
if (aHasParams && !bHasParams) return 1;
if (!aHasParams && bHasParams) return -1;
if (leftHasParams && !rightHasParams) return 1;
if (!leftHasParams && rightHasParams) return -1;
// Spat params last
if (!a.parser.hasSpatParam && b.parser.hasSpatParam) return -1;
if (!b.parser.hasSpatParam && a.parser.hasSpatParam) return 1;
if (!left.parser.hasSpatParam && right.parser.hasSpatParam) return -1;
if (!right.parser.hasSpatParam && left.parser.hasSpatParam) return 1;
// Sort by number of segments descending
var aSegments = (a.path.match(/\//g) || []).length;
var bSegments = (b.path.match(/\//g) || []).length;
if (aSegments < bSegments) return 1;
var leftSegments = (leftPath.match(/\//g) || []).length;
var rightSegments = (rightPath.match(/\//g) || []).length;
if (leftSegments < rightSegments) return 1;
return 0;

@@ -488,0 +489,0 @@ });

@@ -115,22 +115,24 @@ 'use strict';

// Push greedy spats to the bottom of the pile
this.children.sort(function (a, b) {
this.children.sort(function (left, right) {
var leftPath = left.path.split('?')[0];
var rightPath = right.path.split('?')[0];
// '/' last
if (a.path === '/') return 1;
if (b.path === '/') return -1;
var aHasParams = a.parser.hasUrlParams || a.parser.hasSpatParam;
var bHasParams = b.parser.hasUrlParams || b.parser.hasSpatParam;
if (leftPath === '/') return 1;
if (rightPath === '/') return -1;
var leftHasParams = left.parser.hasUrlParams || left.parser.hasSpatParam;
var rightHasParams = right.parser.hasUrlParams || right.parser.hasSpatParam;
// No params first, sort by length descending
if (!aHasParams && !bHasParams) {
return a.path && b.path ? a.path.length < b.path.length ? 1 : -1 : 0;
if (!leftHasParams && !rightHasParams) {
return leftPath && rightPath ? leftPath.length < rightPath.length ? 1 : -1 : 0;
}
// Params last
if (aHasParams && !bHasParams) return 1;
if (!aHasParams && bHasParams) return -1;
if (leftHasParams && !rightHasParams) return 1;
if (!leftHasParams && rightHasParams) return -1;
// Spat params last
if (!a.parser.hasSpatParam && b.parser.hasSpatParam) return -1;
if (!b.parser.hasSpatParam && a.parser.hasSpatParam) return 1;
if (!left.parser.hasSpatParam && right.parser.hasSpatParam) return -1;
if (!right.parser.hasSpatParam && left.parser.hasSpatParam) return 1;
// Sort by number of segments descending
var aSegments = (a.path.match(/\//g) || []).length;
var bSegments = (b.path.match(/\//g) || []).length;
if (aSegments < bSegments) return 1;
var leftSegments = (leftPath.match(/\//g) || []).length;
var rightSegments = (rightPath.match(/\//g) || []).length;
if (leftSegments < rightSegments) return 1;
return 0;

@@ -137,0 +139,0 @@ });

@@ -279,4 +279,3 @@ (function (global, factory) {

// Check if exact match
var matched = this._urlMatch(path, new RegExp('^' + source + (this.hasQueryParams ? '\\?.*$' : '$')));
var matched = this._urlMatch(path, new RegExp('^' + source + (this.hasQueryParams ? '(\\?.*$|$)' : '$')));
// If no match, or no query params, no need to go further

@@ -470,22 +469,24 @@ if (!matched || !this.hasQueryParams) return matched;

// Push greedy spats to the bottom of the pile
this.children.sort(function (a, b) {
this.children.sort(function (left, right) {
var leftPath = left.path.split('?')[0];
var rightPath = right.path.split('?')[0];
// '/' last
if (a.path === '/') return 1;
if (b.path === '/') return -1;
var aHasParams = a.parser.hasUrlParams || a.parser.hasSpatParam;
var bHasParams = b.parser.hasUrlParams || b.parser.hasSpatParam;
if (leftPath === '/') return 1;
if (rightPath === '/') return -1;
var leftHasParams = left.parser.hasUrlParams || left.parser.hasSpatParam;
var rightHasParams = right.parser.hasUrlParams || right.parser.hasSpatParam;
// No params first, sort by length descending
if (!aHasParams && !bHasParams) {
return a.path && b.path ? a.path.length < b.path.length ? 1 : -1 : 0;
if (!leftHasParams && !rightHasParams) {
return leftPath && rightPath ? leftPath.length < rightPath.length ? 1 : -1 : 0;
}
// Params last
if (aHasParams && !bHasParams) return 1;
if (!aHasParams && bHasParams) return -1;
if (leftHasParams && !rightHasParams) return 1;
if (!leftHasParams && rightHasParams) return -1;
// Spat params last
if (!a.parser.hasSpatParam && b.parser.hasSpatParam) return -1;
if (!b.parser.hasSpatParam && a.parser.hasSpatParam) return 1;
if (!left.parser.hasSpatParam && right.parser.hasSpatParam) return -1;
if (!right.parser.hasSpatParam && left.parser.hasSpatParam) return 1;
// Sort by number of segments descending
var aSegments = (a.path.match(/\//g) || []).length;
var bSegments = (b.path.match(/\//g) || []).length;
if (aSegments < bSegments) return 1;
var leftSegments = (leftPath.match(/\//g) || []).length;
var rightSegments = (rightPath.match(/\//g) || []).length;
if (leftSegments < rightSegments) return 1;
return 0;

@@ -492,0 +493,0 @@ });

@@ -78,22 +78,24 @@ import Path from 'path-parser';

// Push greedy spats to the bottom of the pile
this.children.sort((a, b) => {
this.children.sort((left, right) => {
const leftPath = left.path.split('?')[0];
const rightPath = right.path.split('?')[0];
// '/' last
if (a.path === '/') return 1;
if (b.path === '/') return -1;
let aHasParams = a.parser.hasUrlParams || a.parser.hasSpatParam;
let bHasParams = b.parser.hasUrlParams || b.parser.hasSpatParam;
if (leftPath === '/') return 1;
if (rightPath === '/') return -1;
let leftHasParams = left.parser.hasUrlParams || left.parser.hasSpatParam;
let rightHasParams = right.parser.hasUrlParams || right.parser.hasSpatParam;
// No params first, sort by length descending
if (!aHasParams && !bHasParams) {
return a.path && b.path ? (a.path.length < b.path.length ? 1 : -1) : 0;
if (!leftHasParams && !rightHasParams) {
return leftPath && rightPath ? (leftPath.length < rightPath.length ? 1 : -1) : 0;
}
// Params last
if (aHasParams && !bHasParams) return 1;
if (!aHasParams && bHasParams) return -1;
if (leftHasParams && !rightHasParams) return 1;
if (!leftHasParams && rightHasParams) return -1;
// Spat params last
if (!a.parser.hasSpatParam && b.parser.hasSpatParam) return -1;
if (!b.parser.hasSpatParam && a.parser.hasSpatParam) return 1;
if (!left.parser.hasSpatParam && right.parser.hasSpatParam) return -1;
if (!right.parser.hasSpatParam && left.parser.hasSpatParam) return 1;
// Sort by number of segments descending
let aSegments = (a.path.match(/\//g) || []).length;
let bSegments = (b.path.match(/\//g) || []).length;
if (aSegments < bSegments) return 1;
let leftSegments = (leftPath.match(/\//g) || []).length;
let rightSegments = (rightPath.match(/\//g) || []).length;
if (leftSegments < rightSegments) return 1;
return 0;

@@ -100,0 +102,0 @@ });

{
"name": "route-node",
"version": "1.0.1",
"version": "1.0.2",
"description": "A package to create a tree of named routes",

@@ -57,4 +57,4 @@ "main": "dist/commonjs/route-node.js",

"dependencies": {
"path-parser": "~1.0.0"
"path-parser": "~1.0.2"
}
}

@@ -256,7 +256,7 @@ 'use strict';

var rootNode = new RouteNode('', '')
.addNode('section', '/section/:id')
.addNode('index', '/')
.addNode('id', '/:id')
.addNode('section', '/section/:id?a')
.addNode('index', '/?queryparamOfexceptionalLength')
.addNode('id', '/:id?rrrr')
.addNode('abo', '/abo')
.addNode('about', '/about');
.addNode('about', '/about?hello');

@@ -263,0 +263,0 @@ withoutMeta(rootNode.matchPath('/')).should.eql({name: 'index', params: {}});

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