frontexpress/frontexpress.min.js

3 lines
9.5 KiB
JavaScript
Raw Normal View History

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