-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminiroute.min.js
2 lines (2 loc) · 1.15 KB
/
miniroute.min.js
1
2
function MiniRoute(){this.routes=[],this.map={},this.type={str:"([^/]+)",num:"([0-9]+)"},this.reg=/([^<]*)<(.+?):(.+?)>|([^<]+)/g}MiniRoute.prototype={addRoute:function(e,t,n){function r(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}for(var o,i="^",s=[];o=this.reg.exec(e);)o[1]&&(i+=r(o[1])),o[2]&&(s.push(o[2]),i+=this.type[o[3]]),o[4]&&(i+=r(o[4]));this.routes.push({regexp:i+"$",names:s,handler:n}),this.map[t]=e},addType:function(e,t){this.type[e]=t},url:function(e,t,n){for(var r,o="",i="";r=this.reg.exec(this.map[e]);)r[1]&&(o+=r[1]),r[2]&&(o+=encodeURIComponent(t[r[2]])),r[4]&&(o+=r[4]);for(var s in n)i+=s+"="+encodeURIComponent(n[s]);return i?o+"?"+i:o},urlEncoded:function(e,t,n){return encodeURI(this.url(e,t,n))},run:function(e){var t,n,r=this.routes,o={},i={},s=/([^&=]+)=([^&=]*)/g;if(n=e.match(/^([^\?#]*)\??([^\#]*)$/)){for(;t=s.exec(n[2]);)i[t[1]]=decodeURIComponent(t[2]);for(var u=0;u<r.length;u++)if(t=n[1].match(r[u].regexp)){for(var a=0;a<r[u].names.length;a++)o[r[u].names[a]]=decodeURIComponent(t[a+1]);return r[u].handler({url:n[1],qsa_str:n[2],params:o,qsa:i}),!0}}return!1}};
//# sourceMappingURL=miniroute.js/miniroute.js.map