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 3.2.0 to 4.0.0

src/generateUrls.js

69

browser.js

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

function matchPath(routePath, urlPath, end, parentParams) {
var key = routePath + '|' + end;
function parseParam(key, value) {
if (key.repeat) {
return value ? value.split(key.delimiter).map(decodeParam) : [];
}
return value ? decodeParam(value) : value;
}
function matchPath(route, path, parentKeys, parentParams) {
var key = (route.path || '') + '|' + !route.children;
var regexp = cache.get(key);

@@ -35,7 +42,10 @@

var keys = [];
regexp = { pattern: pathToRegexp(routePath, keys, { end: end }), keys: keys };
regexp = {
keys: keys,
pattern: pathToRegexp(route.path || '', keys, { end: !route.children })
};
cache.set(key, regexp);
}
var m = regexp.pattern.exec(urlPath);
var m = regexp.pattern.exec(path);
if (!m) {

@@ -45,14 +55,13 @@ return null;

var path = m[0];
var params = Object.create(null);
var params = Object.assign({}, parentParams);
if (parentParams) {
Object.assign(params, parentParams);
}
for (var i = 1; i < m.length; i += 1) {
params[regexp.keys[i - 1].name] = m[i] && decodeParam(m[i]);
params[regexp.keys[i - 1].name] = parseParam(regexp.keys[i - 1], m[i]);
}
return { path: path === '' ? '/' : path, keys: regexp.keys.slice(), params: params };
return {
path: m[0],
keys: regexp.keys.concat(parentKeys),
params: params
};
}

@@ -69,3 +78,3 @@

function matchRoute(route, baseUrl, path, parentParams) {
function matchRoute(route, baseUrl, path, parentKeys, parentParams) {
var match = void 0;

@@ -78,3 +87,3 @@ var childMatches = void 0;

if (!match) {
match = matchPath(route.path, path, !route.children, parentParams);
match = matchPath(route, path, parentKeys, parentParams);

@@ -98,7 +107,6 @@ if (match) {

if (!childMatches) {
var newPath = path.substr(match.path.length);
var childRoute = route.children[childIndex];
childRoute.parent = route;
childMatches = matchRoute(childRoute, baseUrl + (match.path === '/' ? '' : match.path), newPath.charAt(0) === '/' ? newPath : '/' + newPath, match.params);
childMatches = matchRoute(childRoute, baseUrl + match.path, path.substr(match.path.length), match.keys, match.params);
}

@@ -165,7 +173,7 @@

var Router = function () {
function Router(routes) {
var UniversalRouter = function () {
function UniversalRouter(routes) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Router);
_classCallCheck(this, UniversalRouter);

@@ -179,11 +187,11 @@ if (Object(routes) !== routes) {

this.context = Object.assign({ router: this }, options.context);
this.root = Array.isArray(routes) ? { path: '/', children: routes, parent: null } : routes;
this.root = Array.isArray(routes) ? { path: '', children: routes, parent: null } : routes;
this.root.parent = null;
}
_createClass(Router, [{
_createClass(UniversalRouter, [{
key: 'resolve',
value: function resolve(pathOrContext) {
var context = Object.assign({}, this.context, typeof pathOrContext === 'string' ? { path: pathOrContext } : pathOrContext);
var match = matchRoute(this.root, this.baseUrl, context.path.substr(this.baseUrl.length));
value: function resolve(pathnameOrContext) {
var context = Object.assign({}, this.context, typeof pathnameOrContext === 'string' ? { pathname: pathnameOrContext } : pathnameOrContext);
var match = matchRoute(this.root, this.baseUrl, context.pathname.substr(this.baseUrl.length), [], null);
var resolve = this.resolveRoute;

@@ -219,3 +227,2 @@ var matches = null;

context.url = context.path;
context.next = next;

@@ -227,11 +234,11 @@

return Router;
return UniversalRouter;
}();
Router.pathToRegexp = pathToRegexp;
Router.matchPath = matchPath;
Router.matchRoute = matchRoute;
Router.resolveRoute = resolveRoute;
UniversalRouter.pathToRegexp = pathToRegexp;
UniversalRouter.matchPath = matchPath;
UniversalRouter.matchRoute = matchRoute;
UniversalRouter.resolveRoute = resolveRoute;
module.exports = Router;
module.exports = UniversalRouter;
//# sourceMappingURL=browser.js.map

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

var Router = _interopDefault(require('..'));
var UniversalRouter = _interopDefault(require('..'));

@@ -21,2 +21,4 @@ /**

var pathToRegexp = UniversalRouter.pathToRegexp;
var cache = new Map();

@@ -45,4 +47,4 @@

if (!(router instanceof Router)) {
throw new TypeError('An instance of Router is expected');
if (!(router instanceof UniversalRouter)) {
throw new TypeError('An instance of UniversalRouter is expected');
}

@@ -69,3 +71,3 @@

while (rt) {
if (rt.path !== '/') {
if (rt.path) {
fullPath = rt.path + fullPath;

@@ -75,4 +77,4 @@ }

}
var tokens = Router.pathToRegexp.parse(fullPath);
var toPath = Router.pathToRegexp.tokensToFunction(tokens);
var tokens = pathToRegexp.parse(fullPath);
var toPath = pathToRegexp.tokensToFunction(tokens);
var keys = Object.create(null);

@@ -92,3 +94,3 @@ for (var i = 0; i < tokens.length; i += 1) {

if (options.stringifyQueryParams && params) {
var queryParams = Object.create(null);
var queryParams = {};
var _keys = Object.keys(params);

@@ -111,5 +113,5 @@ for (var _i = 0; _i < _keys.length; _i += 1) {

Router.generateUrls = generateUrls;
UniversalRouter.generateUrls = generateUrls;
module.exports = generateUrls;
//# sourceMappingURL=browser.js.map

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

var Router = _interopDefault(require('..'));
var UniversalRouter = _interopDefault(require('..'));

@@ -21,2 +21,4 @@ /**

var pathToRegexp = UniversalRouter.pathToRegexp;
var cache = new Map();

@@ -45,4 +47,4 @@

if (!(router instanceof Router)) {
throw new TypeError('An instance of Router is expected');
if (!(router instanceof UniversalRouter)) {
throw new TypeError('An instance of UniversalRouter is expected');
}

@@ -69,3 +71,3 @@

while (rt) {
if (rt.path !== '/') {
if (rt.path) {
fullPath = rt.path + fullPath;

@@ -75,4 +77,4 @@ }

}
var tokens = Router.pathToRegexp.parse(fullPath);
var toPath = Router.pathToRegexp.tokensToFunction(tokens);
var tokens = pathToRegexp.parse(fullPath);
var toPath = pathToRegexp.tokensToFunction(tokens);
var keys = Object.create(null);

@@ -92,3 +94,3 @@ for (var i = 0; i < tokens.length; i += 1) {

if (options.stringifyQueryParams && params) {
var queryParams = Object.create(null);
var queryParams = {};
var _keys = Object.keys(params);

@@ -111,5 +113,5 @@ for (var _i = 0; _i < _keys.length; _i += 1) {

Router.generateUrls = generateUrls;
UniversalRouter.generateUrls = generateUrls;
module.exports = generateUrls;
//# sourceMappingURL=legacy.js.map

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

var Router = _interopDefault(require('..'));
var UniversalRouter = _interopDefault(require('..'));

@@ -21,2 +21,3 @@ /**

const { pathToRegexp } = UniversalRouter;
const cache = new Map();

@@ -43,4 +44,4 @@

function generateUrls(router, options = {}) {
if (!(router instanceof Router)) {
throw new TypeError('An instance of Router is expected');
if (!(router instanceof UniversalRouter)) {
throw new TypeError('An instance of UniversalRouter is expected');
}

@@ -67,3 +68,3 @@

while (rt) {
if (rt.path !== '/') {
if (rt.path) {
fullPath = rt.path + fullPath;

@@ -73,4 +74,4 @@ }

}
const tokens = Router.pathToRegexp.parse(fullPath);
const toPath = Router.pathToRegexp.tokensToFunction(tokens);
const tokens = pathToRegexp.parse(fullPath);
const toPath = pathToRegexp.tokensToFunction(tokens);
const keys = Object.create(null);

@@ -90,3 +91,3 @@ for (let i = 0; i < tokens.length; i += 1) {

if (options.stringifyQueryParams && params) {
const queryParams = Object.create(null);
const queryParams = {};
const keys = Object.keys(params);

@@ -109,5 +110,5 @@ for (let i = 0; i < keys.length; i += 1) {

Router.generateUrls = generateUrls;
UniversalRouter.generateUrls = generateUrls;
module.exports = generateUrls;
//# sourceMappingURL=main.js.map
{
"private": true,
"name": "generateUrls",
"version": "3.2.0",
"version": "4.0.0",
"description": "Universal Router Generate URLs Add-on",

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

"main": "main.js",
"jsnext:main": "main.mjs",
"browser": "browser.js",
"jsnext:browser": "browser.mjs",
"private": true
}
"module": "main.mjs",
"browser": {
"main.js": "./browser.js",
"main.mjs": "./browser.mjs"
},
"esnext": "../src/generateUrls.js"
}

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

function matchPath(routePath, urlPath, end, parentParams) {
var key = routePath + '|' + end;
function parseParam(key, value) {
if (key.repeat) {
return value ? value.split(key.delimiter).map(decodeParam) : [];
}
return value ? decodeParam(value) : value;
}
function matchPath(route, path, parentKeys, parentParams) {
var key = (route.path || '') + '|' + !route.children;
var regexp = cache.get(key);

@@ -35,7 +42,10 @@

var keys = [];
regexp = { pattern: pathToRegexp(routePath, keys, { end: end }), keys: keys };
regexp = {
keys: keys,
pattern: pathToRegexp(route.path || '', keys, { end: !route.children })
};
cache.set(key, regexp);
}
var m = regexp.pattern.exec(urlPath);
var m = regexp.pattern.exec(path);
if (!m) {

@@ -45,14 +55,13 @@ return null;

var path = m[0];
var params = Object.create(null);
var params = Object.assign({}, parentParams);
if (parentParams) {
Object.assign(params, parentParams);
}
for (var i = 1; i < m.length; i += 1) {
params[regexp.keys[i - 1].name] = m[i] && decodeParam(m[i]);
params[regexp.keys[i - 1].name] = parseParam(regexp.keys[i - 1], m[i]);
}
return { path: path === '' ? '/' : path, keys: regexp.keys.slice(), params: params };
return {
path: m[0],
keys: regexp.keys.concat(parentKeys),
params: params
};
}

@@ -69,3 +78,3 @@

function matchRoute(route, baseUrl, path, parentParams) {
function matchRoute(route, baseUrl, path, parentKeys, parentParams) {
var match = void 0;

@@ -78,3 +87,3 @@ var childMatches = void 0;

if (!match) {
match = matchPath(route.path, path, !route.children, parentParams);
match = matchPath(route, path, parentKeys, parentParams);

@@ -98,7 +107,6 @@ if (match) {

if (!childMatches) {
var newPath = path.substr(match.path.length);
var childRoute = route.children[childIndex];
childRoute.parent = route;
childMatches = matchRoute(childRoute, baseUrl + (match.path === '/' ? '' : match.path), newPath.charAt(0) === '/' ? newPath : '/' + newPath, match.params);
childMatches = matchRoute(childRoute, baseUrl + match.path, path.substr(match.path.length), match.keys, match.params);
}

@@ -165,7 +173,7 @@

var Router = function () {
function Router(routes) {
var UniversalRouter = function () {
function UniversalRouter(routes) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Router);
_classCallCheck(this, UniversalRouter);

@@ -179,11 +187,11 @@ if (Object(routes) !== routes) {

this.context = Object.assign({ router: this }, options.context);
this.root = Array.isArray(routes) ? { path: '/', children: routes, parent: null } : routes;
this.root = Array.isArray(routes) ? { path: '', children: routes, parent: null } : routes;
this.root.parent = null;
}
_createClass(Router, [{
_createClass(UniversalRouter, [{
key: 'resolve',
value: function resolve(pathOrContext) {
var context = Object.assign({}, this.context, typeof pathOrContext === 'string' ? { path: pathOrContext } : pathOrContext);
var match = matchRoute(this.root, this.baseUrl, context.path.substr(this.baseUrl.length));
value: function resolve(pathnameOrContext) {
var context = Object.assign({}, this.context, typeof pathnameOrContext === 'string' ? { pathname: pathnameOrContext } : pathnameOrContext);
var match = matchRoute(this.root, this.baseUrl, context.pathname.substr(this.baseUrl.length), [], null);
var resolve = this.resolveRoute;

@@ -219,3 +227,2 @@ var matches = null;

context.url = context.path;
context.next = next;

@@ -227,11 +234,11 @@

return Router;
return UniversalRouter;
}();
Router.pathToRegexp = pathToRegexp;
Router.matchPath = matchPath;
Router.matchRoute = matchRoute;
Router.resolveRoute = resolveRoute;
UniversalRouter.pathToRegexp = pathToRegexp;
UniversalRouter.matchPath = matchPath;
UniversalRouter.matchRoute = matchRoute;
UniversalRouter.resolveRoute = resolveRoute;
module.exports = Router;
module.exports = UniversalRouter;
//# sourceMappingURL=legacy.js.map

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

function matchPath(routePath, urlPath, end, parentParams) {
const key = `${routePath}|${end}`;
function parseParam(key, value) {
if (key.repeat) {
return value ? value.split(key.delimiter).map(decodeParam) : [];
}
return value ? decodeParam(value) : value;
}
function matchPath(route, path, parentKeys, parentParams) {
const key = `${route.path || ''}|${!route.children}`;
let regexp = cache.get(key);

@@ -35,7 +42,10 @@

const keys = [];
regexp = { pattern: pathToRegexp(routePath, keys, { end }), keys };
regexp = {
keys,
pattern: pathToRegexp(route.path || '', keys, { end: !route.children })
};
cache.set(key, regexp);
}
const m = regexp.pattern.exec(urlPath);
const m = regexp.pattern.exec(path);
if (!m) {

@@ -45,14 +55,13 @@ return null;

const path = m[0];
const params = Object.create(null);
const params = Object.assign({}, parentParams);
if (parentParams) {
Object.assign(params, parentParams);
}
for (let i = 1; i < m.length; i += 1) {
params[regexp.keys[i - 1].name] = m[i] && decodeParam(m[i]);
params[regexp.keys[i - 1].name] = parseParam(regexp.keys[i - 1], m[i]);
}
return { path: path === '' ? '/' : path, keys: regexp.keys.slice(), params };
return {
path: m[0],
keys: regexp.keys.concat(parentKeys),
params
};
}

@@ -69,3 +78,3 @@

function matchRoute(route, baseUrl, path, parentParams) {
function matchRoute(route, baseUrl, path, parentKeys, parentParams) {
let match;

@@ -78,3 +87,3 @@ let childMatches;

if (!match) {
match = matchPath(route.path, path, !route.children, parentParams);
match = matchPath(route, path, parentKeys, parentParams);

@@ -98,7 +107,6 @@ if (match) {

if (!childMatches) {
const newPath = path.substr(match.path.length);
const childRoute = route.children[childIndex];
childRoute.parent = route;
childMatches = matchRoute(childRoute, baseUrl + (match.path === '/' ? '' : match.path), newPath.charAt(0) === '/' ? newPath : `/${newPath}`, match.params);
childMatches = matchRoute(childRoute, baseUrl + match.path, path.substr(match.path.length), match.keys, match.params);
}

@@ -161,3 +169,3 @@

class Router {
class UniversalRouter {
constructor(routes, options = {}) {

@@ -171,9 +179,9 @@ if (Object(routes) !== routes) {

this.context = Object.assign({ router: this }, options.context);
this.root = Array.isArray(routes) ? { path: '/', children: routes, parent: null } : routes;
this.root = Array.isArray(routes) ? { path: '', children: routes, parent: null } : routes;
this.root.parent = null;
}
resolve(pathOrContext) {
const context = Object.assign({}, this.context, typeof pathOrContext === 'string' ? { path: pathOrContext } : pathOrContext);
const match = matchRoute(this.root, this.baseUrl, context.path.substr(this.baseUrl.length));
resolve(pathnameOrContext) {
const context = Object.assign({}, this.context, typeof pathnameOrContext === 'string' ? { pathname: pathnameOrContext } : pathnameOrContext);
const match = matchRoute(this.root, this.baseUrl, context.pathname.substr(this.baseUrl.length), [], null);
const resolve = this.resolveRoute;

@@ -207,3 +215,2 @@ let matches = null;

context.url = context.path;
context.next = next;

@@ -215,8 +222,8 @@

Router.pathToRegexp = pathToRegexp;
Router.matchPath = matchPath;
Router.matchRoute = matchRoute;
Router.resolveRoute = resolveRoute;
UniversalRouter.pathToRegexp = pathToRegexp;
UniversalRouter.matchPath = matchPath;
UniversalRouter.matchRoute = matchRoute;
UniversalRouter.resolveRoute = resolveRoute;
module.exports = Router;
module.exports = UniversalRouter;
//# sourceMappingURL=main.js.map
{
"name": "universal-router",
"version": "3.2.0",
"version": "4.0.0",
"description": "Isomorphic router for JavaScript web applications",

@@ -24,8 +24,11 @@ "homepage": "https://www.kriasoft.com/universal-router/",

"main": "main.js",
"jsnext:main": "main.mjs",
"browser": "browser.js",
"jsnext:browser": "browser.mjs",
"module": "main.mjs",
"browser": {
"main.js": "./browser.js",
"main.mjs": "./browser.mjs"
},
"esnext": "src/UniversalRouter.js",
"dependencies": {
"path-to-regexp": "^1.7.0"
"path-to-regexp": "^2.0.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/master/src/Router.js)
✓ It has [simple code](https://github.com/kriasoft/universal-router/blob/v4.0.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@3.2.0/universal-router.min.js"></script>
<script src="https://unpkg.com/universal-router@4.0.0/universal-router.min.js"></script>
```

@@ -58,4 +58,4 @@

{
path: '/',
action: () => `<h1>Home</h1>`
path: '', // optional
action: () => `<h1>Home</h1>`,
},

@@ -67,10 +67,10 @@ {

{
path: '/',
action: () => `<h1>Posts</h1>`
path: '', // optional, matches both "/posts" and "/posts/"
action: () => `<h1>Posts</h1>`,
},
{
path: '/:id',
action: (context) => `<h1>Post #${context.params.id}</h1>`
}
]
action: (context) => `<h1>Post #${context.params.id}</h1>`,
},
],
},

@@ -94,3 +94,2 @@ ];

* [Overview](https://github.com/kriasoft/universal-router/blob/master/docs/README.md)
* [Getting Started](https://github.com/kriasoft/universal-router/blob/master/docs/getting-started.md)

@@ -116,4 +115,10 @@ * [Universal Router API](https://github.com/kriasoft/universal-router/blob/master/docs/api.md)

:mortar_board: &nbsp; **[ES6 Training Course](https://es6.io/friend/konstantin)** by Wes Bos<br>
:green_book: &nbsp; **[You Don't Know JS: ES6 & Beyond](http://amzn.to/2bFss85)** by Kyle Simpson (Dec, 2015)<br>
:mortar_board: &nbsp; **[ES6 Training Course](https://es6.io/friend/konstantin)**
by [Wes Bos](https://twitter.com/wesbos)<br>
:green_book: &nbsp; **[You Don't Know JS: ES6 & Beyond](http://amzn.to/2bFss85)**
by [Kyle Simpson](https://github.com/getify) (Dec, 2015)<br>
:page_facing_up: &nbsp; **[You might not need React Router](https://medium.freecodecamp.org/38673620f3d)**
by [Konstantin Tarkus](https://twitter.com/koistya)<br>
:page_facing_up: &nbsp; **[An Introduction to the Redux-First Routing Model](https://medium.freecodecamp.org/98926ebf53cb)**
by [Michael Sargent](https://twitter.com/michaelksarge)<br>

@@ -200,15 +205,17 @@

* [React Starter Kit](https://github.com/kriasoft/react-starter-kit) —
Isomorphic web app boilerplate (Node.js, React, GraphQL, Webpack, CSS Modules)
Boilerplate and tooling for building isomorphic web apps with React and Relay
* [Node.js API Starter Kit](https://github.com/kriasoft/nodejs-api-starter) —
Boilerplate and tooling for building data APIs with Node.js, GraphQL and Relay
Boilerplate and tooling for building data APIs with Docker, Node.js and GraphQL
* [ASP.NET Core Starter Kit](https://github.com/kriasoft/aspnet-starter-kit) —
Cross-platform single-page application boilerplate (ASP.NET Core, React, Redux)
* [Babel Starter Kit](https://github.com/kriasoft/babel-starter-kit) —
JavaScript library boilerplate (ES2015, Babel, Rollup, Mocha, Chai, Sinon, Rewire)
Boilerplate for authoring JavaScript/React.js libraries
* [React App SDK](https://github.com/kriasoft/react-app) —
Create React apps with just a single dev dependency and zero configuration
* [React Static Boilerplate](https://github.com/koistya/react-static-boilerplate) —
* [React Static Boilerplate](https://github.com/kriasoft/react-static-boilerplate) —
Single-page application (SPA) starter kit (React, Redux, Webpack, Firebase)
* [History](https://github.com/mjackson/history) —
* [History](https://github.com/ReactTraining/history) —
HTML5 History API wrapper library that handle navigation in single-page apps
* [Redux-First Routing](https://github.com/mksarge/redux-first-routing) —
A minimal, framework-agnostic API for accomplishing Redux-first routing

@@ -215,0 +222,0 @@

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

(global.generateUrls = factory(global.UniversalRouter));
}(this, (function (Router) { 'use strict';
}(this, (function (UniversalRouter) { 'use strict';
Router = 'default' in Router ? Router['default'] : Router;
UniversalRouter = UniversalRouter && UniversalRouter.hasOwnProperty('default') ? UniversalRouter['default'] : UniversalRouter;

@@ -23,2 +23,4 @@ /**

var pathToRegexp = UniversalRouter.pathToRegexp;
var cache = new Map();

@@ -47,4 +49,4 @@

if (!(router instanceof Router)) {
throw new TypeError('An instance of Router is expected');
if (!(router instanceof UniversalRouter)) {
throw new TypeError('An instance of UniversalRouter is expected');
}

@@ -71,3 +73,3 @@

while (rt) {
if (rt.path !== '/') {
if (rt.path) {
fullPath = rt.path + fullPath;

@@ -77,4 +79,4 @@ }

}
var tokens = Router.pathToRegexp.parse(fullPath);
var toPath = Router.pathToRegexp.tokensToFunction(tokens);
var tokens = pathToRegexp.parse(fullPath);
var toPath = pathToRegexp.tokensToFunction(tokens);
var keys = Object.create(null);

@@ -94,3 +96,3 @@ for (var i = 0; i < tokens.length; i += 1) {

if (options.stringifyQueryParams && params) {
var queryParams = Object.create(null);
var queryParams = {};
var _keys = Object.keys(params);

@@ -113,3 +115,3 @@ for (var _i = 0; _i < _keys.length; _i += 1) {

Router.generateUrls = generateUrls;
UniversalRouter.generateUrls = generateUrls;

@@ -116,0 +118,0 @@ return generateUrls;

/*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("./universal-router.min.js")):"function"==typeof define&&define.amd?define(["./universal-router.min.js"],r):e.generateUrls=r(e.UniversalRouter)}(this,function(e){"use strict";function r(e,t,n){if(e[t.name])throw new Error('Route "'+t.name+'" already exists');if(t.name&&(e[t.name]=t),n)for(var a=0;a<n.length;a+=1){var o=n[a];o.parent=t,r(e,o,o.children)}}function t(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(t instanceof e))throw new TypeError("An instance of Router is expected");return t.routesByName=t.routesByName||{},function(o,i){var u=t.routesByName[o];if(!(u||(t.routesByName={},r(t.routesByName,t.root,t.root.children),u=t.routesByName[o])))throw new Error('Route "'+o+'" not found');var s=n.get(u.fullPath);if(!s){for(var f="",l=u;l;)"/"!==l.path&&(f=l.path+f),l=l.parent;for(var c=e.pathToRegexp.parse(f),h=e.pathToRegexp.tokensToFunction(c),y=Object.create(null),m=0;m<c.length;m+=1)"string"!=typeof c[m]&&(y[c[m].name]=!0);s={toPath:h,keys:y},n.set(f,s),u.fullPath=f}var p=t.baseUrl+s.toPath(i,a)||"/";if(a.stringifyQueryParams&&i){for(var d=Object.create(null),v=Object.keys(i),g=0;g<v.length;g+=1){var w=v[g];s.keys[w]||(d[w]=i[w])}var j=a.stringifyQueryParams(d);j&&(p+="?"===j.charAt(0)?j:"?"+j)}return p}}e="default"in e?e.default:e;var n=new Map;return e.generateUrls=t,t});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("./universal-router.min.js")):"function"==typeof define&&define.amd?define(["./universal-router.min.js"],r):e.generateUrls=r(e.UniversalRouter)}(this,function(e){"use strict";function r(e,t,n){if(e[t.name])throw new Error('Route "'+t.name+'" already exists');if(t.name&&(e[t.name]=t),n)for(var a=0;a<n.length;a+=1){var o=n[a];o.parent=t,r(e,o,o.children)}}function t(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(t instanceof e))throw new TypeError("An instance of UniversalRouter is expected");return t.routesByName=t.routesByName||{},function(e,i){var s=t.routesByName[e];if(!(s||(t.routesByName={},r(t.routesByName,t.root,t.root.children),s=t.routesByName[e])))throw new Error('Route "'+e+'" not found');var u=a.get(s.fullPath);if(!u){for(var f="",l=s;l;)l.path&&(f=l.path+f),l=l.parent;for(var y=n.parse(f),h=n.tokensToFunction(y),c=Object.create(null),m=0;m<y.length;m+=1)"string"!=typeof y[m]&&(c[y[m].name]=!0);u={toPath:h,keys:c},a.set(f,u),s.fullPath=f}var p=t.baseUrl+u.toPath(i,o)||"/";if(o.stringifyQueryParams&&i){for(var v={},d=Object.keys(i),g=0;g<d.length;g+=1){var w=d[g];u.keys[w]||(v[w]=i[w])}var P=o.stringifyQueryParams(v);P&&(p+="?"===P.charAt(0)?P:"?"+P)}return p}}var n=(e=e&&e.hasOwnProperty("default")?e.default:e).pathToRegexp,a=new Map;return e.generateUrls=t,t});
//# sourceMappingURL=universal-router-generate-urls.min.js.map

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

var index$1 = Array.isArray || function (arr) {
return Object.prototype.toString.call(arr) == '[object Array]';
};
/**
* Expose `pathToRegexp`.
*/
var index = pathToRegexp;
var pathToRegexp_1$1 = pathToRegexp;
var parse_1 = parse;

@@ -35,6 +31,5 @@ var compile_1 = compile;

//
// "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined]
// "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined]
// "/*" => ["/", undefined, undefined, undefined, undefined, "*"]
'([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))'
// "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?"]
// "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined]
'(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?'
].join('|'), 'g');

@@ -54,6 +49,8 @@

var path = '';
var defaultDelimiter = options && options.delimiter || '/';
var defaultDelimiter = (options && options.delimiter) || '/';
var delimiters = (options && options.delimiters) || './';
var pathEscaped = false;
var res;
while ((res = PATH_REGEXP.exec(str)) != null) {
while ((res = PATH_REGEXP.exec(str)) !== null) {
var m = res[0];

@@ -68,13 +65,22 @@ var escaped = res[1];

path += escaped[1];
pathEscaped = true;
continue
}
var prev = '';
var next = str[index];
var prefix = res[2];
var name = res[3];
var capture = res[4];
var group = res[5];
var modifier = res[6];
var asterisk = res[7];
var name = res[2];
var capture = res[3];
var group = res[4];
var modifier = res[5];
if (!pathEscaped && path.length) {
var k = path.length - 1;
if (delimiters.indexOf(path[k]) > -1) {
prev = path[k];
path = path.slice(0, k);
}
}
// Push the current path onto the tokens.

@@ -84,8 +90,9 @@ if (path) {

path = '';
pathEscaped = false;
}
var partial = prefix != null && next != null && next !== prefix;
var partial = prev !== '' && next !== undefined && next !== prev;
var repeat = modifier === '+' || modifier === '*';
var optional = modifier === '?' || modifier === '*';
var delimiter = res[2] || defaultDelimiter;
var delimiter = prev || defaultDelimiter;
var pattern = capture || group;

@@ -95,3 +102,3 @@

name: name || key++,
prefix: prefix || '',
prefix: prev,
delimiter: delimiter,

@@ -101,17 +108,11 @@ optional: optional,

partial: partial,
asterisk: !!asterisk,
pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
pattern: pattern ? escapeGroup(pattern) : '[^' + escapeString(delimiter) + ']+?'
});
}
// Match any characters still remaining.
if (index < str.length) {
path += str.substr(index);
// Push any remaining characters.
if (path || index < str.length) {
tokens.push(path + str.substr(index));
}
// If the path exists, push it onto the end.
if (path) {
tokens.push(path);
}
return tokens

@@ -132,26 +133,2 @@ }

/**
* Prettier encoding of URI path segments.
*
* @param {string}
* @return {string}
*/
function encodeURIComponentPretty (str) {
return encodeURI(str).replace(/[\/?#]/g, function (c) {
return '%' + c.charCodeAt(0).toString(16).toUpperCase()
})
}
/**
* Encode the asterisk parameter. Similar to `pretty`, but allows slashes.
*
* @param {string}
* @return {string}
*/
function encodeAsterisk (str) {
return encodeURI(str).replace(/[?#]/g, function (c) {
return '%' + c.charCodeAt(0).toString(16).toUpperCase()
})
}
/**
* Expose a method for transforming tokens into the path function.

@@ -170,7 +147,5 @@ */

return function (obj, opts) {
return function (data, options) {
var path = '';
var data = obj || {};
var options = opts || {};
var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent;
var encode = (options && options.encode) || encodeURIComponent;

@@ -182,33 +157,17 @@ for (var i = 0; i < tokens.length; i++) {

path += token;
continue
}
var value = data[token.name];
var value = data ? data[token.name] : undefined;
var segment;
if (value == null) {
if (token.optional) {
// Prepend partial segment prefixes.
if (token.partial) {
path += token.prefix;
}
continue
} else {
throw new TypeError('Expected "' + token.name + '" to be defined')
}
}
if (index$1(value)) {
if (Array.isArray(value)) {
if (!token.repeat) {
throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`')
throw new TypeError('Expected "' + token.name + '" to not repeat, but got array')
}
if (value.length === 0) {
if (token.optional) {
continue
} else {
throw new TypeError('Expected "' + token.name + '" to not be empty')
}
if (token.optional) continue
throw new TypeError('Expected "' + token.name + '" to not be empty')
}

@@ -220,3 +179,3 @@

if (!matches[i].test(segment)) {
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`')
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"')
}

@@ -230,9 +189,21 @@

segment = token.asterisk ? encodeAsterisk(value) : encode(value);
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
segment = encode(String(value));
if (!matches[i].test(segment)) {
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"')
if (!matches[i].test(segment)) {
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"')
}
path += token.prefix + segment;
continue
}
path += token.prefix + segment;
if (token.optional) {
// Prepend partial segment prefixes.
if (token.partial) path += token.prefix;
continue
}
throw new TypeError('Expected "' + token.name + '" to be ' + (token.repeat ? 'an array' : 'a string'))
}

@@ -251,3 +222,3 @@

function escapeString (str) {
return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1')
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1')
}

@@ -262,18 +233,6 @@

function escapeGroup (group) {
return group.replace(/([=!:$\/()])/g, '\\$1')
return group.replace(/([=!:$/()])/g, '\\$1')
}
/**
* Attach the keys as a property of the regexp.
*
* @param {!RegExp} re
* @param {Array} keys
* @return {!RegExp}
*/
function attachKeys (re, keys) {
re.keys = keys;
return re
}
/**
* Get the flags for a regexp from the options.

@@ -285,3 +244,3 @@ *

function flags (options) {
return options.sensitive ? '' : 'i'
return options && options.sensitive ? '' : 'i'
}

@@ -293,6 +252,8 @@

* @param {!RegExp} path
* @param {!Array} keys
* @param {Array=} keys
* @return {!RegExp}
*/
function regexpToRegexp (path, keys) {
if (!keys) return path
// Use a negative lookahead to match only capturing groups.

@@ -310,3 +271,2 @@ var groups = path.source.match(/\((?!\?)/g);

partial: false,
asterisk: false,
pattern: null

@@ -317,3 +277,3 @@ });

return attachKeys(path, keys)
return path
}

@@ -325,4 +285,4 @@

* @param {!Array} path
* @param {Array} keys
* @param {!Object} options
* @param {Array=} keys
* @param {Object=} options
* @return {!RegExp}

@@ -337,5 +297,3 @@ */

var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options));
return attachKeys(regexp, keys)
return new RegExp('(?:' + parts.join('|') + ')', flags(options))
}

@@ -347,4 +305,4 @@

* @param {string} path
* @param {!Array} keys
* @param {!Object} options
* @param {Array=} keys
* @param {Object=} options
* @return {!RegExp}

@@ -359,13 +317,8 @@ */

*
* @param {!Array} tokens
* @param {(Array|Object)=} keys
* @param {Object=} options
* @param {!Array} tokens
* @param {Array=} keys
* @param {Object=} options
* @return {!RegExp}
*/
function tokensToRegExp (tokens, keys, options) {
if (!index$1(keys)) {
options = /** @type {!Object} */ (keys || options);
keys = [];
}
options = options || {};

@@ -375,2 +328,4 @@

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

@@ -388,3 +343,3 @@

keys.push(token);
if (keys) keys.push(token);

@@ -409,22 +364,16 @@ if (token.repeat) {

var delimiter = escapeString(options.delimiter || '/');
var endsWithDelimiter = route.slice(-delimiter.length) === delimiter;
// In non-strict mode we allow a slash at the end of match. If the path to
// match already ends with a slash, we remove it for consistency. The slash
// is valid at the end of a path match, not in the middle. This is important
// in non-ending mode, where "/test/" shouldn't match "/test//route".
// In non-strict mode we allow a delimiter at the end of a match.
if (!strict) {
route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?';
route += '(?:' + delimiter + '(?=' + endsWith + '))?';
}
if (end) {
route += '$';
route += endsWith === '$' ? 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 += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)';
route += '(?=' + delimiter + '|' + endsWith + ')';
}
return attachKeys(new RegExp('^' + route, flags(options)), keys)
return new RegExp('^' + route, flags(options))
}

@@ -440,3 +389,3 @@

* @param {(string|RegExp|Array)} path
* @param {(Array|Object)=} keys
* @param {Array=} keys
* @param {Object=} options

@@ -446,24 +395,17 @@ * @return {!RegExp}

function pathToRegexp (path, keys, options) {
if (!index$1(keys)) {
options = /** @type {!Object} */ (keys || options);
keys = [];
}
options = options || {};
if (path instanceof RegExp) {
return regexpToRegexp(path, /** @type {!Array} */ (keys))
return regexpToRegexp(path, keys)
}
if (index$1(path)) {
return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options)
if (Array.isArray(path)) {
return arrayToRegexp(/** @type {!Array} */ (path), keys, options)
}
return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
return stringToRegexp(/** @type {string} */ (path), keys, options)
}
index.parse = parse_1;
index.compile = compile_1;
index.tokensToFunction = tokensToFunction_1;
index.tokensToRegExp = tokensToRegExp_1;
pathToRegexp_1$1.parse = parse_1;
pathToRegexp_1$1.compile = compile_1;
pathToRegexp_1$1.tokensToFunction = tokensToFunction_1;
pathToRegexp_1$1.tokensToRegExp = tokensToRegExp_1;

@@ -489,4 +431,11 @@ /**

function matchPath(routePath, urlPath, end, parentParams) {
var key = routePath + '|' + end;
function parseParam(key, value) {
if (key.repeat) {
return value ? value.split(key.delimiter).map(decodeParam) : [];
}
return value ? decodeParam(value) : value;
}
function matchPath(route, path, parentKeys, parentParams) {
var key = (route.path || '') + '|' + !route.children;
var regexp = cache.get(key);

@@ -496,7 +445,10 @@

var keys = [];
regexp = { pattern: index(routePath, keys, { end: end }), keys: keys };
regexp = {
keys: keys,
pattern: pathToRegexp_1$1(route.path || '', keys, { end: !route.children })
};
cache.set(key, regexp);
}
var m = regexp.pattern.exec(urlPath);
var m = regexp.pattern.exec(path);
if (!m) {

@@ -506,14 +458,13 @@ return null;

var path = m[0];
var params = Object.create(null);
var params = Object.assign({}, parentParams);
if (parentParams) {
Object.assign(params, parentParams);
}
for (var i = 1; i < m.length; i += 1) {
params[regexp.keys[i - 1].name] = m[i] && decodeParam(m[i]);
params[regexp.keys[i - 1].name] = parseParam(regexp.keys[i - 1], m[i]);
}
return { path: path === '' ? '/' : path, keys: regexp.keys.slice(), params: params };
return {
path: m[0],
keys: regexp.keys.concat(parentKeys),
params: params
};
}

@@ -530,3 +481,3 @@

function matchRoute(route, baseUrl, path, parentParams) {
function matchRoute(route, baseUrl, path, parentKeys, parentParams) {
var match = void 0;

@@ -539,3 +490,3 @@ var childMatches = void 0;

if (!match) {
match = matchPath(route.path, path, !route.children, parentParams);
match = matchPath(route, path, parentKeys, parentParams);

@@ -559,7 +510,6 @@ if (match) {

if (!childMatches) {
var newPath = path.substr(match.path.length);
var childRoute = route.children[childIndex];
childRoute.parent = route;
childMatches = matchRoute(childRoute, baseUrl + (match.path === '/' ? '' : match.path), newPath.charAt(0) === '/' ? newPath : '/' + newPath, match.params);
childMatches = matchRoute(childRoute, baseUrl + match.path, path.substr(match.path.length), match.keys, match.params);
}

@@ -626,7 +576,7 @@

var Router = function () {
function Router(routes) {
var UniversalRouter = function () {
function UniversalRouter(routes) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Router);
_classCallCheck(this, UniversalRouter);

@@ -640,11 +590,11 @@ if (Object(routes) !== routes) {

this.context = Object.assign({ router: this }, options.context);
this.root = Array.isArray(routes) ? { path: '/', children: routes, parent: null } : routes;
this.root = Array.isArray(routes) ? { path: '', children: routes, parent: null } : routes;
this.root.parent = null;
}
_createClass(Router, [{
_createClass(UniversalRouter, [{
key: 'resolve',
value: function resolve(pathOrContext) {
var context = Object.assign({}, this.context, typeof pathOrContext === 'string' ? { path: pathOrContext } : pathOrContext);
var match = matchRoute(this.root, this.baseUrl, context.path.substr(this.baseUrl.length));
value: function resolve(pathnameOrContext) {
var context = Object.assign({}, this.context, typeof pathnameOrContext === 'string' ? { pathname: pathnameOrContext } : pathnameOrContext);
var match = matchRoute(this.root, this.baseUrl, context.pathname.substr(this.baseUrl.length), [], null);
var resolve = this.resolveRoute;

@@ -680,3 +630,2 @@ var matches = null;

context.url = context.path;
context.next = next;

@@ -688,13 +637,13 @@

return Router;
return UniversalRouter;
}();
Router.pathToRegexp = index;
Router.matchPath = matchPath;
Router.matchRoute = matchRoute;
Router.resolveRoute = resolveRoute;
UniversalRouter.pathToRegexp = pathToRegexp_1$1;
UniversalRouter.matchPath = matchPath;
UniversalRouter.matchRoute = matchRoute;
UniversalRouter.resolveRoute = resolveRoute;
return Router;
return UniversalRouter;
})));
//# sourceMappingURL=universal-router.js.map
/*! 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 r,n=[],o=0,u=0,l="",s=t&&t.delimiter||"/";null!=(r=U.exec(e));){var c=r[0],p=r[1],f=r.index;if(l+=e.slice(u,f),u=f+c.length,p)l+=p[1];else{var h=e[u],v=r[2],d=r[3],g=r[4],y=r[5],m=r[6],x=r[7];l&&(n.push(l),l="");var b=null!=v&&null!=h&&h!==v,w="+"===m||"*"===m,E="?"===m||"*"===m,R=r[2]||s,j=g||y;n.push({name:d||o++,prefix:v||"",delimiter:R,optional:E,repeat:w,partial:b,asterisk:!!x,pattern:j?a(j):x?".*":"[^"+i(R)+"]+?"})}}return u<e.length&&(l+=e.substr(u)),l&&n.push(l),n}function t(t,r){return o(e(t,r))}function r(e){return encodeURI(e).replace(/[\/?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}function n(e){return encodeURI(e).replace(/[?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}function o(e){for(var t=new Array(e.length),o=0;o<e.length;o++)"object"==typeof e[o]&&(t[o]=new RegExp("^(?:"+e[o].pattern+")$"));return function(o,i){for(var a="",u=o||{},l=i||{},s=l.pretty?r:encodeURIComponent,c=0;c<e.length;c++){var p=e[c];if("string"!=typeof p){var f,h=u[p.name];if(null==h){if(p.optional){p.partial&&(a+=p.prefix);continue}throw new TypeError('Expected "'+p.name+'" to be defined')}if(b(h)){if(!p.repeat)throw new TypeError('Expected "'+p.name+'" to not repeat, but received `'+JSON.stringify(h)+"`");if(0===h.length){if(p.optional)continue;throw new TypeError('Expected "'+p.name+'" to not be empty')}for(var v=0;v<h.length;v++){if(f=s(h[v]),!t[c].test(f))throw new TypeError('Expected all "'+p.name+'" to match "'+p.pattern+'", but received `'+JSON.stringify(f)+"`");a+=(0===v?p.prefix:p.delimiter)+f}}else{if(f=p.asterisk?n(h):s(h),!t[c].test(f))throw new TypeError('Expected "'+p.name+'" to match "'+p.pattern+'", but received "'+f+'"');a+=p.prefix+f}}else a+=p}return a}}function i(e){return e.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function a(e){return e.replace(/([=!:$\/()])/g,"\\$1")}function u(e,t){return e.keys=t,e}function l(e){return e.sensitive?"":"i"}function s(e,t){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,asterisk:!1,pattern:null});return u(e,t)}function c(e,t,r){for(var n=[],o=0;o<e.length;o++)n.push(h(e[o],t,r).source);return u(new RegExp("(?:"+n.join("|")+")",l(r)),t)}function p(t,r,n){return f(e(t,n),r,n)}function f(e,t,r){b(t)||(r=t||r,t=[]),r=r||{};for(var n=r.strict,o=!1!==r.end,a="",s=0;s<e.length;s++){var c=e[s];if("string"==typeof c)a+=i(c);else{var p=i(c.prefix),f="(?:"+c.pattern+")";t.push(c),c.repeat&&(f+="(?:"+p+f+")*"),f=c.optional?c.partial?p+"("+f+")?":"(?:"+p+"("+f+"))?":p+"("+f+")",a+=f}}var h=i(r.delimiter||"/"),v=a.slice(-h.length)===h;return n||(a=(v?a.slice(0,-h.length):a)+"(?:"+h+"(?=$))?"),a+=o?"$":n&&v?"":"(?="+h+"|$)",u(new RegExp("^"+a,l(r)),t)}function h(e,t,r){return b(t)||(r=t||r,t=[]),r=r||{},e instanceof RegExp?s(e,t):b(e)?c(e,t,r):p(e,t,r)}function v(e){try{return decodeURIComponent(e)}catch(t){return e}}function d(e,t,r,n){var o=e+"|"+r,i=O.get(o);if(!i){var a=[];i={pattern:w(e,a,{end:r}),keys:a},O.set(o,i)}var u=i.pattern.exec(t);if(!u)return null;var l=u[0],s=Object.create(null);n&&Object.assign(s,n);for(var c=1;c<u.length;c+=1)s[i.keys[c-1].name]=u[c]&&v(u[c]);return{path:""===l?"/":l,keys:i.keys.slice(),params:s}}function g(e,t,r,n){var o=void 0,i=void 0,a=0;return{next:function(){if(!o&&(o=d(e.path,r,!e.children,n)))return{done:!1,value:{route:e,baseUrl:t,path:o.path,keys:o.keys,params:o.params}};if(o&&e.children)for(;a<e.children.length;){if(!i){var u=r.substr(o.path.length),l=e.children[a];l.parent=e,i=g(l,t+("/"===o.path?"":o.path),"/"===u.charAt(0)?u:"/"+u,o.params)}var s=i.next();if(!s.done)return{done:!1,value:s.value};i=null,a+=1}return{done:!0}}}}function y(e,t){return"function"==typeof e.route.action?e.route.action(e,t):null}function m(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function x(e,t){for(var r=t;r;)if((r=r.parent)===e)return!0;return!1}var b=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)},w=h,E=e,R=t,j=o,k=f,U=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");w.parse=E,w.compile=R,w.tokensToFunction=j,w.tokensToRegExp=k;var O=new Map,T=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}}(),A=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(m(this,e),Object(t)!==t)throw new TypeError("Invalid routes");this.baseUrl=r.baseUrl||"",this.resolveRoute=r.resolveRoute||y,this.context=Object.assign({router:this},r.context),this.root=Array.isArray(t)?{path:"/",children:t,parent:null}:t,this.root.parent=null}return T(e,[{key:"resolve",value:function(e){function t(e){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i.value.route;return i=a||n.next(),a=null,e||!i.done&&x(u,i.value.route)?i.done?Promise.reject(Object.assign(new Error("Page not found"),{context:r,status:404,statusCode:404})):Promise.resolve(o(Object.assign({},r,i.value),i.value.params)).then(function(r){return null!==r&&void 0!==r?r:t(e,u)}):(a=i,Promise.resolve(null))}var r=Object.assign({},this.context,"string"==typeof e?{path:e}:e),n=g(this.root,this.baseUrl,r.path.substr(this.baseUrl.length)),o=this.resolveRoute,i=null,a=null;return r.url=r.path,r.next=t,t(!0,this.root)}}]),e}();return A.pathToRegexp=w,A.matchPath=d,A.matchRoute=g,A.resolveRoute=y,A});
!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=w.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],b=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="+"===b||"*"===b,k="?"===b||"*"===b,T=d||s,O=y||x;a.push({name:m||i++,prefix:d,delimiter:T,optional:k,repeat:j,partial:R,pattern:O?n(O):"[^"+r(T)+"]+?"})}}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){return e.repeat?t?t.split(e.delimiter).map(p):[]:t?p(t):t}function f(e,t,r,n){var o=(e.path||"")+"|"+!e.children,a=E.get(o);if(!a){var i=[];a={keys:i,pattern:m(e.path||"",i,{end:!e.children})},E.set(o,a)}var u=a.pattern.exec(t);if(!u)return null;for(var l=Object.assign({},n),s=1;s<u.length;s+=1)l[a.keys[s-1].name]=c(a.keys[s-1],u[s]);return{path:u[0],keys:a.keys.concat(r),params:l}}function h(e,t,r,n,o){var a=void 0,i=void 0,u=0;return{next:function(){if(!a&&(a=f(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=h(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 v(e,t){return"function"==typeof e.route.action?e.route.action(e,t):null}function d(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function g(e,t){for(var r=t;r;)if((r=r.parent)===e)return!0;return!1}var m=s,y=e,x=t,b=l,w=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");m.parse=y,m.compile=function(r,n){return t(e(r,n))},m.tokensToFunction=x,m.tokensToRegExp=b;var 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(d(this,e),Object(t)!==t)throw new TypeError("Invalid routes");this.baseUrl=r.baseUrl||"",this.resolveRoute=r.resolveRoute||v,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&&g(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=h(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=m,j.matchPath=f,j.matchRoute=h,j.resolveRoute=v,j});
//# 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

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

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