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 6.0.0 to 6.1.0

9

CHANGELOG.md

@@ -0,1 +1,10 @@

# [6.1.0](https://github.com/troch/path-parser/compare/v6.0.0...v6.1.0) (2020-01-06)
### Features
* enable overwritting options on building and matching methods ([#47](https://github.com/troch/path-parser/issues/47)) ([605c7f9](https://github.com/troch/path-parser/commit/605c7f969dadd347033ce20f8e3d3d8416f31e44))
This reverts a breaking change below.
# [6.0.0](https://github.com/troch/path-parser/compare/v5.1.0...v6.0.0) (2020-01-05)

@@ -2,0 +11,0 @@

33

dist/path-parser.cjs.development.js

@@ -236,6 +236,6 @@ 'use strict';

var options = tslib.__assign({
var options = tslib.__assign(tslib.__assign({
caseSensitive: false,
strictTrailingSlash: false
}, opts); // trailingSlash: falsy => non optional, truthy => optional
}, this.options), opts); // trailingSlash: falsy => non optional, truthy => optional

@@ -245,3 +245,3 @@

var match = this.urlTest(path, source + (this.hasQueryParams ? '(\\?.*$|$)' : '$'), options.caseSensitive); // If no match, or no query params, no need to go further
var match = this.urlTest(path, source + (this.hasQueryParams ? '(\\?.*$|$)' : '$'), options.caseSensitive, options.urlParamsEncoding); // If no match, or no query params, no need to go further

@@ -253,3 +253,3 @@ if (!match || !this.hasQueryParams) {

var queryParams = searchParams.parse(path, this.options.queryParams);
var queryParams = searchParams.parse(path, options.queryParams);
var unexpectedQueryParams = Object.keys(queryParams).filter(function (p) {

@@ -274,6 +274,6 @@ return !_this.isQueryParam(p);

var options = tslib.__assign({
var options = tslib.__assign(tslib.__assign({
caseSensitive: false,
delimited: true
}, opts); // Check if partial match (start of given path matches regex)
}, this.options), opts); // Check if partial match (start of given path matches regex)
// trailingSlash: falsy => non optional, truthy => optional

@@ -283,3 +283,3 @@

var source = upToDelimiter(this.source, options.delimited);
var match = this.urlTest(path, source, options.caseSensitive);
var match = this.urlTest(path, source, options.caseSensitive, options.urlParamsEncoding);

@@ -294,3 +294,3 @@ if (!match) {

var queryParams = searchParams.parse(path, this.options.queryParams);
var queryParams = searchParams.parse(path, options.queryParams);
Object.keys(queryParams).filter(function (p) {

@@ -311,8 +311,7 @@ return _this.isQueryParam(p);

var options = tslib.__assign({
var options = tslib.__assign(tslib.__assign({
ignoreConstraints: false,
ignoreSearch: false,
queryParams: {},
urlParamsEncoding: 'default'
}, opts);
queryParams: {}
}, this.options), opts);

@@ -334,6 +333,6 @@ var encodedUrlParams = Object.keys(params).filter(function (p) {

acc[key] = val.map(function (v) {
return encodeParam(v, _this.options.urlParamsEncoding, isSpatParam);
return encodeParam(v, options.urlParamsEncoding, isSpatParam);
});
} else {
acc[key] = encodeParam(val, _this.options.urlParamsEncoding, isSpatParam);
acc[key] = encodeParam(val, options.urlParamsEncoding, isSpatParam);
}

@@ -386,3 +385,3 @@

}, {});
var searchPart = searchParams.build(searchParams$1, this.options.queryParams);
var searchPart = searchParams.build(searchParams$1, options.queryParams);
return searchPart ? base + '?' + searchPart : base;

@@ -402,3 +401,3 @@ };

Path.prototype.urlTest = function (path, source, caseSensitive) {
Path.prototype.urlTest = function (path, source, caseSensitive, urlParamsEncoding) {
var _this = this;

@@ -417,3 +416,3 @@

return match.slice(1, this.urlParams.length + 1).reduce(function (params, m, i) {
params[_this.urlParams[i]] = decodeParam(m, _this.options.urlParamsEncoding);
params[_this.urlParams[i]] = decodeParam(m, urlParamsEncoding);
return params;

@@ -420,0 +419,0 @@ }, {});

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),r=require("search-params"),e=/[^!$'()*+,;|:]/g,n=function(t){return t.replace(e,(function(t){return encodeURIComponent(t)}))},a={default:n,uri:encodeURI,uriComponent:encodeURIComponent,none:function(t){return t},legacy:encodeURI},i={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:function(t){return t},legacy:decodeURIComponent},s=function(t,r,e){var i=a[r]||n;return e?String(t).split("/").map(i).join("/"):i(String(t))},u=function(t){return"("+(t?t.replace(/(^<|>$)/g,""):"[a-zA-Z0-9-_.~%':|=+\\*@$]+")+")"},o=[{name:"url-parameter",pattern:/^:([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})(<(.+?)>)?/,regex:function(t){return new RegExp(u(t[2]))}},{name:"url-parameter-splat",pattern:/^\*([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/,regex:/([^?]*)/},{name:"url-parameter-matrix",pattern:/^;([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})(<(.+?)>)?/,regex:function(t){return new RegExp(";"+t[1]+"="+u(t[2]))}},{name:"query-parameter",pattern:/^(?:\?|&)(?::)?([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/},{name:"delimiter",pattern:/^(\/|\?)/,regex:function(t){return new RegExp("\\"+t[0])}},{name:"sub-delimiter",pattern:/^(!|&|-|_|\.|;)/,regex:function(t){return new RegExp(t[0])}},{name:"fragment",pattern:/^([0-9a-zA-Z]+)/,regex:function(t){return new RegExp(t[0])}}],c=function t(r,e){if(void 0===e&&(e=[]),!o.some((function(n){var a=r.match(n.pattern);return!!a&&(e.push({type:n.name,match:a[0],val:a.slice(1,2),otherVal:a.slice(2),regex:n.regex instanceof Function?n.regex(a):n.regex}),a[0].length<r.length&&(e=t(r.substr(a[0].length),e)),!0)})))throw new Error("Could not parse path '"+r+"'");return e},p=function(t){return null!=t},l={urlParamsEncoding:"default"};exports.Path=function(){function e(r,e){if(!r)throw new Error("Missing path in Path constructor");this.path=r,this.options=t.__assign(t.__assign({},l),e),this.tokens=c(r),this.hasUrlParams=this.tokens.filter((function(t){return/^url-parameter/.test(t.type)})).length>0,this.hasSpatParam=this.tokens.filter((function(t){return/splat$/.test(t.type)})).length>0,this.hasMatrixParams=this.tokens.filter((function(t){return/matrix$/.test(t.type)})).length>0,this.hasQueryParams=this.tokens.filter((function(t){return/^query-parameter/.test(t.type)})).length>0,this.spatParams=this.getParams("url-parameter-splat"),this.urlParams=this.getParams(/^url-parameter/),this.queryParams=this.getParams("query-parameter"),this.params=this.urlParams.concat(this.queryParams),this.source=this.tokens.filter((function(t){return void 0!==t.regex})).map((function(t){return t.regex.source})).join("")}return e.createPath=function(t,r){return new e(t,r)},e.prototype.isQueryParam=function(t){return-1!==this.queryParams.indexOf(t)},e.prototype.isSpatParam=function(t){return-1!==this.spatParams.indexOf(t)},e.prototype.test=function(e,n){var a=this,i=t.__assign({caseSensitive:!1,strictTrailingSlash:!1},n),s=function(t,r){return r?t:"\\/"===t?t:t.replace(/\\\/$/,"")+"(?:\\/)?"}(this.source,i.strictTrailingSlash),u=this.urlTest(e,s+(this.hasQueryParams?"(\\?.*$|$)":"$"),i.caseSensitive);if(!u||!this.hasQueryParams)return u;var o=r.parse(e,this.options.queryParams);return 0===Object.keys(o).filter((function(t){return!a.isQueryParam(t)})).length?(Object.keys(o).forEach((function(t){return u[t]=o[t]})),u):null},e.prototype.partialTest=function(e,n){var a=this,i=t.__assign({caseSensitive:!1,delimited:!0},n),s=function(t,r){return r?/(\/)$/.test(t)?t:t+"(\\/|\\?|\\.|;|$)":t}(this.source,i.delimited),u=this.urlTest(e,s,i.caseSensitive);if(!u)return u;if(!this.hasQueryParams)return u;var o=r.parse(e,this.options.queryParams);return Object.keys(o).filter((function(t){return a.isQueryParam(t)})).forEach((function(t){return function(t,r,e){void 0===e&&(e="");var n=t[r];return t[r]=void 0===n?e:Array.isArray(n)?n.concat(e):[n,e],t}(u,t,o[t])})),u},e.prototype.build=function(e,n){var a=this;void 0===e&&(e={});var i=t.__assign({ignoreConstraints:!1,ignoreSearch:!1,queryParams:{},urlParamsEncoding:"default"},n),o=Object.keys(e).filter((function(t){return!a.isQueryParam(t)})).reduce((function(t,r){if(!p(e[r]))return t;var n=e[r],i=a.isSpatParam(r);return t[r]="boolean"==typeof n?n:Array.isArray(n)?n.map((function(t){return s(t,a.options.urlParamsEncoding,i)})):s(n,a.options.urlParamsEncoding,i),t}),{});if(this.urlParams.some((function(t){return!p(e[t])}))){var c=this.urlParams.filter((function(t){return!p(e[t])}));throw new Error("Cannot build path: '"+this.path+"' requires missing parameters { "+c.join(", ")+" }")}if(!i.ignoreConstraints&&!this.tokens.filter((function(t){return/^url-parameter/.test(t.type)&&!/-splat$/.test(t.type)})).every((function(t){return new RegExp("^"+u(t.otherVal[0])+"$").test(o[t.val])})))throw new Error("Some parameters of '"+this.path+"' are of invalid format");var l=this.tokens.filter((function(t){return!1===/^query-parameter/.test(t.type)})).map((function(t){return"url-parameter-matrix"===t.type?";"+t.val+"="+o[t.val[0]]:/^url-parameter/.test(t.type)?o[t.val[0]]:t.match})).join("");if(i.ignoreSearch)return l;var m=this.queryParams.filter((function(t){return-1!==Object.keys(e).indexOf(t)})).reduce((function(t,r){return t[r]=e[r],t}),{}),h=r.build(m,this.options.queryParams);return h?l+"?"+h:l},e.prototype.getParams=function(t){var r=t instanceof RegExp?function(r){return t.test(r.type)}:function(r){return r.type===t};return this.tokens.filter(r).map((function(t){return t.val[0]}))},e.prototype.urlTest=function(t,r,e){var n=this,a=new RegExp("^"+r,e?"":"i"),s=t.match(a);return s?this.urlParams.length?s.slice(1,this.urlParams.length+1).reduce((function(t,r,e){return t[n.urlParams[e]]=(i[n.options.urlParamsEncoding]||decodeURIComponent)(r),t}),{}):{}:null},e}();
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("tslib"),t=require("search-params"),e=/[^!$'()*+,;|:]/g,n=function(r){return r.replace(e,(function(r){return encodeURIComponent(r)}))},a={default:n,uri:encodeURI,uriComponent:encodeURIComponent,none:function(r){return r},legacy:encodeURI},i={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:function(r){return r},legacy:decodeURIComponent},s=function(r,t,e){var i=a[t]||n;return e?String(r).split("/").map(i).join("/"):i(String(r))},u=function(r){return"("+(r?r.replace(/(^<|>$)/g,""):"[a-zA-Z0-9-_.~%':|=+\\*@$]+")+")"},o=[{name:"url-parameter",pattern:/^:([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})(<(.+?)>)?/,regex:function(r){return new RegExp(u(r[2]))}},{name:"url-parameter-splat",pattern:/^\*([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/,regex:/([^?]*)/},{name:"url-parameter-matrix",pattern:/^;([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})(<(.+?)>)?/,regex:function(r){return new RegExp(";"+r[1]+"="+u(r[2]))}},{name:"query-parameter",pattern:/^(?:\?|&)(?::)?([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/},{name:"delimiter",pattern:/^(\/|\?)/,regex:function(r){return new RegExp("\\"+r[0])}},{name:"sub-delimiter",pattern:/^(!|&|-|_|\.|;)/,regex:function(r){return new RegExp(r[0])}},{name:"fragment",pattern:/^([0-9a-zA-Z]+)/,regex:function(r){return new RegExp(r[0])}}],c=function r(t,e){if(void 0===e&&(e=[]),!o.some((function(n){var a=t.match(n.pattern);return!!a&&(e.push({type:n.name,match:a[0],val:a.slice(1,2),otherVal:a.slice(2),regex:n.regex instanceof Function?n.regex(a):n.regex}),a[0].length<t.length&&(e=r(t.substr(a[0].length),e)),!0)})))throw new Error("Could not parse path '"+t+"'");return e},p=function(r){return null!=r},l={urlParamsEncoding:"default"};exports.Path=function(){function e(t,e){if(!t)throw new Error("Missing path in Path constructor");this.path=t,this.options=r.__assign(r.__assign({},l),e),this.tokens=c(t),this.hasUrlParams=this.tokens.filter((function(r){return/^url-parameter/.test(r.type)})).length>0,this.hasSpatParam=this.tokens.filter((function(r){return/splat$/.test(r.type)})).length>0,this.hasMatrixParams=this.tokens.filter((function(r){return/matrix$/.test(r.type)})).length>0,this.hasQueryParams=this.tokens.filter((function(r){return/^query-parameter/.test(r.type)})).length>0,this.spatParams=this.getParams("url-parameter-splat"),this.urlParams=this.getParams(/^url-parameter/),this.queryParams=this.getParams("query-parameter"),this.params=this.urlParams.concat(this.queryParams),this.source=this.tokens.filter((function(r){return void 0!==r.regex})).map((function(r){return r.regex.source})).join("")}return e.createPath=function(r,t){return new e(r,t)},e.prototype.isQueryParam=function(r){return-1!==this.queryParams.indexOf(r)},e.prototype.isSpatParam=function(r){return-1!==this.spatParams.indexOf(r)},e.prototype.test=function(e,n){var a=this,i=r.__assign(r.__assign({caseSensitive:!1,strictTrailingSlash:!1},this.options),n),s=function(r,t){return t?r:"\\/"===r?r:r.replace(/\\\/$/,"")+"(?:\\/)?"}(this.source,i.strictTrailingSlash),u=this.urlTest(e,s+(this.hasQueryParams?"(\\?.*$|$)":"$"),i.caseSensitive,i.urlParamsEncoding);if(!u||!this.hasQueryParams)return u;var o=t.parse(e,i.queryParams);return 0===Object.keys(o).filter((function(r){return!a.isQueryParam(r)})).length?(Object.keys(o).forEach((function(r){return u[r]=o[r]})),u):null},e.prototype.partialTest=function(e,n){var a=this,i=r.__assign(r.__assign({caseSensitive:!1,delimited:!0},this.options),n),s=function(r,t){return t?/(\/)$/.test(r)?r:r+"(\\/|\\?|\\.|;|$)":r}(this.source,i.delimited),u=this.urlTest(e,s,i.caseSensitive,i.urlParamsEncoding);if(!u)return u;if(!this.hasQueryParams)return u;var o=t.parse(e,i.queryParams);return Object.keys(o).filter((function(r){return a.isQueryParam(r)})).forEach((function(r){return function(r,t,e){void 0===e&&(e="");var n=r[t];return r[t]=void 0===n?e:Array.isArray(n)?n.concat(e):[n,e],r}(u,r,o[r])})),u},e.prototype.build=function(e,n){var a=this;void 0===e&&(e={});var i=r.__assign(r.__assign({ignoreConstraints:!1,ignoreSearch:!1,queryParams:{}},this.options),n),o=Object.keys(e).filter((function(r){return!a.isQueryParam(r)})).reduce((function(r,t){if(!p(e[t]))return r;var n=e[t],u=a.isSpatParam(t);return r[t]="boolean"==typeof n?n:Array.isArray(n)?n.map((function(r){return s(r,i.urlParamsEncoding,u)})):s(n,i.urlParamsEncoding,u),r}),{});if(this.urlParams.some((function(r){return!p(e[r])}))){var c=this.urlParams.filter((function(r){return!p(e[r])}));throw new Error("Cannot build path: '"+this.path+"' requires missing parameters { "+c.join(", ")+" }")}if(!i.ignoreConstraints&&!this.tokens.filter((function(r){return/^url-parameter/.test(r.type)&&!/-splat$/.test(r.type)})).every((function(r){return new RegExp("^"+u(r.otherVal[0])+"$").test(o[r.val])})))throw new Error("Some parameters of '"+this.path+"' are of invalid format");var l=this.tokens.filter((function(r){return!1===/^query-parameter/.test(r.type)})).map((function(r){return"url-parameter-matrix"===r.type?";"+r.val+"="+o[r.val[0]]:/^url-parameter/.test(r.type)?o[r.val[0]]:r.match})).join("");if(i.ignoreSearch)return l;var m=this.queryParams.filter((function(r){return-1!==Object.keys(e).indexOf(r)})).reduce((function(r,t){return r[t]=e[t],r}),{}),h=t.build(m,i.queryParams);return h?l+"?"+h:l},e.prototype.getParams=function(r){var t=r instanceof RegExp?function(t){return r.test(t.type)}:function(t){return t.type===r};return this.tokens.filter(t).map((function(r){return r.val[0]}))},e.prototype.urlTest=function(r,t,e,n){var a=this,s=new RegExp("^"+t,e?"":"i"),u=r.match(s);return u?this.urlParams.length?u.slice(1,this.urlParams.length+1).reduce((function(r,t,e){return r[a.urlParams[e]]=(i[n]||decodeURIComponent)(t),r}),{}):{}:null},e}();
//# sourceMappingURL=path-parser.cjs.production.min.js.map

@@ -232,6 +232,6 @@ import { __assign } from 'tslib';

var options = __assign({
var options = __assign(__assign({
caseSensitive: false,
strictTrailingSlash: false
}, opts); // trailingSlash: falsy => non optional, truthy => optional
}, this.options), opts); // trailingSlash: falsy => non optional, truthy => optional

@@ -241,3 +241,3 @@

var match = this.urlTest(path, source + (this.hasQueryParams ? '(\\?.*$|$)' : '$'), options.caseSensitive); // If no match, or no query params, no need to go further
var match = this.urlTest(path, source + (this.hasQueryParams ? '(\\?.*$|$)' : '$'), options.caseSensitive, options.urlParamsEncoding); // If no match, or no query params, no need to go further

@@ -249,3 +249,3 @@ if (!match || !this.hasQueryParams) {

var queryParams = parse(path, this.options.queryParams);
var queryParams = parse(path, options.queryParams);
var unexpectedQueryParams = Object.keys(queryParams).filter(function (p) {

@@ -270,6 +270,6 @@ return !_this.isQueryParam(p);

var options = __assign({
var options = __assign(__assign({
caseSensitive: false,
delimited: true
}, opts); // Check if partial match (start of given path matches regex)
}, this.options), opts); // Check if partial match (start of given path matches regex)
// trailingSlash: falsy => non optional, truthy => optional

@@ -279,3 +279,3 @@

var source = upToDelimiter(this.source, options.delimited);
var match = this.urlTest(path, source, options.caseSensitive);
var match = this.urlTest(path, source, options.caseSensitive, options.urlParamsEncoding);

@@ -290,3 +290,3 @@ if (!match) {

var queryParams = parse(path, this.options.queryParams);
var queryParams = parse(path, options.queryParams);
Object.keys(queryParams).filter(function (p) {

@@ -307,8 +307,7 @@ return _this.isQueryParam(p);

var options = __assign({
var options = __assign(__assign({
ignoreConstraints: false,
ignoreSearch: false,
queryParams: {},
urlParamsEncoding: 'default'
}, opts);
queryParams: {}
}, this.options), opts);

@@ -330,6 +329,6 @@ var encodedUrlParams = Object.keys(params).filter(function (p) {

acc[key] = val.map(function (v) {
return encodeParam(v, _this.options.urlParamsEncoding, isSpatParam);
return encodeParam(v, options.urlParamsEncoding, isSpatParam);
});
} else {
acc[key] = encodeParam(val, _this.options.urlParamsEncoding, isSpatParam);
acc[key] = encodeParam(val, options.urlParamsEncoding, isSpatParam);
}

@@ -382,3 +381,3 @@

}, {});
var searchPart = build(searchParams, this.options.queryParams);
var searchPart = build(searchParams, options.queryParams);
return searchPart ? base + '?' + searchPart : base;

@@ -398,3 +397,3 @@ };

Path.prototype.urlTest = function (path, source, caseSensitive) {
Path.prototype.urlTest = function (path, source, caseSensitive, urlParamsEncoding) {
var _this = this;

@@ -413,3 +412,3 @@

return match.slice(1, this.urlParams.length + 1).reduce(function (params, m, i) {
params[_this.urlParams[i]] = decodeParam(m, _this.options.urlParamsEncoding);
params[_this.urlParams[i]] = decodeParam(m, urlParamsEncoding);
return params;

@@ -416,0 +415,0 @@ }, {});

@@ -30,11 +30,11 @@ import { IOptions } from 'search-params';

}
export interface PathPartialTestOptions {
export interface PathPartialTestOptions extends PathOptions {
caseSensitive?: boolean;
delimited?: boolean;
}
export interface PathTestOptions {
export interface PathTestOptions extends PathOptions {
caseSensitive?: boolean;
strictTrailingSlash?: boolean;
}
export interface PathBuildOptions {
export interface PathBuildOptions extends PathOptions {
ignoreConstraints?: boolean;

@@ -41,0 +41,0 @@ ignoreSearch?: boolean;

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

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -104,2 +104,4 @@ [![npm version](https://badge.fury.io/js/path-parser.svg)](http://badge.fury.io/js/path-parser)

- `'delimited'`: whether or not a partial match should only be successful if it reaches a delimiter (`/`, `?`, `.` and `;`). Default to `true`.
- `'queryParams'`: to overwrite query parameter options (see above)
- `'urlParamsEncoding`: to overwrite URL param encoding and decoding option (see above)

@@ -113,2 +115,4 @@ ### path.build(params?: object, opts?: object): string;

- `'ignoreSearch'`: whether or not to build query parameters (default to `false`)
- `'queryParams'`: to overwrite query parameter options (see above)
- `'urlParamsEncoding`: to overwrite URL param encoding and decoding option (see above)

@@ -115,0 +119,0 @@ ## Related modules

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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