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 5.0.0 to 5.0.1

11

CHANGELOG.md

@@ -0,1 +1,12 @@

## [5.0.1](https://github.com/troch/path-parser/compare/v5.0.0...v5.0.1) (2019-12-29)
### Bug Fixes
* Revert encoding fix ([c43c07e](https://github.com/troch/path-parser/commit/c43c07e1d89d9c324a84683be55d1634445f2a21))
Note: not all cases were accounted for and the benefits of this fix is currently unclear.
# [5.0.0](https://github.com/troch/path-parser/compare/v4.2.0...v5.0.0) (2019-12-29)

@@ -2,0 +13,0 @@

4

dist/path-parser.cjs.development.js

@@ -114,3 +114,3 @@ 'use strict';

var encodeSpatParam = function encodeSpatParam(value) {
return value.split('/').map(encodeURIComponent).join('/');
return value.split('/').map(encodeURI).join('/');
};

@@ -275,3 +275,3 @@

var val = params[key];
var encode = _this.isQueryParam(key) ? identity : _this.isSpatParam(key) ? encodeSpatParam : encodeURIComponent;
var encode = _this.isQueryParam(key) ? identity : _this.isSpatParam(key) ? encodeSpatParam : encodeURI;

@@ -278,0 +278,0 @@ if (typeof val === 'boolean') {

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

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

@@ -110,3 +110,3 @@ import { __assign } from 'tslib';

var encodeSpatParam = function encodeSpatParam(value) {
return value.split('/').map(encodeURIComponent).join('/');
return value.split('/').map(encodeURI).join('/');
};

@@ -271,3 +271,3 @@

var val = params[key];
var encode = _this.isQueryParam(key) ? identity : _this.isSpatParam(key) ? encodeSpatParam : encodeURIComponent;
var encode = _this.isQueryParam(key) ? identity : _this.isSpatParam(key) ? encodeSpatParam : encodeURI;

@@ -274,0 +274,0 @@ if (typeof val === 'boolean') {

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

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

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