universal-router
Version:
Isomorphic router for JavaScript web applications
4 lines (3 loc) • 1.62 kB
JavaScript
/*! 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";var r=(e=e&&e.hasOwnProperty("default")?e.default:e).pathToRegexp,t=new Map;function a(a){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(a instanceof e))throw new TypeError("An instance of UniversalRouter is expected");return a.routesByName=a.routesByName||new Map,function(e,o){var s=a.routesByName.get(e);if(!(s||(a.routesByName.clear(),function e(r,t,a){if(r.has(t.name))throw new Error('Route "'+t.name+'" already exists');if(t.name&&r.set(t.name,t),a)for(var n=0;n<a.length;n+=1){var o=a[n];o.parent=t,e(r,o,o.children)}}(a.routesByName,a.root,a.root.children),s=a.routesByName.get(e))))throw new Error('Route "'+e+'" not found');var i=t.get(s.fullPath);if(!i){for(var u="",f=s;f;){var l=Array.isArray(f.path)?f.path[0]:f.path;l&&(u=l+u),f=f.parent}for(var y=r.parse(u),h=r.tokensToFunction(y),c=Object.create(null),p=0;p<y.length;p+=1)"string"!=typeof y[p]&&(c[y[p].name]=!0);i={toPath:h,keys:c},t.set(u,i),s.fullPath=u}var m=a.baseUrl+i.toPath(o,n)||"/";if(n.stringifyQueryParams&&o){for(var v={},d=Object.keys(o),g=0;g<d.length;g+=1){var w=d[g];i.keys[w]||(v[w]=o[w])}var P=n.stringifyQueryParams(v);P&&(m+="?"===P.charAt(0)?P:"?"+P)}return m}}return e.generateUrls=a,a});
//# sourceMappingURL=universal-router-generate-urls.min.js.map