UNPKG

rudy-match-path

Version:

link to URL path matching borrowed from React Router

1 lines 5.17 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ReduxFirstRouterLink=t():e.ReduxFirstRouterLink=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e["default"]}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,r){"use strict";function n(e){return Array.isArray(e)?e:Array.from(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.compileParamsToPath=t.compilePath=undefined;var o=r(1),i=function(e){return e&&e.__esModule?e:{"default":e}}(o),u={},a=0,p=t.compilePath=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=t.end,n=r===undefined||r,o=t.strict,p=o!==undefined&&o,f=(n?"t":"f")+(p?"t":"f"),c=u[f]||(u[f]={});if(c[e])return c[e];var l=[],s=(0,i["default"])(e,l,t),d={re:s,keys:l};return 1e4>a&&(c[e]=d,a++),d},f={};t.compileParamsToPath=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=f[e]||i["default"].compile(e);return f[e]=r,r(t)};t["default"]=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};"string"==typeof t&&(t={path:t,exact:!1,strict:!1});var r=t,o=r.path,i=o===undefined?"/":o,u=r.exact,a=u!==undefined&&u,f=r.strict,c=f!==undefined&&f,l=p(i,{end:a,strict:c}),s=l.re,d=l.keys,h=s.exec(e);if(!h)return null;var x=n(h),g=x[0],m=x.slice(1),v=e===g;return a&&!v?null:{path:i,url:"/"===i&&""===g?"/":g,isExact:v,params:d.reduce(function(e,t,r){return e[t.name]=m[r],e},{})}}},function(e,t,r){function n(e,t){for(var r,n=[],o=0,i=0,u="",a=t&&t.delimiter||"/";null!=(r=v.exec(e));){var c=r[0],l=r[1],s=r.index;if(u+=e.slice(i,s),i=s+c.length,l)u+=l[1];else{var d=e[i],h=r[2],x=r[3],g=r[4],m=r[5],y=r[6],b=r[7];u&&(n.push(u),u="");var E=null!=h&&null!=d&&d!==h,R="+"===y||"*"===y,w="?"===y||"*"===y,j=r[2]||a,k=g||m;n.push({name:x||o++,prefix:h||"",delimiter:j,optional:w,repeat:R,partial:E,asterisk:!!b,pattern:k?f(k):b?".*":"[^"+p(j)+"]+?"})}}return e.length>i&&(u+=e.substr(i)),u&&n.push(u),n}function o(e,t){return a(n(e,t))}function i(e){return encodeURI(e).replace(/[\/?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}function u(e){return encodeURI(e).replace(/[?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}function a(e){for(var t=Array(e.length),r=0;e.length>r;r++)"object"==typeof e[r]&&(t[r]=RegExp("^(?:"+e[r].pattern+")$"));return function(r,n){for(var o="",a=r||{},p=n||{},f=p.pretty?i:encodeURIComponent,c=0;e.length>c;c++){var l=e[c];if("string"!=typeof l){var s,d=a[l.name];if(null==d){if(l.optional){l.partial&&(o+=l.prefix);continue}throw new TypeError('Expected "'+l.name+'" to be defined')}if(m(d)){if(!l.repeat)throw new TypeError('Expected "'+l.name+'" to not repeat, but received `'+JSON.stringify(d)+"`");if(0===d.length){if(l.optional)continue;throw new TypeError('Expected "'+l.name+'" to not be empty')}for(var h=0;d.length>h;h++){if(s=f(d[h]),!t[c].test(s))throw new TypeError('Expected all "'+l.name+'" to match "'+l.pattern+'", but received `'+JSON.stringify(s)+"`");o+=(0===h?l.prefix:l.delimiter)+s}}else{if(s=l.asterisk?u(d):f(d),!t[c].test(s))throw new TypeError('Expected "'+l.name+'" to match "'+l.pattern+'", but received "'+s+'"');o+=l.prefix+s}}else o+=l}return o}}function p(e){return e.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function f(e){return e.replace(/([=!:$\/()])/g,"\\$1")}function c(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;r.length>n;n++)t.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return c(e,t)}function d(e,t,r){for(var n=[],o=0;e.length>o;o++)n.push(g(e[o],t,r).source);return c(RegExp("(?:"+n.join("|")+")",l(r)),t)}function h(e,t,r){return x(n(e,r),t,r)}function x(e,t,r){m(t)||(r=t||r,t=[]),r=r||{};for(var n=r.strict,o=!1!==r.end,i="",u=0;e.length>u;u++){var a=e[u];if("string"==typeof a)i+=p(a);else{var f=p(a.prefix),s="(?:"+a.pattern+")";t.push(a),a.repeat&&(s+="(?:"+f+s+")*"),s=a.optional?a.partial?f+"("+s+")?":"(?:"+f+"("+s+"))?":f+"("+s+")",i+=s}}var d=p(r.delimiter||"/"),h=i.slice(-d.length)===d;return n||(i=(h?i.slice(0,-d.length):i)+"(?:"+d+"(?=$))?"),i+=o?"$":n&&h?"":"(?="+d+"|$)",c(RegExp("^"+i,l(r)),t)}function g(e,t,r){return m(t)||(r=t||r,t=[]),r=r||{},e instanceof RegExp?s(e,t):m(e)?d(e,t,r):h(e,t,r)}var m=r(2);e.exports=g,e.exports.parse=n,e.exports.compile=o,e.exports.tokensToFunction=a,e.exports.tokensToRegExp=x;var v=RegExp("(\\\\.)|([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))","g")},function(e,t){e.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}}])});