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 8.1.0 to 8.2.0

2

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

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

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

return next(true, _this.root);
}).catch(function (error) {
})["catch"](function (error) {
if (_this.errorHandler) {

@@ -220,0 +220,0 @@ return _this.errorHandler(error, currentContext);

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

return next(true, _this.root);
}).catch(function (error) {
})["catch"](function (error) {
if (_this.errorHandler) {

@@ -218,0 +218,0 @@ return _this.errorHandler(error, currentContext);

{
"name": "universal-router",
"version": "8.1.0",
"version": "8.2.0",
"description": "Isomorphic router for JavaScript web applications",

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

@@ -11,4 +11,8 @@ /**

import { PathFunctionOptions } from 'path-to-regexp'
import UniversalRouter, { Params } from './UniversalRouter'
import UniversalRouter from './UniversalRouter'
export interface Params {
[paramName: string]: any
}
export interface GenerateUrlsOptions extends PathFunctionOptions {

@@ -15,0 +19,0 @@ stringifyQueryParams?: (params: Params) => string

@@ -12,4 +12,4 @@ /**

export interface Params {
[paramName: string]: any
export interface QueryParams {
[paramName: string]: string | string[]
}

@@ -27,6 +27,6 @@

router: UniversalRouter<C, R>
route: Route
route: Route<C, R>
baseUrl: string
path: string
params: Params
params: QueryParams
keys: pathToRegexp.Key[]

@@ -36,8 +36,10 @@ next: (resume?: boolean) => Promise<R>

export type Result<T> = T | Promise<T | void> | void
export interface Route<C extends Context = any, R = any> {
path?: string | RegExp | Array<string | RegExp>
name?: string
parent?: Route | null
parent?: Route<C, R> | null
children?: Routes<C, R> | null
action?: (context: RouteContext<C, R> & C, params: Params) => R | Promise<R> | void
action?: (context: RouteContext<C, R> & C, params: QueryParams) => Result<R>
}

@@ -47,7 +49,17 @@

export type ResolveRoute<C extends Context = Context, R = any> = (
context: C & RouteContext<C, R>,
params: QueryParams,
) => Result<R>
export type ErrorHandler<C extends Context = Context, R = any> = (
error: Error & { status?: number },
context: C & RouteContext<C, R>,
) => Result<R>
export interface Options<C extends Context = Context, R = any> {
context?: C
baseUrl?: string
resolveRoute?: (context: C & RouteContext<C, R>, params: Params) => any
errorHandler?: (error: Error & { status?: number }, context: C & RouteContext<C, R>) => any
resolveRoute?: ResolveRoute<C, R>
errorHandler?: ErrorHandler<C, R>
}

@@ -57,4 +69,10 @@

static pathToRegexp: typeof pathToRegexp
constructor(routes: Route<C, R> | Routes<C, R>, options?: Options<C>)
baseUrl: string
errorHandler?: ErrorHandler<C, R>
resolveRoute: ResolveRoute<C, R>
context: C & { router: UniversalRouter<C, R> }
root: Route<C, R>
routesByName?: Map<string, Route<C, R>>
constructor(routes: Route<C, R> | Routes<C, R>, options?: Options<C, R>)
resolve(pathnameOrContext: string | ResolveContext): Promise<R>
}

@@ -12,4 +12,4 @@ /**

export interface Params {
[paramName: string]: any
export interface QueryParams {
[paramName: string]: string | string[]
}

@@ -27,6 +27,6 @@

router: UniversalRouter<C, R>
route: Route
route: Route<C, R>
baseUrl: string
path: string
params: Params
params: QueryParams
keys: pathToRegexp.Key[]

@@ -36,8 +36,10 @@ next: (resume?: boolean) => R

export type Result<T> = T | void
export interface Route<C extends Context = any, R = any> {
path?: string | RegExp | Array<string | RegExp>
name?: string
parent?: Route | null
parent?: Route<C, R> | null
children?: Routes<C, R> | null
action?: (context: RouteContext<C, R> & C, params: Params) => R | void
action?: (context: RouteContext<C, R> & C, params: QueryParams) => Result<R>
}

@@ -47,7 +49,17 @@

export type ResolveRoute<C extends Context = Context, R = any> = (
context: C & RouteContext<C, R>,
params: QueryParams,
) => Result<R>
export type ErrorHandler<C extends Context = Context, R = any> = (
error: Error & { status?: number },
context: C & RouteContext<C, R>,
) => Result<R>
export interface Options<C extends Context = Context, R = any> {
context?: C
baseUrl?: string
resolveRoute?: (context: C & RouteContext<C, R>, params: Params) => any
errorHandler?: (error: Error & { status?: number }, context: C & RouteContext<C, R>) => any
resolveRoute?: ResolveRoute<C, R>
errorHandler?: ErrorHandler<C, R>
}

@@ -57,4 +69,10 @@

static pathToRegexp: typeof pathToRegexp
constructor(routes: Route<C, R> | Routes<C, R>, options?: Options<C>)
baseUrl: string
errorHandler?: ErrorHandler<C, R>
resolveRoute: ResolveRoute<C, R>
context: C & { router: UniversalRouter<C, R> }
root: Route<C, R>
routesByName?: Map<string, Route<C, R>>
constructor(routes: Route<C, R> | Routes<C, R>, options?: Options<C, R>)
resolve(pathnameOrContext: string | ResolveContext): R
}
{
"private": true,
"name": "sync",
"version": "8.1.0",
"version": "8.2.0",
"description": "Universal Router Sync Add-on",

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

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

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

return next(true, _this.root);
}).catch(function (error) {
})["catch"](function (error) {
if (_this.errorHandler) {

@@ -472,0 +472,0 @@ return _this.errorHandler(error, currentContext);

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

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