Socket
Socket
Sign inDemoInstall

path-parser

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

path-parser - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

184

CHANGELOG.md

@@ -0,1 +1,21 @@

<a name="0.3.2"></a>
## 0.3.2 (2015-09-04)
### Bug Fixes
* make query parameters optional when matching and match them on partial match ([303b240](https://github.com/troch/path-parser/commit/303b240))
<a name="0.3.2"></a>
## 0.3.2 (2015-09-04)
### Bug Fixes
* make query parameters optional when matching and match them on partial match ([303b240](https://github.com/troch/path-parser/commit/303b240))
<a name="0.3.1"></a>

@@ -165,2 +185,12 @@ ## 0.3.1 (2015-09-04)

<a name="0.3.1"></a>
## 0.3.1 (2015-09-04)
### Bug Fixes
* better building and matching of query params ([5e8f881](https://github.com/troch/path-parser/commit/5e8f881))
<a name="0.3.0"></a>

@@ -317,1 +347,155 @@ # 0.3.0 (2015-09-03)

* add support for splats ([e346bbf](https://github.com/troch/path-parser/commit/e346bbf))
<a name="0.3.0"></a>
# 0.3.0 (2015-09-03)
### Bug Fixes
* build a path without all query parameters ([208fd8a](https://github.com/troch/path-parser/commit/208fd8a))
### Features
* build paths without search part ([c9973be](https://github.com/troch/path-parser/commit/c9973be))
### BREAKING CHANGES
* .build() now takes an options object as a second parameter
Issue router5/router5#19
<a name="0.2.4"></a>
## 0.2.4 (2015-09-01)
### Features
* allow optional trailing slash for '/' ([570a0c4](https://github.com/troch/path-parser/commit/570a0c4))
<a name="0.2.3"></a>
## 0.2.3 (2015-08-20)
### Bug Fixes
* better escape regular expression special chars so built source matches regexp so ([21d30b7](https://github.com/troch/path-parser/commit/21d30b7))
<a name="0.2.2"></a>
## 0.2.2 (2015-08-19)
### Bug Fixes
* escape special characters properly in regular expressions ([f573957](https://github.com/troch/path-parser/commit/f573957))
<a name="0.2.1"></a>
## 0.2.1 (2015-08-19)
### Bug Fixes
* don't apply optional trailing slashes on paths === / ([36e0180](https://github.com/troch/path-parser/commit/36e0180))
<a name="0.2.0"></a>
# 0.2.0 (2015-08-19)
### Features
* support optional trailing slashes ([6785886](https://github.com/troch/path-parser/commit/6785886))
<a name="0.1.1"></a>
## 0.1.1 (2015-07-22)
<a name="0.1.0"></a>
# 0.1.0 (2015-07-06)
### Features
* add matrix and url parameter constraints ([a567ba1](https://github.com/troch/path-parser/commit/a567ba1))
<a name="0.0.7"></a>
## 0.0.7 (2015-07-01)
### Features
* support matrix parameters ([0451290](https://github.com/troch/path-parser/commit/0451290))
<a name="0.0.6"></a>
## 0.0.6 (2015-06-30)
<a name="0.0.5"></a>
## 0.0.5 (2015-06-30)
<a name="0.0.4"></a>
## 0.0.4 (2015-06-28)
### Bug Fixes
* fix bug when multiple query params ([880bae0](https://github.com/troch/path-parser/commit/880bae0))
### Features
* improve tokenisation and tests ([5b9e1fe](https://github.com/troch/path-parser/commit/5b9e1fe))
<a name="0.0.3"></a>
## 0.0.3 (2015-06-26)
### Bug Fixes
* fix path building with splats ([7bd7d74](https://github.com/troch/path-parser/commit/7bd7d74))
<a name="0.0.2"></a>
## 0.0.2 (2015-06-25)
### Features
* add splat support with query params ([96bcd6d](https://github.com/troch/path-parser/commit/96bcd6d))
<a name="0.0.1"></a>
## 0.0.1 (2015-06-25)
### Features
* add spat param flag ([b77174a](https://github.com/troch/path-parser/commit/b77174a))
* add support for query parameters ([4ee86cf](https://github.com/troch/path-parser/commit/4ee86cf))
* add support for splats ([e346bbf](https://github.com/troch/path-parser/commit/e346bbf))

43

dist/amd/path-parser.js

@@ -92,2 +92,13 @@ define(['exports', 'module'], function (exports, module) {

var parseQueryParams = function parseQueryParams(path) {
var searchPart = path.split('?')[1];
if (!searchPart) return {};
return searchPart.split('&').map(function (_) {
return _.split('=');
}).reduce(function (obj, m) {
obj[m[0]] = m[1] === undefined ? '' : m[1];
return obj;
}, {});
};
var isSerialisable = function isSerialisable(val) {

@@ -178,12 +189,8 @@ return val !== undefined && val !== null && val !== '';

// Extract query params
var queryParams = path.split('?')[1].split('&').map(function (_) {
return _.split('=');
}).reduce(function (obj, m) {
obj[m[0]] = m[1] === undefined ? '' : m[1];
return obj;
}, {});
var queryParams = parseQueryParams(path);
var unexpectedQueryParams = Object.keys(queryParams).filter(function (p) {
return _this2.queryParams.indexOf(p) === -1;
});
if (Object.keys(queryParams).every(function (p) {
return Object.keys(_this2.queryParams).indexOf(p) !== 1;
}) && Object.keys(queryParams).length === this.queryParams.length) {
if (unexpectedQueryParams.length === 0) {
// Extend url match

@@ -202,2 +209,4 @@ Object.keys(queryParams).forEach(function (p) {

value: function partialMatch(path) {
var _this3 = this;
var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];

@@ -208,3 +217,17 @@

var source = optTrailingSlash(this.source, trailingSlash);
return this._urlMatch(path, new RegExp('^' + source));
var match = this._urlMatch(path, new RegExp('^' + source));
if (!match) return match;
if (!this.hasQueryParams) return match;
var queryParams = parseQueryParams(path);
Object.keys(queryParams).filter(function (p) {
return _this3.queryParams.indexOf(p) >= 0;
}).forEach(function (p) {
return match[p] = queryParams[p];
});
return match;
}

@@ -211,0 +234,0 @@ }, {

@@ -95,2 +95,13 @@ 'use strict';

var parseQueryParams = function parseQueryParams(path) {
var searchPart = path.split('?')[1];
if (!searchPart) return {};
return searchPart.split('&').map(function (_) {
return _.split('=');
}).reduce(function (obj, m) {
obj[m[0]] = m[1] === undefined ? '' : m[1];
return obj;
}, {});
};
var isSerialisable = function isSerialisable(val) {

@@ -181,12 +192,8 @@ return val !== undefined && val !== null && val !== '';

// Extract query params
var queryParams = path.split('?')[1].split('&').map(function (_) {
return _.split('=');
}).reduce(function (obj, m) {
obj[m[0]] = m[1] === undefined ? '' : m[1];
return obj;
}, {});
var queryParams = parseQueryParams(path);
var unexpectedQueryParams = Object.keys(queryParams).filter(function (p) {
return _this2.queryParams.indexOf(p) === -1;
});
if (Object.keys(queryParams).every(function (p) {
return Object.keys(_this2.queryParams).indexOf(p) !== 1;
}) && Object.keys(queryParams).length === this.queryParams.length) {
if (unexpectedQueryParams.length === 0) {
// Extend url match

@@ -205,2 +212,4 @@ Object.keys(queryParams).forEach(function (p) {

value: function partialMatch(path) {
var _this3 = this;
var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];

@@ -211,3 +220,17 @@

var source = optTrailingSlash(this.source, trailingSlash);
return this._urlMatch(path, new RegExp('^' + source));
var match = this._urlMatch(path, new RegExp('^' + source));
if (!match) return match;
if (!this.hasQueryParams) return match;
var queryParams = parseQueryParams(path);
Object.keys(queryParams).filter(function (p) {
return _this3.queryParams.indexOf(p) >= 0;
}).forEach(function (p) {
return match[p] = queryParams[p];
});
return match;
}

@@ -214,0 +237,0 @@ }, {

@@ -104,2 +104,13 @@ (function (global, factory) {

var parseQueryParams = function parseQueryParams(path) {
var searchPart = path.split('?')[1];
if (!searchPart) return {};
return searchPart.split('&').map(function (_) {
return _.split('=');
}).reduce(function (obj, m) {
obj[m[0]] = m[1] === undefined ? '' : m[1];
return obj;
}, {});
};
var isSerialisable = function isSerialisable(val) {

@@ -190,12 +201,8 @@ return val !== undefined && val !== null && val !== '';

// Extract query params
var queryParams = path.split('?')[1].split('&').map(function (_) {
return _.split('=');
}).reduce(function (obj, m) {
obj[m[0]] = m[1] === undefined ? '' : m[1];
return obj;
}, {});
var queryParams = parseQueryParams(path);
var unexpectedQueryParams = Object.keys(queryParams).filter(function (p) {
return _this2.queryParams.indexOf(p) === -1;
});
if (Object.keys(queryParams).every(function (p) {
return Object.keys(_this2.queryParams).indexOf(p) !== 1;
}) && Object.keys(queryParams).length === this.queryParams.length) {
if (unexpectedQueryParams.length === 0) {
// Extend url match

@@ -214,2 +221,4 @@ Object.keys(queryParams).forEach(function (p) {

value: function partialMatch(path) {
var _this3 = this;
var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];

@@ -220,3 +229,17 @@

var source = optTrailingSlash(this.source, trailingSlash);
return this._urlMatch(path, new RegExp('^' + source));
var match = this._urlMatch(path, new RegExp('^' + source));
if (!match) return match;
if (!this.hasQueryParams) return match;
var queryParams = parseQueryParams(path);
Object.keys(queryParams).filter(function (p) {
return _this3.queryParams.indexOf(p) >= 0;
}).forEach(function (p) {
return match[p] = queryParams[p];
});
return match;
}

@@ -223,0 +246,0 @@ }, {

@@ -82,2 +82,13 @@ let defaultOrConstrained = (match) => {

let parseQueryParams = path => {
let searchPart = path.split('?')[1]
if (!searchPart) return {}
return searchPart.split('&')
.map(_ => _.split('='))
.reduce((obj, m) => {
obj[m[0]] = m[1] === undefined ? '' : m[1]
return obj
}, {})
}
let isSerialisable = val => val !== undefined && val !== null && val !== ''

@@ -136,11 +147,7 @@

// Extract query params
let queryParams = path.split('?')[1].split('&')
.map(_ => _.split('='))
.reduce((obj, m) => {
obj[m[0]] = m[1] === undefined ? '' : m[1]
return obj
}, {})
let queryParams = parseQueryParams(path)
let unexpectedQueryParams = Object.keys(queryParams)
.filter(p => this.queryParams.indexOf(p) === -1)
if (Object.keys(queryParams).every(p => Object.keys(this.queryParams).indexOf(p) !== 1)
&& Object.keys(queryParams).length === this.queryParams.length) {
if (unexpectedQueryParams.length === 0) {
// Extend url match

@@ -160,3 +167,15 @@ Object.keys(queryParams)

let source = optTrailingSlash(this.source, trailingSlash)
return this._urlMatch(path, new RegExp('^' + source))
let match = this._urlMatch(path, new RegExp('^' + source))
if (!match) return match
if (!this.hasQueryParams) return match
let queryParams = parseQueryParams(path)
Object.keys(queryParams)
.filter(p => this.queryParams.indexOf(p) >= 0)
.forEach(p => match[p] = queryParams[p])
return match
}

@@ -163,0 +182,0 @@

{
"name": "path-parser",
"version": "0.3.1",
"version": "0.3.2",
"description": "A small utility to parse, match and generate paths",

@@ -5,0 +5,0 @@ "main": "dist/commonjs/path-parser.js",

@@ -11,4 +11,3 @@ var clog = require('conventional-changelog');

preset: 'angular',
// repository: 'https://github.com/router5/router5',
releaseCount: 0
// repository: 'https://github.com/router5/router5'
})

@@ -15,0 +14,0 @@ .pipe(source('CHANGELOG.md'))

@@ -50,6 +50,9 @@ 'use strict';

path.match('/users?offset&limit=15').should.eql({ offset: '', limit: '15' });
// path.partialMatch('/users').should.eql({});
path.match('/users?limit=15').should.eql({ limit: '15' });
path.partialMatch('/users?offset&limits=1').should.eql({ offset: '' });
path.partialMatch('/users').should.eql({});
// Unsuccessful match
should.not.exist(path.match('/users?offset=31'));
should.not.exist(path.match('/users?limit=15'));
should.not.exist(path.match('/users?offset=31&order=asc'));
should.not.exist(path.match('/users?offset=31&limit=10&order=asc'));

@@ -62,3 +65,2 @@ path.build({ offset: 31, limit: 15 }).should.equal('/users?offset=31&limit=15');

path.build({ offset: 31, limit: 15 }, {ignoreSearch: true}).should.equal('/users');
});

@@ -65,0 +67,0 @@

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