frontexpress/frontexpress.min.js

3 lines
9.3 KiB
JavaScript
Raw Normal View History

2017-06-22 19:17:18 +00:00
var frontexpress=function(){"use strict";function e(e,t){if(t.method&&t.method!==e.method)return!1;if(!t.uri||!e.uri)return!0;var r=/^(.*)\?.*#.*|(.*)(?=\?|#)|(.*[^\?#])$/.exec(e.uri),n=r[1]||r[2]||r[3];if(t.uri instanceof RegExp)return null!==n.match(t.uri);if(-1!==t.uri.indexOf(":")){for(var i=function(e){return!isNaN(parseFloat(e))&&isFinite(e)?Number.isInteger(e)?Number.parseInt(e,10):Number.parseFloat(e):e},a=[],u=/:([^\/\?]+)\??/g,o=u.exec(t.uri);null!=o;)a.push(o[1]),o=u.exec(t.uri);var s=t.uri.replace(/\/:[^\/]+\?/g,"(?:/([^/]+))?").replace(/:[^\/]+/g,"([^/]+)").replace("/","\\/"),f=n.match(new RegExp("^"+s+"$"));return!!f&&(e.params=Object.assign(e.params,a.reduce(function(e,t,r){var n=f[r+1];return n&&(n=-1!==n.indexOf(",")?n.split(",").map(function(e){return i(e)}):n=i(n)),e[t]=n,e},{})),!0)}return t.uri===n}function t(e,t){if("function"!=typeof e)throw new TypeError(t)}function r(e){var t,r,n,i,a=void 0,u=void 0,s=void 0,h=void 0,c=void 0;return 1===e.length?(t=e,r=o(t,1),c=r[0]):(n=e,i=o(n,2),a=i[0],c=i[1]),c instanceof d?s=c:c instanceof f||"function"==typeof c?u=c:c&&c.plugin&&"function"==typeof c.plugin&&(h=c),{baseUri:a,middleware:u,router:s,plugin:h,which:c}}var n=["GET","POST","PUT","PATCH","DELETE"],i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},u=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=function(){function e(e,t){var r=[],n=!0,i=!1,a=void 0;try{for(var u,o=e[Symbol.iterator]();!(n=(u=o.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){i=!0,a=e}finally{try{!n&&o.return&&o.return()}finally{if(i)throw a}}return r}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),s=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},f=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";a(this,e),this.name=t}return u(e,[{key:"entered",value:function(e){}},{key:"exited",value:function(e){}},{key:"updated",value:function(e,t){}},{key:"failed",value:function(e,t){}},{key:"next",value:function(){return!0}}]),e}(),h=function(){function e(t,r,n,i){a(this,e),this.router=t,this.uriPart=r,this.method=n,this.middleware=i,this.visited=!1}return u(e,[{key:"uri",get:function(){if(this.uriPart||this.method){if(this.uriPart instanceof RegExp)return this.uriPart;if(this.router.baseUri instanceof RegExp)return this.router.baseUri;if(this.router.baseUri){var e=this.router.baseUri.trim();return this.uriPart?(e+this.uriPart.trim()).replace(/\/{2,}/,"/"):e}return this.uriPart}}}]),e}(),d=function(){function e(t){a(this,e),this._baseUri=t,this._routes=[]}return u(e,[{key:"_add",value:function(e){return this._routes.push(e),this}},{key:"routes",value:function(e,t){t.params=t.params||{};var r=e.get("route matcher");return this._routes.filter(function(e){return r(t,e)})}},{key:"visited",value:function(){return this._routes.filter(function(e){return e.visited})}},{key:"use",value:function(e){if(!(e instanceof f)&&"function"!=typeof e)throw new TypeError("method takes at least a middleware");return this._add(new h(this,void 0,void 0,e)),this}},{key:"all",value:function(){for(var e=this,t=arguments.length,i=Array(t),a=0;a<t;a++)i[a]=arguments[a];if(!r(i).middleware)throw new TypeError("method takes at least a middleware");return n.forEach(function(t){e[t.toLowerCase()].apply(e,i)}),this}},{key:"baseUri",set:function(e){if(e){if(!this._baseUri)return void(this._baseUri=e);if(i(this._baseUri)!==(void 0===e?"undefined":i(e)))throw new TypeError("router cannot mix
//# sourceMappingURL=frontexpress.min.js.map