universal-router
Advanced tools
Comparing version 9.0.1 to 9.1.0
@@ -7,9 +7,9 @@ /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
function cacheRoutes(routesByName, route, routes) { | ||
if (route.name && routesByName.has(route.name)) { | ||
throw new Error("Route \"" + route.name + "\" already exists"); | ||
function cacheRoutes(routesByName, route, routes, name, sep) { | ||
if (route.name && name && routesByName.has(name)) { | ||
throw new Error("Route \"" + name + "\" already exists"); | ||
} | ||
if (route.name) { | ||
routesByName.set(route.name, route); | ||
if (route.name && name) { | ||
routesByName.set(name, route); | ||
} | ||
@@ -20,4 +20,5 @@ | ||
var childRoute = routes[i]; | ||
var childName = childRoute.name; | ||
childRoute.parent = route; | ||
cacheRoutes(routesByName, childRoute, childRoute.children); | ||
cacheRoutes(routesByName, childRoute, childRoute.children, name && sep ? childName ? name + sep + childName : name : childName, sep); | ||
} | ||
@@ -43,3 +44,3 @@ } | ||
regexpByRoute.clear(); | ||
cacheRoutes(routesByName, router.root, router.root.children); | ||
cacheRoutes(routesByName, router.root, router.root.children, router.root.name, opts.uniqueRouteNameSep); | ||
route = routesByName.get(routeName); | ||
@@ -46,0 +47,0 @@ |
@@ -5,9 +5,9 @@ /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
function cacheRoutes(routesByName, route, routes) { | ||
if (route.name && routesByName.has(route.name)) { | ||
throw new Error("Route \"" + route.name + "\" already exists"); | ||
function cacheRoutes(routesByName, route, routes, name, sep) { | ||
if (route.name && name && routesByName.has(name)) { | ||
throw new Error("Route \"" + name + "\" already exists"); | ||
} | ||
if (route.name) { | ||
routesByName.set(route.name, route); | ||
if (route.name && name) { | ||
routesByName.set(name, route); | ||
} | ||
@@ -18,4 +18,5 @@ | ||
var childRoute = routes[i]; | ||
var childName = childRoute.name; | ||
childRoute.parent = route; | ||
cacheRoutes(routesByName, childRoute, childRoute.children); | ||
cacheRoutes(routesByName, childRoute, childRoute.children, name && sep ? childName ? name + sep + childName : name : childName, sep); | ||
} | ||
@@ -41,3 +42,3 @@ } | ||
regexpByRoute.clear(); | ||
cacheRoutes(routesByName, router.root, router.root.children); | ||
cacheRoutes(routesByName, router.root, router.root.children, router.root.name, opts.uniqueRouteNameSep); | ||
route = routesByName.get(routeName); | ||
@@ -44,0 +45,0 @@ |
{ | ||
"private": true, | ||
"name": "generateUrls", | ||
"version": "9.0.1", | ||
"version": "9.1.0", | ||
"description": "Universal Router Generate URLs Add-on", | ||
@@ -6,0 +6,0 @@ "homepage": "https://www.kriasoft.com/universal-router/", |
@@ -44,3 +44,3 @@ /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
matchResult.path = !end && path.charAt(path.length - 1) === '/' ? path.substr(1) : path; | ||
matchResult.params = Object.assign({}, parentParams, {}, matchResult.params); | ||
matchResult.params = Object.assign({}, parentParams, matchResult.params); | ||
return { | ||
@@ -135,3 +135,3 @@ done: false, | ||
router: this | ||
}, this.options.context, {}, typeof pathnameOrContext === 'string' ? { | ||
}, this.options.context, typeof pathnameOrContext === 'string' ? { | ||
pathname: pathnameOrContext | ||
@@ -167,3 +167,3 @@ } : pathnameOrContext); | ||
currentContext = Object.assign({}, context, {}, matches.value); | ||
currentContext = Object.assign({}, context, matches.value); | ||
return Promise.resolve(resolve(currentContext, matches.value.params)).then(function (result) { | ||
@@ -170,0 +170,0 @@ if (result !== null && result !== undefined) { |
@@ -42,3 +42,3 @@ /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
matchResult.path = !end && path.charAt(path.length - 1) === '/' ? path.substr(1) : path; | ||
matchResult.params = Object.assign({}, parentParams, {}, matchResult.params); | ||
matchResult.params = Object.assign({}, parentParams, matchResult.params); | ||
return { | ||
@@ -133,3 +133,3 @@ done: false, | ||
router: this | ||
}, this.options.context, {}, typeof pathnameOrContext === 'string' ? { | ||
}, this.options.context, typeof pathnameOrContext === 'string' ? { | ||
pathname: pathnameOrContext | ||
@@ -165,3 +165,3 @@ } : pathnameOrContext); | ||
currentContext = Object.assign({}, context, {}, matches.value); | ||
currentContext = Object.assign({}, context, matches.value); | ||
return Promise.resolve(resolve(currentContext, matches.value.params)).then(function (result) { | ||
@@ -168,0 +168,0 @@ if (result !== null && result !== undefined) { |
{ | ||
"name": "universal-router", | ||
"version": "9.0.1", | ||
"version": "9.1.0", | ||
"description": "Isomorphic router for JavaScript web applications", | ||
@@ -25,4 +25,4 @@ "homepage": "https://www.kriasoft.com/universal-router/", | ||
"dependencies": { | ||
"path-to-regexp": "^6.1.0" | ||
"path-to-regexp": "^6.2.0" | ||
} | ||
} |
@@ -19,2 +19,6 @@ /** | ||
stringifyQueryParams?: (params: UrlParams) => string; | ||
/** | ||
* Generates a unique route name based on all parent routes with the specified separator. | ||
*/ | ||
uniqueRouteNameSep?: string; | ||
} | ||
@@ -21,0 +25,0 @@ /** |
@@ -10,8 +10,8 @@ /** | ||
import { parse, tokensToFunction, } from 'path-to-regexp'; | ||
function cacheRoutes(routesByName, route, routes) { | ||
if (route.name && routesByName.has(route.name)) { | ||
throw new Error(`Route "${route.name}" already exists`); | ||
function cacheRoutes(routesByName, route, routes, name, sep) { | ||
if (route.name && name && routesByName.has(name)) { | ||
throw new Error(`Route "${name}" already exists`); | ||
} | ||
if (route.name) { | ||
routesByName.set(route.name, route); | ||
if (route.name && name) { | ||
routesByName.set(name, route); | ||
} | ||
@@ -21,4 +21,5 @@ if (routes) { | ||
const childRoute = routes[i]; | ||
const childName = childRoute.name; | ||
childRoute.parent = route; | ||
cacheRoutes(routesByName, childRoute, childRoute.children); | ||
cacheRoutes(routesByName, childRoute, childRoute.children, name && sep ? (childName ? name + sep + childName : name) : childName, sep); | ||
} | ||
@@ -42,3 +43,3 @@ } | ||
regexpByRoute.clear(); | ||
cacheRoutes(routesByName, router.root, router.root.children); | ||
cacheRoutes(routesByName, router.root, router.root.children, router.root.name, opts.uniqueRouteNameSep); | ||
route = routesByName.get(routeName); | ||
@@ -45,0 +46,0 @@ if (!route) { |
@@ -28,2 +28,6 @@ /** | ||
stringifyQueryParams?: (params: UrlParams) => string | ||
/** | ||
* Generates a unique route name based on all parent routes with the specified separator. | ||
*/ | ||
uniqueRouteNameSep?: string | ||
} | ||
@@ -44,9 +48,11 @@ | ||
routes: Routes | null | undefined, | ||
name?: string, | ||
sep?: string, | ||
): void { | ||
if (route.name && routesByName.has(route.name)) { | ||
throw new Error(`Route "${route.name}" already exists`) | ||
if (route.name && name && routesByName.has(name)) { | ||
throw new Error(`Route "${name}" already exists`) | ||
} | ||
if (route.name) { | ||
routesByName.set(route.name, route) | ||
if (route.name && name) { | ||
routesByName.set(name, route) | ||
} | ||
@@ -57,4 +63,11 @@ | ||
const childRoute = routes[i] | ||
const childName = childRoute.name | ||
childRoute.parent = route | ||
cacheRoutes(routesByName, childRoute, childRoute.children) | ||
cacheRoutes( | ||
routesByName, | ||
childRoute, | ||
childRoute.children, | ||
name && sep ? (childName ? name + sep + childName : name) : childName, | ||
sep, | ||
) | ||
} | ||
@@ -80,3 +93,9 @@ } | ||
regexpByRoute.clear() | ||
cacheRoutes(routesByName, router.root, router.root.children) | ||
cacheRoutes( | ||
routesByName, | ||
router.root, | ||
router.root.children, | ||
router.root.name, | ||
opts.uniqueRouteNameSep, | ||
) | ||
@@ -83,0 +102,0 @@ route = routesByName.get(routeName) |
@@ -44,3 +44,3 @@ /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
matchResult.path = !end && path.charAt(path.length - 1) === '/' ? path.substr(1) : path; | ||
matchResult.params = Object.assign({}, parentParams, {}, matchResult.params); | ||
matchResult.params = Object.assign({}, parentParams, matchResult.params); | ||
return { | ||
@@ -133,3 +133,3 @@ done: false, | ||
router: this | ||
}, this.options.context, {}, typeof pathnameOrContext === 'string' ? { | ||
}, this.options.context, typeof pathnameOrContext === 'string' ? { | ||
pathname: pathnameOrContext | ||
@@ -165,3 +165,3 @@ } : pathnameOrContext); | ||
currentContext = Object.assign({}, context, {}, matches.value); | ||
currentContext = Object.assign({}, context, matches.value); | ||
var result = resolve(currentContext, matches.value.params); | ||
@@ -168,0 +168,0 @@ |
@@ -42,3 +42,3 @@ /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
matchResult.path = !end && path.charAt(path.length - 1) === '/' ? path.substr(1) : path; | ||
matchResult.params = Object.assign({}, parentParams, {}, matchResult.params); | ||
matchResult.params = Object.assign({}, parentParams, matchResult.params); | ||
return { | ||
@@ -131,3 +131,3 @@ done: false, | ||
router: this | ||
}, this.options.context, {}, typeof pathnameOrContext === 'string' ? { | ||
}, this.options.context, typeof pathnameOrContext === 'string' ? { | ||
pathname: pathnameOrContext | ||
@@ -163,3 +163,3 @@ } : pathnameOrContext); | ||
currentContext = Object.assign({}, context, {}, matches.value); | ||
currentContext = Object.assign({}, context, matches.value); | ||
var result = resolve(currentContext, matches.value.params); | ||
@@ -166,0 +166,0 @@ |
{ | ||
"private": true, | ||
"name": "sync", | ||
"version": "9.0.1", | ||
"version": "9.1.0", | ||
"description": "Universal Router Sync Add-on", | ||
@@ -6,0 +6,0 @@ "homepage": "https://www.kriasoft.com/universal-router/", |
@@ -6,3 +6,3 @@ /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.generateUrls = factory()); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.generateUrls = factory()); | ||
}(this, (function () { 'use strict'; | ||
@@ -322,9 +322,9 @@ | ||
function cacheRoutes(routesByName, route, routes) { | ||
if (route.name && routesByName.has(route.name)) { | ||
throw new Error("Route \"" + route.name + "\" already exists"); | ||
function cacheRoutes(routesByName, route, routes, name, sep) { | ||
if (route.name && name && routesByName.has(name)) { | ||
throw new Error("Route \"" + name + "\" already exists"); | ||
} | ||
if (route.name) { | ||
routesByName.set(route.name, route); | ||
if (route.name && name) { | ||
routesByName.set(name, route); | ||
} | ||
@@ -335,4 +335,5 @@ | ||
var childRoute = routes[i]; | ||
var childName = childRoute.name; | ||
childRoute.parent = route; | ||
cacheRoutes(routesByName, childRoute, childRoute.children); | ||
cacheRoutes(routesByName, childRoute, childRoute.children, name && sep ? childName ? name + sep + childName : name : childName, sep); | ||
} | ||
@@ -358,3 +359,3 @@ } | ||
regexpByRoute.clear(); | ||
cacheRoutes(routesByName, router.root, router.root.children); | ||
cacheRoutes(routesByName, router.root, router.root.children, router.root.name, opts.uniqueRouteNameSep); | ||
route = routesByName.get(routeName); | ||
@@ -361,0 +362,0 @@ |
/*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e=e||self).generateUrls=r()}(this,function(){"use strict";function A(e,r){void 0===r&&(r={});for(var i=function(e){for(var r=[],t=0;t<e.length;){var n=e[t];if("*"!==n&&"+"!==n&&"?"!==n)if("\\"!==n)if("{"!==n)if("}"!==n)if(":"!==n)if("("!==n)r.push({type:"CHAR",index:t,value:e[t++]});else{var a=1,i="";if("?"===e[f=t+1])throw new TypeError('Pattern cannot start with "?" at '+f);for(;f<e.length;)if("\\"!==e[f]){if(")"===e[f]){if(0===--a){f++;break}}else if("("===e[f]&&(a++,"?"!==e[f+1]))throw new TypeError("Capturing groups are not allowed at "+f);i+=e[f++]}else i+=e[f++]+e[f++];if(a)throw new TypeError("Unbalanced pattern at "+t);if(!i)throw new TypeError("Missing pattern at "+t);r.push({type:"PATTERN",index:t,value:i}),t=f}else{for(var o="",f=t+1;f<e.length;){var p=e.charCodeAt(f);if(!(48<=p&&p<=57||65<=p&&p<=90||97<=p&&p<=122||95===p))break;o+=e[f++]}if(!o)throw new TypeError("Missing parameter name at "+t);r.push({type:"NAME",index:t,value:o}),t=f}else r.push({type:"CLOSE",index:t,value:e[t++]});else r.push({type:"OPEN",index:t,value:e[t++]});else r.push({type:"ESCAPED_CHAR",index:t++,value:e[t++]});else r.push({type:"MODIFIER",index:t,value:e[t++]})}return r.push({type:"END",index:t,value:""}),r}(e),t=r.prefixes,n=void 0===t?"./":t,a="[^"+(r.delimiter||"/#?").replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")+"]+?",o=[],f=0,p=0,s="",u=function(e){if(p<i.length&&i[p].type===e)return i[p++].value},l=function(e){var r=u(e);if(void 0!==r)return r;var t=i[p],n=t.type,a=t.index;throw new TypeError("Unexpected "+n+" at "+a+", expected "+e)},d=function(){for(var e,r="";e=u("CHAR")||u("ESCAPED_CHAR");)r+=e;return r};p<i.length;){var h=u("CHAR"),v=u("NAME"),c=u("PATTERN");if(v||c){var y=h||"";-1===n.indexOf(y)&&(s+=y,y=""),s&&(o.push(s),s=""),o.push({name:v||f++,prefix:y,suffix:"",pattern:c||a,modifier:u("MODIFIER")||""})}else{var E=h||u("ESCAPED_CHAR");if(E)s+=E;else if(s&&(o.push(s),s=""),u("OPEN")){y=d();var m=u("NAME")||"",w=u("PATTERN")||"",g=d();l("CLOSE"),o.push({name:m||(w?f++:""),pattern:m&&!w?a:w,prefix:y,suffix:g,modifier:u("MODIFIER")||""})}else l("END")}}return o}return function(m,e){if(!m)throw new ReferenceError("Router is not defined");var w=new Map,g=new Map,x=Object.assign({encode:encodeURIComponent},e);return function(e,r){var t=w.get(e);if(!(t||(w.clear(),g.clear(),function e(r,t,n){if(t.name&&r.has(t.name))throw new Error('Route "'+t.name+'" already exists');if(t.name&&r.set(t.name,t),n)for(var a=0;a<n.length;a++){var i=n[a];i.parent=t,e(r,i,i.children)}}(w,m.root,m.root.children),t=w.get(e))))throw new Error('Route "'+e+'" not found');var n=g.get(t);if(!n){for(var a="",i=t;i;){var o=Array.isArray(i.path)?i.path[0]:i.path;o&&(a=o+a),i=i.parent}for(var f=A(a,x),p=function(u,e){void 0===e&&(e={});var r,t=(r=e)&&r.sensitive?"":"i",n=e.encode,l=void 0===n?function(e){return e}:n,a=e.validate,d=void 0===a||a,h=u.map(function(e){if("object"==typeof e)return new RegExp("^(?:"+e.pattern+")$",t)});return function(e){for(var r="",t=0;t<u.length;t++){var n=u[t];if("string"!=typeof n){var a=e?e[n.name]:void 0,i="?"===n.modifier||"*"===n.modifier,o="*"===n.modifier||"+"===n.modifier;if(Array.isArray(a)){if(!o)throw new TypeError('Expected "'+n.name+'" to not repeat, but got an array');if(0===a.length){if(i)continue;throw new TypeError('Expected "'+n.name+'" to not be empty')}for(var f=0;f<a.length;f++){var p=l(a[f],n);if(d&&!h[t].test(p))throw new TypeError('Expected all "'+n.name+'" to match "'+n.pattern+'", but got "'+p+'"');r+=n.prefix+p+n.suffix}}else if("string"!=typeof a&&"number"!=typeof a){if(!i){var s=o?"an array":"a string";throw new TypeError('Expected "'+n.name+'" to be '+s)}}else{p=l(String(a),n);if(d&&!h[t].test(p))throw new TypeError('Expected "'+n.name+'" to match "'+n.pattern+'", but got "'+p+'"');r+=n.prefix+p+n.suffix}}else r+=n}return r}}(f,x),s=Object.create(null),u=0;u<f.length;u++){var l=f[u];"string"!=typeof l&&(s[l.name]=!0)}n={toPath:p,keys:s},g.set(t,n)}var d=m.baseUrl+n.toPath(r)||"/";if(x.stringifyQueryParams&&r){for(var h={},v=Object.keys(r),c=0;c<v.length;c++){var y=v[c];n.keys[y]||(h[y]=r[y])}var E=x.stringifyQueryParams(h);E&&(d+="?"===E.charAt(0)?E:"?"+E)}return d}}}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).generateUrls=r()}(this,function(){"use strict";function b(e,r){void 0===r&&(r={});for(var n=function(e){for(var r=[],t=0;t<e.length;){var n=e[t];if("*"!==n&&"+"!==n&&"?"!==n)if("\\"!==n)if("{"!==n)if("}"!==n)if(":"!==n)if("("!==n)r.push({type:"CHAR",index:t,value:e[t++]});else{var i=1,a="";if("?"===e[f=t+1])throw new TypeError('Pattern cannot start with "?" at '+f);for(;f<e.length;)if("\\"!==e[f]){if(")"===e[f]){if(0===--i){f++;break}}else if("("===e[f]&&(i++,"?"!==e[f+1]))throw new TypeError("Capturing groups are not allowed at "+f);a+=e[f++]}else a+=e[f++]+e[f++];if(i)throw new TypeError("Unbalanced pattern at "+t);if(!a)throw new TypeError("Missing pattern at "+t);r.push({type:"PATTERN",index:t,value:a}),t=f}else{for(var o="",f=t+1;f<e.length;){var p=e.charCodeAt(f);if(!(48<=p&&p<=57||65<=p&&p<=90||97<=p&&p<=122||95===p))break;o+=e[f++]}if(!o)throw new TypeError("Missing parameter name at "+t);r.push({type:"NAME",index:t,value:o}),t=f}else r.push({type:"CLOSE",index:t,value:e[t++]});else r.push({type:"OPEN",index:t,value:e[t++]});else r.push({type:"ESCAPED_CHAR",index:t++,value:e[t++]});else r.push({type:"MODIFIER",index:t,value:e[t++]})}return r.push({type:"END",index:t,value:""}),r}(e),e=r.prefixes,t=void 0===e?"./":e,i="[^"+(r.delimiter||"/#?").replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")+"]+?",a=[],o=0,f=0,p="",u=function(e){if(f<n.length&&n[f].type===e)return n[f++].value},s=function(e){var r=u(e);if(void 0!==r)return r;var t=n[f],r=t.type,t=t.index;throw new TypeError("Unexpected "+r+" at "+t+", expected "+e)},l=function(){for(var e,r="";e=u("CHAR")||u("ESCAPED_CHAR");)r+=e;return r};f<n.length;){var d,h=u("CHAR"),y=u("NAME"),c=u("PATTERN");y||c?(-1===t.indexOf(d=h||"")&&(p+=d,d=""),p&&(a.push(p),p=""),a.push({name:y||o++,prefix:d,suffix:"",pattern:c||i,modifier:u("MODIFIER")||""})):(y=h||u("ESCAPED_CHAR"))?p+=y:(p&&(a.push(p),p=""),u("OPEN")?(d=l(),c=u("NAME")||"",h=u("PATTERN")||"",y=l(),s("CLOSE"),a.push({name:c||(h?o++:""),pattern:c&&!h?i:h,prefix:d,suffix:y,modifier:u("MODIFIER")||""})):s("END"))}return a}return function(x,e){if(!x)throw new ReferenceError("Router is not defined");var A=new Map,R=new Map,T=Object.assign({encode:encodeURIComponent},e);return function(e,r){var t=A.get(e);if(!(t||(A.clear(),R.clear(),function e(r,t,n,i,a){if(t.name&&i&&r.has(i))throw new Error('Route "'+i+'" already exists');if(t.name&&i&&r.set(i,t),n)for(var o=0;o<n.length;o++){var f=n[o],p=f.name;f.parent=t,e(r,f,f.children,i&&a?p?i+a+p:i:p,a)}}(A,x.root,x.root.children,x.root.name,T.uniqueRouteNameSep),t=A.get(e))))throw new Error('Route "'+e+'" not found');var u,n,s,l,d,i=R.get(t);if(!i){for(var a="",o=t;o;){var f=Array.isArray(o.path)?o.path[0]:o.path;f&&(a=f+a),o=o.parent}for(var p=b(a,T),h=(u=p,n=(e=h=void 0===(h=T)?{}:h)&&e.sensitive?"":"i",e=h.encode,s=void 0===e?function(e){return e}:e,l=void 0===(h=h.validate)||h,d=u.map(function(e){if("object"==typeof e)return new RegExp("^(?:"+e.pattern+")$",n)}),function(e){for(var r="",t=0;t<u.length;t++){var n=u[t];if("string"!=typeof n){var i=e?e[n.name]:void 0,a="?"===n.modifier||"*"===n.modifier,o="*"===n.modifier||"+"===n.modifier;if(Array.isArray(i)){if(!o)throw new TypeError('Expected "'+n.name+'" to not repeat, but got an array');if(0===i.length){if(a)continue;throw new TypeError('Expected "'+n.name+'" to not be empty')}for(var f=0;f<i.length;f++){var p=s(i[f],n);if(l&&!d[t].test(p))throw new TypeError('Expected all "'+n.name+'" to match "'+n.pattern+'", but got "'+p+'"');r+=n.prefix+p+n.suffix}}else if("string"!=typeof i&&"number"!=typeof i){if(!a)throw new TypeError('Expected "'+n.name+'" to be '+(o?"an array":"a string"))}else{p=s(String(i),n);if(l&&!d[t].test(p))throw new TypeError('Expected "'+n.name+'" to match "'+n.pattern+'", but got "'+p+'"');r+=n.prefix+p+n.suffix}}else r+=n}return r}),y=Object.create(null),c=0;c<p.length;c++){var v=p[c];"string"!=typeof v&&(y[v.name]=!0)}R.set(t,i={toPath:h,keys:y})}t=x.baseUrl+i.toPath(r)||"/";if(T.stringifyQueryParams&&r){for(var E={},g=Object.keys(r),m=0;m<g.length;m++){var w=g[m];i.keys[w]||(E[w]=r[w])}h=T.stringifyQueryParams(E);h&&(t+="?"===h.charAt(0)?h:"?"+h)}return t}}}); | ||
//# sourceMappingURL=universal-router-generate-urls.min.js.map |
@@ -6,3 +6,3 @@ /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.UniversalRouterSync = factory()); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.UniversalRouterSync = factory()); | ||
}(this, (function () { 'use strict'; | ||
@@ -295,14 +295,15 @@ | ||
if (!keys) return path; | ||
var groups = path.source.match(/\((?!\?)/g); | ||
var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g; | ||
var index = 0; | ||
var execResult = groupsRegex.exec(path.source); | ||
if (groups) { | ||
for (var i = 0; i < groups.length; i++) { | ||
keys.push({ | ||
name: i, | ||
prefix: "", | ||
suffix: "", | ||
modifier: "", | ||
pattern: "" | ||
}); | ||
} | ||
while (execResult) { | ||
keys.push({ | ||
name: execResult[1] || index++, | ||
prefix: "", | ||
suffix: "", | ||
modifier: "", | ||
pattern: "" | ||
}); | ||
execResult = groupsRegex.exec(path.source); | ||
} | ||
@@ -432,3 +433,3 @@ | ||
matchResult.path = !end && path.charAt(path.length - 1) === '/' ? path.substr(1) : path; | ||
matchResult.params = Object.assign({}, parentParams, {}, matchResult.params); | ||
matchResult.params = Object.assign({}, parentParams, matchResult.params); | ||
return { | ||
@@ -521,3 +522,3 @@ done: false, | ||
router: this | ||
}, this.options.context, {}, typeof pathnameOrContext === 'string' ? { | ||
}, this.options.context, typeof pathnameOrContext === 'string' ? { | ||
pathname: pathnameOrContext | ||
@@ -553,3 +554,3 @@ } : pathnameOrContext); | ||
currentContext = Object.assign({}, context, {}, matches.value); | ||
currentContext = Object.assign({}, context, matches.value); | ||
var result = resolve(currentContext, matches.value.params); | ||
@@ -556,0 +557,0 @@ |
/*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e=e||self).UniversalRouterSync=r()}(this,function(){"use strict";function n(e,r){void 0===r&&(r={});for(var o=function(e){for(var r=[],t=0;t<e.length;){var n=e[t];if("*"!==n&&"+"!==n&&"?"!==n)if("\\"!==n)if("{"!==n)if("}"!==n)if(":"!==n)if("("!==n)r.push({type:"CHAR",index:t,value:e[t++]});else{var i=1,o="";if("?"===e[u=t+1])throw new TypeError('Pattern cannot start with "?" at '+u);for(;u<e.length;)if("\\"!==e[u]){if(")"===e[u]){if(0===--i){u++;break}}else if("("===e[u]&&(i++,"?"!==e[u+1]))throw new TypeError("Capturing groups are not allowed at "+u);o+=e[u++]}else o+=e[u++]+e[u++];if(i)throw new TypeError("Unbalanced pattern at "+t);if(!o)throw new TypeError("Missing pattern at "+t);r.push({type:"PATTERN",index:t,value:o}),t=u}else{for(var a="",u=t+1;u<e.length;){var f=e.charCodeAt(u);if(!(48<=f&&f<=57||65<=f&&f<=90||97<=f&&f<=122||95===f))break;a+=e[u++]}if(!a)throw new TypeError("Missing parameter name at "+t);r.push({type:"NAME",index:t,value:a}),t=u}else r.push({type:"CLOSE",index:t,value:e[t++]});else r.push({type:"OPEN",index:t,value:e[t++]});else r.push({type:"ESCAPED_CHAR",index:t++,value:e[t++]});else r.push({type:"MODIFIER",index:t,value:e[t++]})}return r.push({type:"END",index:t,value:""}),r}(e),t=r.prefixes,n=void 0===t?"./":t,i="[^"+A(r.delimiter||"/#?")+"]+?",a=[],u=0,f=0,s="",p=function(e){if(f<o.length&&o[f].type===e)return o[f++].value},l=function(e){var r=p(e);if(void 0!==r)return r;var t=o[f],n=t.type,i=t.index;throw new TypeError("Unexpected "+n+" at "+i+", expected "+e)},d=function(){for(var e,r="";e=p("CHAR")||p("ESCAPED_CHAR");)r+=e;return r};f<o.length;){var h=p("CHAR"),c=p("NAME"),v=p("PATTERN");if(c||v){var m=h||"";-1===n.indexOf(m)&&(s+=m,m=""),s&&(a.push(s),s=""),a.push({name:c||u++,prefix:m,suffix:"",pattern:v||i,modifier:p("MODIFIER")||""})}else{var x=h||p("ESCAPED_CHAR");if(x)s+=x;else if(s&&(a.push(s),s=""),p("OPEN")){m=d();var y=p("NAME")||"",E=p("PATTERN")||"",g=d();l("CLOSE"),a.push({name:y||(E?u++:""),pattern:y&&!E?i:E,prefix:m,suffix:g,modifier:p("MODIFIER")||""})}else l("END")}}return a}function v(e,r){var t=[];return function(u,f,e){void 0===e&&(e={});var r=e.decode,s=void 0===r?function(e){return e}:r;return function(e){var t=u.exec(e);if(!t)return!1;for(var r=t[0],n=t.index,i=Object.create(null),o=function(e){if(void 0===t[e])return"continue";var r=f[e-1];"*"===r.modifier||"+"===r.modifier?i[r.name]=t[e].split(r.prefix+r.suffix).map(function(e){return s(e,r)}):i[r.name]=s(t[e],r)},a=1;a<t.length;a++)o(a);return{path:r,index:n,params:i}}}(u(e,t,r),t,r)}function A(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function b(e){return e&&e.sensitive?"":"i"}function a(e,r,t){return function(e,r,t){void 0===t&&(t={});for(var n=t.strict,i=void 0!==n&&n,o=t.start,a=void 0===o||o,u=t.end,f=void 0===u||u,s=t.encode,p=void 0===s?function(e){return e}:s,l="["+A(t.endsWith||"")+"]|$",d="["+A(t.delimiter||"/#?")+"]",h=a?"^":"",c=0,v=e;c<v.length;c++){var m=v[c];if("string"==typeof m)h+=A(p(m));else{var x=A(p(m.prefix)),y=A(p(m.suffix));if(m.pattern)if(r&&r.push(m),x||y)if("+"===m.modifier||"*"===m.modifier){var E="*"===m.modifier?"?":"";h+="(?:"+x+"((?:"+m.pattern+")(?:"+y+x+"(?:"+m.pattern+"))*)"+y+")"+E}else h+="(?:"+x+"("+m.pattern+")"+y+")"+m.modifier;else h+="("+m.pattern+")"+m.modifier;else h+="(?:"+x+y+")"+m.modifier}}if(f)i||(h+=d+"?"),h+=t.endsWith?"(?="+l+")":"$";else{var g=e[e.length-1],w="string"==typeof g?-1<d.indexOf(g[g.length-1]):void 0===g;i||(h+="(?:"+d+"(?="+l+"))?"),w||(h+="(?="+d+"|"+l+")")}return new RegExp(h,b(t))}(n(e,t),r,t)}function u(e,r,t){return e instanceof RegExp?function(e,r){if(!r)return e;var t=e.source.match(/\((?!\?)/g);if(t)for(var n=0;n<t.length;n++)r.push({name:n,prefix:"",suffix:"",modifier:"",pattern:""});return e}(e,r):Array.isArray(e)?(n=r,i=t,o=e.map(function(e){return u(e,n,i).source}),new RegExp("(?:"+o.join("|")+")",b(i))):a(e,r,t);var n,i,o}function t(r){try{return decodeURIComponent(r)}catch(e){return r}}function r(e,r){if("function"==typeof e.route.action)return e.route.action(e,r)}function e(e,r){if(!e||"object"!=typeof e)throw new TypeError("Invalid routes");this.options=Object.assign({decode:t},r),this.baseUrl=this.options.baseUrl||"",this.root=Array.isArray(e)?{path:"",children:e,parent:null}:e,this.root.parent=null}return e.prototype.resolve=function(e){var a,u,f=Object.assign({router:this},this.options.context,{},"string"==typeof e?{pathname:e}:e),s=function a(u,f,s,p,l){var d,h,c=0;return{next:function(e){if(u===e)return{done:!0,value:!1};if(!d){var r=u,t=!r.children;if(r.match||(r.match=v(r.path||"",Object.assign({end:t},s))),d=r.match(p)){var n=d.path;return d.path=t||"/"!==n.charAt(n.length-1)?n:n.substr(1),d.params=Object.assign({},l,{},d.params),{done:!1,value:{route:u,baseUrl:f,path:d.path,params:d.params}}}}if(d&&u.children)for(;c<u.children.length;){if(!h){var i=u.children[c];i.parent=u,h=a(i,f+d.path,s,p.substr(d.path.length),d.params)}var o=h.next(e);if(!o.done)return{done:!1,value:o.value};h=null,c++}return{done:!0,value:!1}}}}(this.root,this.baseUrl,this.options,f.pathname.substr(this.baseUrl.length)),p=this.options.resolveRoute||r,l=f;function d(e,r,t){void 0===r&&(r=!a.done&&a.value.route);var n=null===t&&!a.done&&a.value.route;if(a=u||s.next(n),u=null,!e&&(a.done||!function(e,r){for(var t=r;t;)if((t=t.parent)===e)return 1}(r,a.value.route)))return u=a,null;if(a.done){var i=new Error("Route not found");throw i.status=404,i}l=Object.assign({},f,{},a.value);var o=p(l,a.value.params);return null!=o?o:d(e,r,o)}f.next=d;try{return d(!0,this.root)}catch(e){if(this.options.errorHandler)return this.options.errorHandler(e,l);throw e}},e}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).UniversalRouterSync=r()}(this,function(){"use strict";function n(e,r){void 0===r&&(r={});for(var n=function(e){for(var r=[],t=0;t<e.length;){var n=e[t];if("*"!==n&&"+"!==n&&"?"!==n)if("\\"!==n)if("{"!==n)if("}"!==n)if(":"!==n)if("("!==n)r.push({type:"CHAR",index:t,value:e[t++]});else{var i=1,o="";if("?"===e[u=t+1])throw new TypeError('Pattern cannot start with "?" at '+u);for(;u<e.length;)if("\\"!==e[u]){if(")"===e[u]){if(0===--i){u++;break}}else if("("===e[u]&&(i++,"?"!==e[u+1]))throw new TypeError("Capturing groups are not allowed at "+u);o+=e[u++]}else o+=e[u++]+e[u++];if(i)throw new TypeError("Unbalanced pattern at "+t);if(!o)throw new TypeError("Missing pattern at "+t);r.push({type:"PATTERN",index:t,value:o}),t=u}else{for(var a="",u=t+1;u<e.length;){var f=e.charCodeAt(u);if(!(48<=f&&f<=57||65<=f&&f<=90||97<=f&&f<=122||95===f))break;a+=e[u++]}if(!a)throw new TypeError("Missing parameter name at "+t);r.push({type:"NAME",index:t,value:a}),t=u}else r.push({type:"CLOSE",index:t,value:e[t++]});else r.push({type:"OPEN",index:t,value:e[t++]});else r.push({type:"ESCAPED_CHAR",index:t++,value:e[t++]});else r.push({type:"MODIFIER",index:t,value:e[t++]})}return r.push({type:"END",index:t,value:""}),r}(e),e=r.prefixes,t=void 0===e?"./":e,i="[^"+x(r.delimiter||"/#?")+"]+?",o=[],a=0,u=0,f="",s=function(e){if(u<n.length&&n[u].type===e)return n[u++].value},p=function(e){var r=s(e);if(void 0!==r)return r;var t=n[u],r=t.type,t=t.index;throw new TypeError("Unexpected "+r+" at "+t+", expected "+e)},l=function(){for(var e,r="";e=s("CHAR")||s("ESCAPED_CHAR");)r+=e;return r};u<n.length;){var d,h=s("CHAR"),c=s("NAME"),v=s("PATTERN");c||v?(-1===t.indexOf(d=h||"")&&(f+=d,d=""),f&&(o.push(f),f=""),o.push({name:c||a++,prefix:d,suffix:"",pattern:v||i,modifier:s("MODIFIER")||""})):(c=h||s("ESCAPED_CHAR"))?f+=c:(f&&(o.push(f),f=""),s("OPEN")?(d=l(),v=s("NAME")||"",h=s("PATTERN")||"",c=l(),p("CLOSE"),o.push({name:v||(h?a++:""),pattern:v&&!h?i:h,prefix:d,suffix:c,modifier:s("MODIFIER")||""})):p("END"))}return o}function h(e,r){var t=[];return function(o,a,e){void 0===e&&(e={});var e=e.decode,u=void 0===e?function(e){return e}:e;return function(e){var t=o.exec(e);if(!t)return!1;for(var r=t[0],e=t.index,n=Object.create(null),i=1;i<t.length;i++)!function(e){if(void 0===t[e])return;var r=a[e-1];"*"===r.modifier||"+"===r.modifier?n[r.name]=t[e].split(r.prefix+r.suffix).map(function(e){return u(e,r)}):n[r.name]=u(t[e],r)}(i);return{path:r,index:e,params:n}}}(u(e,t,r),t,r)}function x(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function m(e){return e&&e.sensitive?"":"i"}function a(e,r,t){return function(e,r,t){void 0===t&&(t={});for(var n=t.strict,i=void 0!==n&&n,o=t.start,a=void 0===o||o,u=t.end,n=void 0===u||u,o=t.encode,f=void 0===o?function(e){return e}:o,u="["+x(t.endsWith||"")+"]|$",o="["+x(t.delimiter||"/#?")+"]",s=a?"^":"",p=0,l=e;p<l.length;p++){var d,h,c,v=l[p];"string"==typeof v?s+=x(f(v)):(d=x(f(v.prefix)),h=x(f(v.suffix)),v.pattern?(r&&r.push(v),d||h?"+"===v.modifier||"*"===v.modifier?(c="*"===v.modifier?"?":"",s+="(?:"+d+"((?:"+v.pattern+")(?:"+h+d+"(?:"+v.pattern+"))*)"+h+")"+c):s+="(?:"+d+"("+v.pattern+")"+h+")"+v.modifier:s+="("+v.pattern+")"+v.modifier):s+="(?:"+d+h+")"+v.modifier)}n?(i||(s+=o+"?"),s+=t.endsWith?"(?="+u+")":"$"):(e=e[e.length-1],e="string"==typeof e?-1<o.indexOf(e[e.length-1]):void 0===e,i||(s+="(?:"+o+"(?="+u+"))?"),e||(s+="(?="+o+"|"+u+")"));return new RegExp(s,m(t))}(n(e,t),r,t)}function u(e,r,t){return e instanceof RegExp?function(e,r){if(!r)return e;for(var t=/\((?:\?<(.*?)>)?(?!\?)/g,n=0,i=t.exec(e.source);i;)r.push({name:i[1]||n++,prefix:"",suffix:"",modifier:"",pattern:""}),i=t.exec(e.source);return e}(e,r):Array.isArray(e)?(n=e,i=r,o=t,n=e.map(function(e){return u(e,i,o).source}),new RegExp("(?:"+n.join("|")+")",m(o))):a(e,r,t);var n,i,o}function t(r){try{return decodeURIComponent(r)}catch(e){return r}}function r(e,r){if("function"==typeof e.route.action)return e.route.action(e,r)}function e(e,r){if(!e||"object"!=typeof e)throw new TypeError("Invalid routes");this.options=Object.assign({decode:t},r),this.baseUrl=this.options.baseUrl||"",this.root=Array.isArray(e)?{path:"",children:e,parent:null}:e,this.root.parent=null}return e.prototype.resolve=function(e){var i,o,a=Object.assign({router:this},this.options.context,"string"==typeof e?{pathname:e}:e),u=function i(o,a,u,f,s){var p,l,d=0;return{next:function(e){if(o===e)return{done:!0,value:!1};if(!p){var r=o,t=!r.children;if(r.match||(r.match=h(r.path||"",Object.assign({end:t},u))),p=r.match(f))return r=p.path,p.path=t||"/"!==r.charAt(r.length-1)?r:r.substr(1),p.params=Object.assign({},s,p.params),{done:!1,value:{route:o,baseUrl:a,path:p.path,params:p.params}}}if(p&&o.children)for(;d<o.children.length;){l||((n=o.children[d]).parent=o,l=i(n,a+p.path,u,f.substr(p.path.length),p.params));var n=l.next(e);if(!n.done)return{done:!1,value:n.value};l=null,d++}return{done:!0,value:!1}}}}(this.root,this.baseUrl,this.options,a.pathname.substr(this.baseUrl.length)),f=this.options.resolveRoute||r,s=a;function p(e,r,t){void 0===r&&(r=!i.done&&i.value.route);t=null===t&&!i.done&&i.value.route;if(i=o||u.next(t),o=null,!e&&(i.done||!function(e,r){for(var t=r;t;)if((t=t.parent)===e)return 1}(r,i.value.route)))return o=i,null;if(i.done){var n=new Error("Route not found");throw n.status=404,n}s=Object.assign({},a,i.value);n=f(s,i.value.params);return null!=n?n:p(e,r,n)}a.next=p;try{return p(!0,this.root)}catch(e){if(this.options.errorHandler)return this.options.errorHandler(e,s);throw e}},e}); | ||
//# sourceMappingURL=universal-router-sync.min.js.map |
@@ -6,3 +6,3 @@ /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.UniversalRouter = factory()); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.UniversalRouter = factory()); | ||
}(this, (function () { 'use strict'; | ||
@@ -295,14 +295,15 @@ | ||
if (!keys) return path; | ||
var groups = path.source.match(/\((?!\?)/g); | ||
var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g; | ||
var index = 0; | ||
var execResult = groupsRegex.exec(path.source); | ||
if (groups) { | ||
for (var i = 0; i < groups.length; i++) { | ||
keys.push({ | ||
name: i, | ||
prefix: "", | ||
suffix: "", | ||
modifier: "", | ||
pattern: "" | ||
}); | ||
} | ||
while (execResult) { | ||
keys.push({ | ||
name: execResult[1] || index++, | ||
prefix: "", | ||
suffix: "", | ||
modifier: "", | ||
pattern: "" | ||
}); | ||
execResult = groupsRegex.exec(path.source); | ||
} | ||
@@ -432,3 +433,3 @@ | ||
matchResult.path = !end && path.charAt(path.length - 1) === '/' ? path.substr(1) : path; | ||
matchResult.params = Object.assign({}, parentParams, {}, matchResult.params); | ||
matchResult.params = Object.assign({}, parentParams, matchResult.params); | ||
return { | ||
@@ -523,3 +524,3 @@ done: false, | ||
router: this | ||
}, this.options.context, {}, typeof pathnameOrContext === 'string' ? { | ||
}, this.options.context, typeof pathnameOrContext === 'string' ? { | ||
pathname: pathnameOrContext | ||
@@ -555,3 +556,3 @@ } : pathnameOrContext); | ||
currentContext = Object.assign({}, context, {}, matches.value); | ||
currentContext = Object.assign({}, context, matches.value); | ||
return Promise.resolve(resolve(currentContext, matches.value.params)).then(function (result) { | ||
@@ -558,0 +559,0 @@ if (result !== null && result !== undefined) { |
/*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e=e||self).UniversalRouter=r()}(this,function(){"use strict";function n(e,r){void 0===r&&(r={});for(var o=function(e){for(var r=[],t=0;t<e.length;){var n=e[t];if("*"!==n&&"+"!==n&&"?"!==n)if("\\"!==n)if("{"!==n)if("}"!==n)if(":"!==n)if("("!==n)r.push({type:"CHAR",index:t,value:e[t++]});else{var i=1,o="";if("?"===e[u=t+1])throw new TypeError('Pattern cannot start with "?" at '+u);for(;u<e.length;)if("\\"!==e[u]){if(")"===e[u]){if(0===--i){u++;break}}else if("("===e[u]&&(i++,"?"!==e[u+1]))throw new TypeError("Capturing groups are not allowed at "+u);o+=e[u++]}else o+=e[u++]+e[u++];if(i)throw new TypeError("Unbalanced pattern at "+t);if(!o)throw new TypeError("Missing pattern at "+t);r.push({type:"PATTERN",index:t,value:o}),t=u}else{for(var a="",u=t+1;u<e.length;){var f=e.charCodeAt(u);if(!(48<=f&&f<=57||65<=f&&f<=90||97<=f&&f<=122||95===f))break;a+=e[u++]}if(!a)throw new TypeError("Missing parameter name at "+t);r.push({type:"NAME",index:t,value:a}),t=u}else r.push({type:"CLOSE",index:t,value:e[t++]});else r.push({type:"OPEN",index:t,value:e[t++]});else r.push({type:"ESCAPED_CHAR",index:t++,value:e[t++]});else r.push({type:"MODIFIER",index:t,value:e[t++]})}return r.push({type:"END",index:t,value:""}),r}(e),t=r.prefixes,n=void 0===t?"./":t,i="[^"+w(r.delimiter||"/#?")+"]+?",a=[],u=0,f=0,s="",p=function(e){if(f<o.length&&o[f].type===e)return o[f++].value},l=function(e){var r=p(e);if(void 0!==r)return r;var t=o[f],n=t.type,i=t.index;throw new TypeError("Unexpected "+n+" at "+i+", expected "+e)},d=function(){for(var e,r="";e=p("CHAR")||p("ESCAPED_CHAR");)r+=e;return r};f<o.length;){var h=p("CHAR"),c=p("NAME"),v=p("PATTERN");if(c||v){var m=h||"";-1===n.indexOf(m)&&(s+=m,m=""),s&&(a.push(s),s=""),a.push({name:c||u++,prefix:m,suffix:"",pattern:v||i,modifier:p("MODIFIER")||""})}else{var x=h||p("ESCAPED_CHAR");if(x)s+=x;else if(s&&(a.push(s),s=""),p("OPEN")){m=d();var E=p("NAME")||"",g=p("PATTERN")||"",y=d();l("CLOSE"),a.push({name:E||(g?u++:""),pattern:E&&!g?i:g,prefix:m,suffix:y,modifier:p("MODIFIER")||""})}else l("END")}}return a}function v(e,r){var t=[];return function(u,f,e){void 0===e&&(e={});var r=e.decode,s=void 0===r?function(e){return e}:r;return function(e){var t=u.exec(e);if(!t)return!1;for(var r=t[0],n=t.index,i=Object.create(null),o=function(e){if(void 0===t[e])return"continue";var r=f[e-1];"*"===r.modifier||"+"===r.modifier?i[r.name]=t[e].split(r.prefix+r.suffix).map(function(e){return s(e,r)}):i[r.name]=s(t[e],r)},a=1;a<t.length;a++)o(a);return{path:r,index:n,params:i}}}(u(e,t,r),t,r)}function w(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function b(e){return e&&e.sensitive?"":"i"}function a(e,r,t){return function(e,r,t){void 0===t&&(t={});for(var n=t.strict,i=void 0!==n&&n,o=t.start,a=void 0===o||o,u=t.end,f=void 0===u||u,s=t.encode,p=void 0===s?function(e){return e}:s,l="["+w(t.endsWith||"")+"]|$",d="["+w(t.delimiter||"/#?")+"]",h=a?"^":"",c=0,v=e;c<v.length;c++){var m=v[c];if("string"==typeof m)h+=w(p(m));else{var x=w(p(m.prefix)),E=w(p(m.suffix));if(m.pattern)if(r&&r.push(m),x||E)if("+"===m.modifier||"*"===m.modifier){var g="*"===m.modifier?"?":"";h+="(?:"+x+"((?:"+m.pattern+")(?:"+E+x+"(?:"+m.pattern+"))*)"+E+")"+g}else h+="(?:"+x+"("+m.pattern+")"+E+")"+m.modifier;else h+="("+m.pattern+")"+m.modifier;else h+="(?:"+x+E+")"+m.modifier}}if(f)i||(h+=d+"?"),h+=t.endsWith?"(?="+l+")":"$";else{var y=e[e.length-1],A="string"==typeof y?-1<d.indexOf(y[y.length-1]):void 0===y;i||(h+="(?:"+d+"(?="+l+"))?"),A||(h+="(?="+d+"|"+l+")")}return new RegExp(h,b(t))}(n(e,t),r,t)}function u(e,r,t){return e instanceof RegExp?function(e,r){if(!r)return e;var t=e.source.match(/\((?!\?)/g);if(t)for(var n=0;n<t.length;n++)r.push({name:n,prefix:"",suffix:"",modifier:"",pattern:""});return e}(e,r):Array.isArray(e)?(n=r,i=t,o=e.map(function(e){return u(e,n,i).source}),new RegExp("(?:"+o.join("|")+")",b(i))):a(e,r,t);var n,i,o}function t(r){try{return decodeURIComponent(r)}catch(e){return r}}function i(e,r){if("function"==typeof e.route.action)return e.route.action(e,r)}function e(e,r){if(!e||"object"!=typeof e)throw new TypeError("Invalid routes");this.options=Object.assign({decode:t},r),this.baseUrl=this.options.baseUrl||"",this.root=Array.isArray(e)?{path:"",children:e,parent:null}:e,this.root.parent=null}return e.prototype.resolve=function(e){var o,a,r=this,u=Object.assign({router:this},this.options.context,{},"string"==typeof e?{pathname:e}:e),f=function a(u,f,s,p,l){var d,h,c=0;return{next:function(e){if(u===e)return{done:!0,value:!1};if(!d){var r=u,t=!r.children;if(r.match||(r.match=v(r.path||"",Object.assign({end:t},s))),d=r.match(p)){var n=d.path;return d.path=t||"/"!==n.charAt(n.length-1)?n:n.substr(1),d.params=Object.assign({},l,{},d.params),{done:!1,value:{route:u,baseUrl:f,path:d.path,params:d.params}}}}if(d&&u.children)for(;c<u.children.length;){if(!h){var i=u.children[c];i.parent=u,h=a(i,f+d.path,s,p.substr(d.path.length),d.params)}var o=h.next(e);if(!o.done)return{done:!1,value:o.value};h=null,c++}return{done:!0,value:!1}}}}(this.root,this.baseUrl,this.options,u.pathname.substr(this.baseUrl.length)),s=this.options.resolveRoute||i,p=u;function l(r,t,e){void 0===t&&(t=!o.done&&o.value.route);var n=null===e&&!o.done&&o.value.route;if(o=a||f.next(n),a=null,!r&&(o.done||!function(e,r){for(var t=r;t;)if((t=t.parent)===e)return 1}(t,o.value.route)))return a=o,Promise.resolve(null);if(o.done){var i=new Error("Route not found");return i.status=404,Promise.reject(i)}return p=Object.assign({},u,{},o.value),Promise.resolve(s(p,o.value.params)).then(function(e){return null!=e?e:l(r,t,e)})}return u.next=l,Promise.resolve().then(function(){return l(!0,r.root)}).catch(function(e){if(r.options.errorHandler)return r.options.errorHandler(e,p);throw e})},e}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).UniversalRouter=r()}(this,function(){"use strict";function n(e,r){void 0===r&&(r={});for(var n=function(e){for(var r=[],t=0;t<e.length;){var n=e[t];if("*"!==n&&"+"!==n&&"?"!==n)if("\\"!==n)if("{"!==n)if("}"!==n)if(":"!==n)if("("!==n)r.push({type:"CHAR",index:t,value:e[t++]});else{var i=1,o="";if("?"===e[u=t+1])throw new TypeError('Pattern cannot start with "?" at '+u);for(;u<e.length;)if("\\"!==e[u]){if(")"===e[u]){if(0===--i){u++;break}}else if("("===e[u]&&(i++,"?"!==e[u+1]))throw new TypeError("Capturing groups are not allowed at "+u);o+=e[u++]}else o+=e[u++]+e[u++];if(i)throw new TypeError("Unbalanced pattern at "+t);if(!o)throw new TypeError("Missing pattern at "+t);r.push({type:"PATTERN",index:t,value:o}),t=u}else{for(var a="",u=t+1;u<e.length;){var f=e.charCodeAt(u);if(!(48<=f&&f<=57||65<=f&&f<=90||97<=f&&f<=122||95===f))break;a+=e[u++]}if(!a)throw new TypeError("Missing parameter name at "+t);r.push({type:"NAME",index:t,value:a}),t=u}else r.push({type:"CLOSE",index:t,value:e[t++]});else r.push({type:"OPEN",index:t,value:e[t++]});else r.push({type:"ESCAPED_CHAR",index:t++,value:e[t++]});else r.push({type:"MODIFIER",index:t,value:e[t++]})}return r.push({type:"END",index:t,value:""}),r}(e),e=r.prefixes,t=void 0===e?"./":e,i="[^"+m(r.delimiter||"/#?")+"]+?",o=[],a=0,u=0,f="",s=function(e){if(u<n.length&&n[u].type===e)return n[u++].value},p=function(e){var r=s(e);if(void 0!==r)return r;var t=n[u],r=t.type,t=t.index;throw new TypeError("Unexpected "+r+" at "+t+", expected "+e)},l=function(){for(var e,r="";e=s("CHAR")||s("ESCAPED_CHAR");)r+=e;return r};u<n.length;){var d,c=s("CHAR"),h=s("NAME"),v=s("PATTERN");h||v?(-1===t.indexOf(d=c||"")&&(f+=d,d=""),f&&(o.push(f),f=""),o.push({name:h||a++,prefix:d,suffix:"",pattern:v||i,modifier:s("MODIFIER")||""})):(h=c||s("ESCAPED_CHAR"))?f+=h:(f&&(o.push(f),f=""),s("OPEN")?(d=l(),v=s("NAME")||"",c=s("PATTERN")||"",h=l(),p("CLOSE"),o.push({name:v||(c?a++:""),pattern:v&&!c?i:c,prefix:d,suffix:h,modifier:s("MODIFIER")||""})):p("END"))}return o}function c(e,r){var t=[];return function(o,a,e){void 0===e&&(e={});var e=e.decode,u=void 0===e?function(e){return e}:e;return function(e){var t=o.exec(e);if(!t)return!1;for(var r=t[0],e=t.index,n=Object.create(null),i=1;i<t.length;i++)!function(e){if(void 0===t[e])return;var r=a[e-1];"*"===r.modifier||"+"===r.modifier?n[r.name]=t[e].split(r.prefix+r.suffix).map(function(e){return u(e,r)}):n[r.name]=u(t[e],r)}(i);return{path:r,index:e,params:n}}}(u(e,t,r),t,r)}function m(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function x(e){return e&&e.sensitive?"":"i"}function a(e,r,t){return function(e,r,t){void 0===t&&(t={});for(var n=t.strict,i=void 0!==n&&n,o=t.start,a=void 0===o||o,u=t.end,n=void 0===u||u,o=t.encode,f=void 0===o?function(e){return e}:o,u="["+m(t.endsWith||"")+"]|$",o="["+m(t.delimiter||"/#?")+"]",s=a?"^":"",p=0,l=e;p<l.length;p++){var d,c,h,v=l[p];"string"==typeof v?s+=m(f(v)):(d=m(f(v.prefix)),c=m(f(v.suffix)),v.pattern?(r&&r.push(v),d||c?"+"===v.modifier||"*"===v.modifier?(h="*"===v.modifier?"?":"",s+="(?:"+d+"((?:"+v.pattern+")(?:"+c+d+"(?:"+v.pattern+"))*)"+c+")"+h):s+="(?:"+d+"("+v.pattern+")"+c+")"+v.modifier:s+="("+v.pattern+")"+v.modifier):s+="(?:"+d+c+")"+v.modifier)}n?(i||(s+=o+"?"),s+=t.endsWith?"(?="+u+")":"$"):(e=e[e.length-1],e="string"==typeof e?-1<o.indexOf(e[e.length-1]):void 0===e,i||(s+="(?:"+o+"(?="+u+"))?"),e||(s+="(?="+o+"|"+u+")"));return new RegExp(s,x(t))}(n(e,t),r,t)}function u(e,r,t){return e instanceof RegExp?function(e,r){if(!r)return e;for(var t=/\((?:\?<(.*?)>)?(?!\?)/g,n=0,i=t.exec(e.source);i;)r.push({name:i[1]||n++,prefix:"",suffix:"",modifier:"",pattern:""}),i=t.exec(e.source);return e}(e,r):Array.isArray(e)?(n=e,i=r,o=t,n=e.map(function(e){return u(e,i,o).source}),new RegExp("(?:"+n.join("|")+")",x(o))):a(e,r,t);var n,i,o}function t(r){try{return decodeURIComponent(r)}catch(e){return r}}function p(e,r){if("function"==typeof e.route.action)return e.route.action(e,r)}function e(e,r){if(!e||"object"!=typeof e)throw new TypeError("Invalid routes");this.options=Object.assign({decode:t},r),this.baseUrl=this.options.baseUrl||"",this.root=Array.isArray(e)?{path:"",children:e,parent:null}:e,this.root.parent=null}return e.prototype.resolve=function(e){var n,i,r=this,o=Object.assign({router:this},this.options.context,"string"==typeof e?{pathname:e}:e),a=function i(o,a,u,f,s){var p,l,d=0;return{next:function(e){if(o===e)return{done:!0,value:!1};if(!p){var r=o,t=!r.children;if(r.match||(r.match=c(r.path||"",Object.assign({end:t},u))),p=r.match(f))return r=p.path,p.path=t||"/"!==r.charAt(r.length-1)?r:r.substr(1),p.params=Object.assign({},s,p.params),{done:!1,value:{route:o,baseUrl:a,path:p.path,params:p.params}}}if(p&&o.children)for(;d<o.children.length;){l||((n=o.children[d]).parent=o,l=i(n,a+p.path,u,f.substr(p.path.length),p.params));var n=l.next(e);if(!n.done)return{done:!1,value:n.value};l=null,d++}return{done:!0,value:!1}}}}(this.root,this.baseUrl,this.options,o.pathname.substr(this.baseUrl.length)),u=this.options.resolveRoute||p,f=o;function s(r,t,e){void 0===t&&(t=!n.done&&n.value.route);e=null===e&&!n.done&&n.value.route;if(n=i||a.next(e),i=null,!r&&(n.done||!function(e,r){for(var t=r;t;)if((t=t.parent)===e)return 1}(t,n.value.route)))return i=n,Promise.resolve(null);if(n.done){e=new Error("Route not found");return e.status=404,Promise.reject(e)}return f=Object.assign({},o,n.value),Promise.resolve(u(f,n.value.params)).then(function(e){return null!=e?e:s(r,t,e)})}return o.next=s,Promise.resolve().then(function(){return s(!0,r.root)}).catch(function(e){if(r.options.errorHandler)return r.options.errorHandler(e,f);throw e})},e}); | ||
//# 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
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
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
383443
3559
Updatedpath-to-regexp@^6.2.0