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

universal-router

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

universal-router - npm Package Compare versions

Comparing version 4.2.1 to 4.3.0

2

generateUrls/package.json
{
"private": true,
"name": "generateUrls",
"version": "4.2.1",
"version": "4.3.0",
"description": "Universal Router Generate URLs Add-on",

@@ -6,0 +6,0 @@ "homepage": "https://www.kriasoft.com/universal-router/",

{
"name": "universal-router",
"version": "4.2.1",
"version": "4.3.0",
"description": "Isomorphic router for JavaScript web applications",

@@ -31,4 +31,4 @@ "homepage": "https://www.kriasoft.com/universal-router/",

"dependencies": {
"path-to-regexp": "^2.0.0"
"path-to-regexp": "^2.1.0"
}
}

@@ -24,3 +24,3 @@ <a href="https://www.kriasoft.com/universal-router/" target="_blank">

✓ It has [simple code](https://github.com/kriasoft/universal-router/blob/v4.2.1/src/UniversalRouter.js)
✓ It has [simple code](https://github.com/kriasoft/universal-router/blob/v4.3.0/src/UniversalRouter.js)
with only single [path-to-regexp](https://github.com/pillarjs/path-to-regexp) dependency<br>

@@ -46,3 +46,3 @@ ✓ It can be used with any JavaScript framework such as React, Vue.js etc<br>

```html
<script src="https://unpkg.com/universal-router@4.2.1/universal-router.min.js"></script>
<script src="https://unpkg.com/universal-router@4.3.0/universal-router.min.js"></script>
```

@@ -49,0 +49,0 @@

@@ -19,2 +19,8 @@ /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */

/**
* Default configs.
*/
var DEFAULT_DELIMITER = '/';
var DEFAULT_DELIMITERS = './';
/**
* The main path matching regexp utility.

@@ -48,4 +54,4 @@ *

var path = '';
var defaultDelimiter = (options && options.delimiter) || '/';
var delimiters = (options && options.delimiters) || './';
var defaultDelimiter = (options && options.delimiter) || DEFAULT_DELIMITER;
var delimiters = (options && options.delimiters) || DEFAULT_DELIMITERS;
var pathEscaped = false;

@@ -308,5 +314,7 @@ var res;

var end = options.end !== false;
var delimiter = escapeString(options.delimiter || '/');
var delimiter = escapeString(options.delimiter || DEFAULT_DELIMITER);
var delimiters = options.delimiters || DEFAULT_DELIMITERS;
var endsWith = [].concat(options.endsWith || []).map(escapeString).concat('$').join('|');
var route = '';
var isEndDelimited = false;

@@ -319,37 +327,30 @@ // Iterate over the tokens and create our regexp string.

route += escapeString(token);
isEndDelimited = i === tokens.length - 1 && delimiters.indexOf(token[token.length - 1]) > -1;
} else {
var prefix = escapeString(token.prefix);
var capture = '(?:' + token.pattern + ')';
var capture = token.repeat
? '(?:' + token.pattern + ')(?:' + prefix + '(?:' + token.pattern + '))*'
: token.pattern;
if (keys) keys.push(token);
if (token.repeat) {
capture += '(?:' + prefix + capture + ')*';
}
if (token.optional) {
if (!token.partial) {
capture = '(?:' + prefix + '(' + capture + '))?';
if (token.partial) {
route += prefix + '(' + capture + ')?';
} else {
capture = prefix + '(' + capture + ')?';
route += '(?:' + prefix + '(' + capture + '))?';
}
} else {
capture = prefix + '(' + capture + ')';
route += prefix + '(' + capture + ')';
}
route += capture;
}
}
// In non-strict mode we allow a delimiter at the end of a match.
if (!strict) {
route += '(?:' + delimiter + '(?=' + endsWith + '))?';
}
if (end) {
if (!strict) route += '(?:' + delimiter + ')?';
if (end) {
route += endsWith === '$' ? endsWith : '(?=' + endsWith + ')';
route += endsWith === '$' ? '$' : '(?=' + endsWith + ')';
} else {
// In non-ending mode, we need the capturing groups to match as much as
// possible by using a positive lookahead to the end or next path segment.
route += '(?=' + delimiter + '|' + endsWith + ')';
if (!strict) route += '(?:' + delimiter + '(?=' + endsWith + '))?';
if (!isEndDelimited) route += '(?=' + delimiter + '|' + endsWith + ')';
}

@@ -356,0 +357,0 @@

/*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.UniversalRouter=t()}(this,function(){"use strict";function e(e,t){for(var o,a=[],i=0,u=0,l="",s=t&&t.delimiter||"/",p=t&&t.delimiters||"./",c=!1;null!==(o=b.exec(e));){var f=o[0],h=o[1],v=o.index;if(l+=e.slice(u,v),u=v+f.length,h)l+=h[1],c=!0;else{var d="",g=e[u],m=o[2],y=o[3],x=o[4],w=o[5];if(!c&&l.length){var E=l.length-1;p.indexOf(l[E])>-1&&(d=l[E],l=l.slice(0,E))}l&&(a.push(l),l="",c=!1);var R=""!==d&&void 0!==g&&g!==d,j="+"===w||"*"===w,k="?"===w||"*"===w,O=d||s,T=y||x;a.push({name:m||i++,prefix:d,delimiter:O,optional:k,repeat:j,partial:R,pattern:T?n(T):"[^"+r(O)+"]+?"})}}return(l||u<e.length)&&a.push(l+e.substr(u)),a}function t(e){for(var t=new Array(e.length),r=0;r<e.length;r++)"object"==typeof e[r]&&(t[r]=new RegExp("^(?:"+e[r].pattern+")$"));return function(r,n){for(var o="",a=n&&n.encode||encodeURIComponent,i=0;i<e.length;i++){var u=e[i];if("string"!=typeof u){var l,s=r?r[u.name]:void 0;if(Array.isArray(s)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===s.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var p=0;p<s.length;p++){if(l=a(s[p]),!t[i].test(l))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');o+=(0===p?u.prefix:u.delimiter)+l}}else if("string"!=typeof s&&"number"!=typeof s&&"boolean"!=typeof s){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(o+=u.prefix)}else{if(l=a(String(s)),!t[i].test(l))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+l+'"');o+=u.prefix+l}}else o+=u}return o}}function r(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function n(e){return e.replace(/([=!:$/()])/g,"\\$1")}function o(e){return e&&e.sensitive?"":"i"}function a(e,t){if(!t)return e;var r=e.source.match(/\((?!\?)/g);if(r)for(var n=0;n<r.length;n++)t.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return e}function i(e,t,r){for(var n=[],a=0;a<e.length;a++)n.push(s(e[a],t,r).source);return new RegExp("(?:"+n.join("|")+")",o(r))}function u(t,r,n){return l(e(t,n),r,n)}function l(e,t,n){for(var a=(n=n||{}).strict,i=!1!==n.end,u=r(n.delimiter||"/"),l=[].concat(n.endsWith||[]).map(r).concat("$").join("|"),s="",p=0;p<e.length;p++){var c=e[p];if("string"==typeof c)s+=r(c);else{var f=r(c.prefix),h="(?:"+c.pattern+")";t&&t.push(c),c.repeat&&(h+="(?:"+f+h+")*"),s+=h=c.optional?c.partial?f+"("+h+")?":"(?:"+f+"("+h+"))?":f+"("+h+")"}}return a||(s+="(?:"+u+"(?="+l+"))?"),s+=i?"$"===l?l:"(?="+l+")":"(?="+u+"|"+l+")",new RegExp("^"+s,o(n))}function s(e,t,r){return e instanceof RegExp?a(e,t):Array.isArray(e)?i(e,t,r):u(e,t,r)}function p(e){try{return decodeURIComponent(e)}catch(t){return e}}function c(e,t,r,n){var o=!e.children,a=(e.path||"")+"|"+o,i=E.get(a);if(!i){var u=[];i={keys:u,pattern:g(e.path||"",u,{end:o})},E.set(a,i)}var l=i.pattern.exec(t);if(!l)return null;for(var s=l[0],c=Object.assign({},n),f=1;f<l.length;f+=1){var h=i.keys[f-1],v=h.name,d=l[f];void 0===d&&w.call(c,v)||(h.repeat?c[v]=d?d.split(h.delimiter).map(p):[]:c[v]=d?p(d):d)}return{path:o||"/"!==s.charAt(s.length-1)?s:s.substr(1),keys:r.concat(i.keys),params:c}}function f(e,t,r,n,o){var a=void 0,i=void 0,u=0;return{next:function(){if(!a&&(a=c(e,r,n,o)))return{done:!1,value:{route:e,baseUrl:t,path:a.path,keys:a.keys,params:a.params}};if(a&&e.children)for(;u<e.children.length;){if(!i){var l=e.children[u];l.parent=e,i=f(l,t+a.path,r.substr(a.path.length),a.keys,a.params)}var s=i.next();if(!s.done)return{done:!1,value:s.value};i=null,u+=1}return{done:!0}}}}function h(e,t){return"function"==typeof e.route.action?e.route.action(e,t):null}function v(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t){for(var r=t;r;)if((r=r.parent)===e)return!0;return!1}var g=s,m=e,y=t,x=l,b=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");g.parse=m,g.compile=function(r,n){return t(e(r,n))},g.tokensToFunction=y,g.tokensToRegExp=x;var w=Object.prototype.hasOwnProperty,E=new Map,R=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),j=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(v(this,e),Object(t)!==t)throw new TypeError("Invalid routes");this.baseUrl=r.baseUrl||"",this.resolveRoute=r.resolveRoute||h,this.context=Object.assign({router:this},r.context),this.root=Array.isArray(t)?{path:"",children:t,parent:null}:t,this.root.parent=null}return R(e,[{key:"resolve",value:function(e){function t(e){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:a.value.route;return a=i||n.next(),i=null,e||!a.done&&d(u,a.value.route)?a.done?Promise.reject(Object.assign(new Error("Page not found"),{context:r,status:404,statusCode:404})):Promise.resolve(o(Object.assign({},r,a.value),a.value.params)).then(function(r){return null!==r&&void 0!==r?r:t(e,u)}):(i=a,Promise.resolve(null))}var r=Object.assign({},this.context,"string"==typeof e?{pathname:e}:e),n=f(this.root,this.baseUrl,r.pathname.substr(this.baseUrl.length),[],null),o=this.resolveRoute,a=null,i=null;return r.next=t,t(!0,this.root)}}]),e}();return j.pathToRegexp=g,j.matchPath=c,j.matchRoute=f,j.resolveRoute=h,j});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.UniversalRouter=t()}(this,function(){"use strict";function e(e,t){for(var o,a=[],i=0,u=0,l="",s=t&&t.delimiter||b,p=t&&t.delimiters||w,c=!1;null!==(o=E.exec(e));){var f=o[0],h=o[1],v=o.index;if(l+=e.slice(u,v),u=v+f.length,h)l+=h[1],c=!0;else{var d="",g=e[u],m=o[2],y=o[3],x=o[4],R=o[5];if(!c&&l.length){var j=l.length-1;p.indexOf(l[j])>-1&&(d=l[j],l=l.slice(0,j))}l&&(a.push(l),l="",c=!1);var k=""!==d&&void 0!==g&&g!==d,O="+"===R||"*"===R,T="?"===R||"*"===R,A=d||s,U=y||x;a.push({name:m||i++,prefix:d,delimiter:A,optional:T,repeat:O,partial:k,pattern:U?n(U):"[^"+r(A)+"]+?"})}}return(l||u<e.length)&&a.push(l+e.substr(u)),a}function t(e){for(var t=new Array(e.length),r=0;r<e.length;r++)"object"==typeof e[r]&&(t[r]=new RegExp("^(?:"+e[r].pattern+")$"));return function(r,n){for(var o="",a=n&&n.encode||encodeURIComponent,i=0;i<e.length;i++){var u=e[i];if("string"!=typeof u){var l,s=r?r[u.name]:void 0;if(Array.isArray(s)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===s.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var p=0;p<s.length;p++){if(l=a(s[p]),!t[i].test(l))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');o+=(0===p?u.prefix:u.delimiter)+l}}else if("string"!=typeof s&&"number"!=typeof s&&"boolean"!=typeof s){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(o+=u.prefix)}else{if(l=a(String(s)),!t[i].test(l))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+l+'"');o+=u.prefix+l}}else o+=u}return o}}function r(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function n(e){return e.replace(/([=!:$/()])/g,"\\$1")}function o(e){return e&&e.sensitive?"":"i"}function a(e,t){if(!t)return e;var r=e.source.match(/\((?!\?)/g);if(r)for(var n=0;n<r.length;n++)t.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return e}function i(e,t,r){for(var n=[],a=0;a<e.length;a++)n.push(s(e[a],t,r).source);return new RegExp("(?:"+n.join("|")+")",o(r))}function u(t,r,n){return l(e(t,n),r,n)}function l(e,t,n){for(var a=(n=n||{}).strict,i=!1!==n.end,u=r(n.delimiter||b),l=n.delimiters||w,s=[].concat(n.endsWith||[]).map(r).concat("$").join("|"),p="",c=!1,f=0;f<e.length;f++){var h=e[f];if("string"==typeof h)p+=r(h),c=f===e.length-1&&l.indexOf(h[h.length-1])>-1;else{var v=r(h.prefix),d=h.repeat?"(?:"+h.pattern+")(?:"+v+"(?:"+h.pattern+"))*":h.pattern;t&&t.push(h),h.optional?h.partial?p+=v+"("+d+")?":p+="(?:"+v+"("+d+"))?":p+=v+"("+d+")"}}return i?(a||(p+="(?:"+u+")?"),p+="$"===s?"$":"(?="+s+")"):(a||(p+="(?:"+u+"(?="+s+"))?"),c||(p+="(?="+u+"|"+s+")")),new RegExp("^"+p,o(n))}function s(e,t,r){return e instanceof RegExp?a(e,t):Array.isArray(e)?i(e,t,r):u(e,t,r)}function p(e){try{return decodeURIComponent(e)}catch(t){return e}}function c(e,t,r,n){var o=!e.children,a=(e.path||"")+"|"+o,i=j.get(a);if(!i){var u=[];i={keys:u,pattern:g(e.path||"",u,{end:o})},j.set(a,i)}var l=i.pattern.exec(t);if(!l)return null;for(var s=l[0],c=Object.assign({},n),f=1;f<l.length;f+=1){var h=i.keys[f-1],v=h.name,d=l[f];void 0===d&&R.call(c,v)||(h.repeat?c[v]=d?d.split(h.delimiter).map(p):[]:c[v]=d?p(d):d)}return{path:o||"/"!==s.charAt(s.length-1)?s:s.substr(1),keys:r.concat(i.keys),params:c}}function f(e,t,r,n,o){var a=void 0,i=void 0,u=0;return{next:function(){if(!a&&(a=c(e,r,n,o)))return{done:!1,value:{route:e,baseUrl:t,path:a.path,keys:a.keys,params:a.params}};if(a&&e.children)for(;u<e.children.length;){if(!i){var l=e.children[u];l.parent=e,i=f(l,t+a.path,r.substr(a.path.length),a.keys,a.params)}var s=i.next();if(!s.done)return{done:!1,value:s.value};i=null,u+=1}return{done:!0}}}}function h(e,t){return"function"==typeof e.route.action?e.route.action(e,t):null}function v(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t){for(var r=t;r;)if((r=r.parent)===e)return!0;return!1}var g=s,m=e,y=t,x=l,b="/",w="./",E=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");g.parse=m,g.compile=function(r,n){return t(e(r,n))},g.tokensToFunction=y,g.tokensToRegExp=x;var R=Object.prototype.hasOwnProperty,j=new Map,k=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),O=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(v(this,e),Object(t)!==t)throw new TypeError("Invalid routes");this.baseUrl=r.baseUrl||"",this.resolveRoute=r.resolveRoute||h,this.context=Object.assign({router:this},r.context),this.root=Array.isArray(t)?{path:"",children:t,parent:null}:t,this.root.parent=null}return k(e,[{key:"resolve",value:function(e){function t(e){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:a.value.route;return a=i||n.next(),i=null,e||!a.done&&d(u,a.value.route)?a.done?Promise.reject(Object.assign(new Error("Page not found"),{context:r,status:404,statusCode:404})):Promise.resolve(o(Object.assign({},r,a.value),a.value.params)).then(function(r){return null!==r&&void 0!==r?r:t(e,u)}):(i=a,Promise.resolve(null))}var r=Object.assign({},this.context,"string"==typeof e?{pathname:e}:e),n=f(this.root,this.baseUrl,r.pathname.substr(this.baseUrl.length),[],null),o=this.resolveRoute,a=null,i=null;return r.next=t,t(!0,this.root)}}]),e}();return O.pathToRegexp=g,O.matchPath=c,O.matchRoute=f,O.resolveRoute=h,O});
//# sourceMappingURL=universal-router.min.js.map

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