-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpathparser.min.js
2 lines (2 loc) · 1.2 KB
/
pathparser.min.js
1
2
/* Copyright (c) 2014-2016 Dan Stillman - MIT License - https://github.com/dstillman/pathparser.js */
!function(r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():~String(this).indexOf("BackstagePass")?(EXPORTED_SYMBOLS=["PathParser"],PathParser=r()):PathParser=r()}(function(){"use strict";var r=function(r){this.rules=[],this.params=r};return r.prototype=function(){function r(r,t,e){var n={},a={};if(r.parts.length<t.length)return!1;for(var s=0;s<r.parts.length;s++){var i=r.parts[s],l=t[s];if(void 0!==l){if(":"==i.charAt(0)){n[i.substr(1)]=l;continue}if(i!==l)return!1}else{if(":"!=i.charAt(0))return!1;a[i.substr(1)]=!0}}for(var s=0;s<e.length;s++){var u=e[s].split("=",2),f=u[0];2!=u.length||n[f]||a[f]||(n[f]=u[1])}return n}return{add:function(r,t){this.rules.push({parts:r.replace(/^\//,"").split("/"),handler:t})},run:function(t){t.length&&(t=t.replace(/\/+/g,"/").replace(/^\/|\/($|\?)/,"").replace(/#.*$/,""));for(var e=t.split("?",2),n=e[0].split("/",50),a=e[1]?e[1].split("&",50):[],s=0;s<this.rules.length;s++){var i=this.rules[s],l=r(i,n,a);if(l){if(l.url=t,this.params)for(var u in l)this.params[u]=l[u];return i.handler&&i.handler.call(l),!0}}return!1}}}(),r});