module.exports=pathToRegexp,module.exports.parse=parse,module.exports.compile=function compile(e,t){return tokensToFunction(parse(e,t))},module.exports.tokensToFunction=tokensToFunction,module.exports.tokensToRegExp=tokensToRegExp;var e="/",t="./",r=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");function parse(n,o){for(var p,a=[],i=0,s=0,l="",g=o&&o.delimiter||e,c=o&&o.delimiters||t,f=!1;null!==(p=r.exec(n));){var u=p[0],x=p[1],h=p.index;if(l+=n.slice(s,h),s=h+u.length,x)l+=x[1],f=!0;else{var m="",d=n[s],v=p[2],y=p[3],E=p[4],T=p[5];if(!f&&l.length){var w=l.length-1;c.indexOf(l[w])>-1&&(m=l[w],l=l.slice(0,w))}l&&(a.push(l),l="",f=!1);var R=""!==m&&void 0!==d&&d!==m,S="+"===T||"*"===T,b="?"===T||"*"===T,k=m||g,$=y||E;a.push({name:v||i++,prefix:m,delimiter:k,optional:b,repeat:S,partial:R,pattern:$?escapeGroup($):"[^"+escapeString(k)+"]+?"})}}return(l||s<n.length)&&a.push(l+n.substr(s)),a}function tokensToFunction(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="",p=n&&n.encode||encodeURIComponent,a=0;a<e.length;a++){var i=e[a];if("string"!=typeof i){var s,l=r?r[i.name]:void 0;if(Array.isArray(l)){if(!i.repeat)throw new TypeError('Expected "'+i.name+'" to not repeat, but got array');if(0===l.length){if(i.optional)continue;throw new TypeError('Expected "'+i.name+'" to not be empty')}for(var g=0;g<l.length;g++){if(s=p(l[g],i),!t[a].test(s))throw new TypeError('Expected all "'+i.name+'" to match "'+i.pattern+'"');o+=(0===g?i.prefix:i.delimiter)+s}}else if("string"!=typeof l&&"number"!=typeof l&&"boolean"!=typeof l){if(!i.optional)throw new TypeError('Expected "'+i.name+'" to be '+(i.repeat?"an array":"a string"));i.partial&&(o+=i.prefix)}else{if(s=p(String(l),i),!t[a].test(s))throw new TypeError('Expected "'+i.name+'" to match "'+i.pattern+'", but got "'+s+'"');o+=i.prefix+s}}else o+=i}return o}}function escapeString(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function escapeGroup(e){return e.replace(/([=!:$/()])/g,"\\$1")}function flags(e){return e&&e.sensitive?"":"i"}function tokensToRegExp(r,n,o){for(var p=(o=o||{}).strict,a=!1!==o.start,i=!1!==o.end,s=escapeString(o.delimiter||e),l=o.delimiters||t,g=[].concat(o.endsWith||[]).map(escapeString).concat("$").join("|"),c=a?"^":"",f=0===r.length,u=0;u<r.length;u++){var x=r[u];if("string"==typeof x)c+=escapeString(x),f=u===r.length-1&&l.indexOf(x[x.length-1])>-1;else{var h=x.repeat?"(?:"+x.pattern+")(?:"+escapeString(x.delimiter)+"(?:"+x.pattern+"))*":x.pattern;n&&n.push(x),x.optional?x.partial?c+=escapeString(x.prefix)+"("+h+")?":c+="(?:"+escapeString(x.prefix)+"("+h+"))?":c+=escapeString(x.prefix)+"("+h+")"}}return i?(p||(c+="(?:"+s+")?"),c+="$"===g?"$":"(?="+g+")"):(p||(c+="(?:"+s+"(?="+g+"))?"),f||(c+="(?="+s+"|"+g+")")),new RegExp(c,flags(o))}function pathToRegexp(e,t,r){return e instanceof RegExp?function regexpToRegexp(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}(e,t):Array.isArray(e)?function arrayToRegexp(e,t,r){for(var n=[],o=0;o<e.length;o++)n.push(pathToRegexp(e[o],t,r).source);return new RegExp("(?:"+n.join("|")+")",flags(r))}(e,t,r):function stringToRegexp(e,t,r){return tokensToRegExp(parse(e,r),t,r)}(e,t,r)}