frontexpress/frontexpress.min.js

3 lines
8.4 KiB
JavaScript
Raw Normal View History

var frontexpress=function(){"use strict";function e(e){var t=void 0,r=void 0,i=void 0,n=void 0;if(e&&e.length>0){if(1===e.length)n=a(e,1)[0];else{var o=a(e,2);t=o[0],n=o[1]}n instanceof f?i=n:(n instanceof d||"function"==typeof n)&&(r=n)}return{baseUri:t,middleware:r,router:i,which:n}}var t=["GET","POST","PUT","PATCH","DELETE"],r="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},i=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),a=function(){function e(e,t){var r=[],i=!0,n=!1,a=void 0;try{for(var o,u=e[Symbol.iterator]();!(i=(o=u.next()).done)&&(r.push(o.value),!t||r.length!==t);i=!0);}catch(e){n=!0,a=e}finally{try{!i&&u.return&&u.return()}finally{if(n)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")}}(),o=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)},u=function(){function e(){i(this,e)}return n(e,[{key:"fetch",value:function(e,t,r){var i=e.method,n=e.uri,a=e.headers,o=e.data,u=function(r){t(e,{status:200,statusText:"OK",responseText:r})},s=function(t){var i=t.status,n=t.statusText,a=t.errorThrown;r(e,{status:i,statusText:n,errorThrown:a,errors:"HTTP "+i+" "+(n||"")})},d=new XMLHttpRequest;d.onreadystatechange=function(){4===d.readyState&&(200===d.status?u(d.responseText):s({status:d.status,statusText:d.statusText}))};try{d.open(i,n,!0),a&&Object.keys(a).forEach(function(e){d.setRequestHeader(e,a[e])}),o?d.send(o):d.send()}catch(e){s({errorThrown:e})}}}]),e}(),s=function(){function e(){i(this,e),this.settings={"http requester":new u,"http GET transformer":{uri:function(e){var t=e.uri,r=(e.headers,e.data);if(!r)return t;var i=t,n="";if(/^(.*)(#.*)$/.exec(t)){var o=/^(.*)(#.*)$/.exec(t),u=a(o,3);i=u[1],n=u[2]}return(i=Object.keys(r).reduce(function(e,t,i){return e+=(0===i&&-1===e.indexOf("?")?"?":"&")+t+"="+r[t]},i))+n}}},this.rules={"http requester":function(e){if("function"!=typeof e.fetch)throw new TypeError("setting http requester has no fetch method")}}}return n(e,[{key:"set",value:function(e,t){var r=this.rules[e];r&&r(t),this.settings[e]=t}},{key:"get",value:function(e){return this.settings[e]}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";i(this,e),this.name=t}return n(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,a){i(this,e),this.router=t,this.uriPart=r,this.method=n,this.middleware=a,this.visited=!1}return n(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}(),f=function(){function a(e){i(this,a),this._baseUri=e,this._routes=[]}return n(a,[{key:"_add",value:function(e){return this._routes.push(e),this}},{key:"routes",value:function(e,t){return this._routes.filter(function(r){if(r.method&&r.method!==t)return!1;if(!r.uri||!e)return!0;var i=/^(.*)\?.*#.*|(.*)(?=\?|#)|(.*[^\?#])$/.exec(e),n=i[1]||i[2]||i[3];return r.uri instanceof RegExp?n.match(r.uri):r.uri===n})}},{key:"visited",value:function(){return this._routes.filter(function(e){return e.visited})}},{key:"use",value:function(e){if(!(e instanceof d)&&"function"!=typeof e)throw new TypeError("method takes at leas
//# sourceMappingURL=frontexpress.min.js.map