Module 353719

3,035 characters · in 12008.4aa0c96447cffb6e.js, 40060.4453ca606a1c4545.js
Dependencies
Required by (2)
Lazily required by (0)none
Requires (1)
Lazily requires (0)none
Source Raw
function(e,t,r){var n=r(271434);e.exports=function e(t,r,i){if(n(r)||(i=r||i,r=[]),i=i||{},t instanceof RegExp){var p,a,l=r,s=t.source.match(/\((?!\?)/g);if(s)for(var f=0;f<s.length;f++)l.push({name:f,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return t.keys=l,t}if(n(t)){for(var h,g=r,d=i,x=[],v=0;v<t.length;v++)x.push(e(t[v],g,d).source);return(h=RegExp("(?:"+x.join("|")+")",u(d))).keys=g,h}return p=r,c(o(t,a=i),p,a)},e.exports.parse=o,e.exports.compile=function(e,t){return a(o(e,t))},e.exports.tokensToFunction=a,e.exports.tokensToRegExp=c;var i=RegExp("(\\\\.)|([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))","g");function o(e,t){for(var r,n=[],o=0,p=0,a="",u=t&&t.delimiter||"/";null!=(r=i.exec(e));){var c=r[0],s=r[1],f=r.index;if(a+=e.slice(p,f),p=f+c.length,s){a+=s[1];continue}var h=e[p],g=r[2],d=r[3],x=r[4],v=r[5],m=r[6],y=r[7];a&&(n.push(a),a="");var E=null!=g&&null!=h&&h!==g,k="+"===m||"*"===m,b="?"===m||"*"===m,R=r[2]||u,w=x||v;n.push({name:d||o++,prefix:g||"",delimiter:R,optional:b,repeat:k,partial:E,asterisk:!!y,pattern:w?w.replace(/([=!:$\/()])/g,"\\$1"):y?".*":"[^"+l(R)+"]+?"})}return p<e.length&&(a+=e.substr(p)),a&&n.push(a),n}function p(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;r<e.length;r++)"object"==typeof e[r]&&(t[r]=RegExp("^(?:"+e[r].pattern+")$"));return function(r,i){for(var o="",a=r||{},l=(i||{}).pretty?p:encodeURIComponent,u=0;u<e.length;u++){var c,s=e[u];if("string"==typeof s){o+=s;continue}var f=a[s.name];if(null==f)if(s.optional){s.partial&&(o+=s.prefix);continue}else throw TypeError('Expected "'+s.name+'" to be defined');if(n(f)){if(!s.repeat)throw TypeError('Expected "'+s.name+'" to not repeat, but received `'+JSON.stringify(f)+"`");if(0===f.length)if(s.optional)continue;else throw TypeError('Expected "'+s.name+'" to not be empty');for(var h=0;h<f.length;h++){if(c=l(f[h]),!t[u].test(c))throw TypeError('Expected all "'+s.name+'" to match "'+s.pattern+'", but received `'+JSON.stringify(c)+"`");o+=(0===h?s.prefix:s.delimiter)+c}continue}if(c=s.asterisk?encodeURI(f).replace(/[?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()}):l(f),!t[u].test(c))throw TypeError('Expected "'+s.name+'" to match "'+s.pattern+'", but received "'+c+'"');o+=s.prefix+c}return o}}function l(e){return e.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function u(e){return e.sensitive?"":"i"}function c(e,t,r){n(t)||(r=t||r,t=[]);for(var i,o=(r=r||{}).strict,p=!1!==r.end,a="",c=0;c<e.length;c++){var s=e[c];if("string"==typeof s)a+=l(s);else{var f=l(s.prefix),h="(?:"+s.pattern+")";t.push(s),s.repeat&&(h+="(?:"+f+h+")*"),a+=h=s.optional?s.partial?f+"("+h+")?":"(?:"+f+"("+h+"))?":f+"("+h+")"}}var g=l(r.delimiter||"/"),d=a.slice(-g.length)===g;return o||(a=(d?a.slice(0,-g.length):a)+"(?:"+g+"(?=$))?"),p?a+="$":a+=o&&d?"":"(?="+g+"|$)",(i=RegExp("^"+a,u(r))).keys=t,i}}