Skip to content

Commit

Permalink
chore: v0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Sep 4, 2015
1 parent 303b240 commit 37b2b45
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 33 deletions.
184 changes: 184 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,187 @@
<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>
## 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>
# 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))



<a name="0.3.1"></a>
## 0.3.1 (2015-09-04)

Expand Down
43 changes: 33 additions & 10 deletions dist/amd/path-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ define(['exports', 'module'], function (exports, module) {
return source.replace(/\\\/$/, '') + '(?:\\/)?';
};

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) {
return val !== undefined && val !== null && val !== '';
};
Expand Down Expand Up @@ -174,16 +185,12 @@ define(['exports', 'module'], function (exports, module) {
// If no match, or no query params, no need to go further
if (!match || !this.hasQueryParams) return match;
// 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
Object.keys(queryParams).forEach(function (p) {
return match[p] = queryParams[p];
Expand All @@ -197,12 +204,28 @@ define(['exports', 'module'], function (exports, module) {
}, {
key: 'partialMatch',
value: function partialMatch(path) {
var _this3 = this;

var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];

// Check if partial match (start of given path matches regex)
// trailingSlash: falsy => non optional, truthy => optional
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;
}
}, {
key: 'build',
Expand Down
43 changes: 33 additions & 10 deletions dist/commonjs/path-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ var optTrailingSlash = function optTrailingSlash(source, trailingSlash) {
return source.replace(/\\\/$/, '') + '(?:\\/)?';
};

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) {
return val !== undefined && val !== null && val !== '';
};
Expand Down Expand Up @@ -177,16 +188,12 @@ var Path = (function () {
// If no match, or no query params, no need to go further
if (!match || !this.hasQueryParams) return match;
// 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
Object.keys(queryParams).forEach(function (p) {
return match[p] = queryParams[p];
Expand All @@ -200,12 +207,28 @@ var Path = (function () {
}, {
key: 'partialMatch',
value: function partialMatch(path) {
var _this3 = this;

var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];

// Check if partial match (start of given path matches regex)
// trailingSlash: falsy => non optional, truthy => optional
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;
}
}, {
key: 'build',
Expand Down
43 changes: 33 additions & 10 deletions dist/umd/path-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@
return source.replace(/\\\/$/, '') + '(?:\\/)?';
};

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) {
return val !== undefined && val !== null && val !== '';
};
Expand Down Expand Up @@ -186,16 +197,12 @@
// If no match, or no query params, no need to go further
if (!match || !this.hasQueryParams) return match;
// 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
Object.keys(queryParams).forEach(function (p) {
return match[p] = queryParams[p];
Expand All @@ -209,12 +216,28 @@
}, {
key: 'partialMatch',
value: function partialMatch(path) {
var _this3 = this;

var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];

// Check if partial match (start of given path matches regex)
// trailingSlash: falsy => non optional, truthy => optional
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;
}
}, {
key: 'build',
Expand Down
Loading

0 comments on commit 37b2b45

Please sign in to comment.