/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/jups@0.1.4/build/jups.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,s=1,i=arguments.length;s<i;s++)for(var r in e=arguments[s])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(t,o,h,u){return new(h=h||Promise)(function(s,e){function i(t){try{n(u.next(t))}catch(t){e(t)}}function r(t){try{n(u.throw(t))}catch(t){e(t)}}function n(t){var e;t.done?s(t.value):((e=t.value)instanceof h?e:new h(function(t){t(e)})).then(i,r)}n((u=u.apply(t,o||[])).next())})},__generator=this&&this.__generator||function(s,i){var r,n,o,t,h={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(r)throw new TypeError("Generator is already executing.");for(;h;)try{if(r=1,n&&(o=2&e[0]?n.return:e[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,e[1])).done)return o;switch(n=0,o&&(e=[2&e[0],o.value]),e[0]){case 0:case 1:o=e;break;case 4:return h.label++,{value:e[1],done:!1};case 5:h.label++,n=e[1],e=[0];continue;case 7:e=h.ops.pop(),h.trys.pop();continue;default:if(!(o=0<(o=h.trys).length&&o[o.length-1])&&(6===e[0]||2===e[0])){h=0;continue}if(3===e[0]&&(!o||e[1]>o[0]&&e[1]<o[3])){h.label=e[1];break}if(6===e[0]&&h.label<o[1]){h.label=o[1],o=e;break}if(o&&h.label<o[2]){h.label=o[2],h.ops.push(e);break}o[2]&&h.ops.pop(),h.trys.pop();continue}e=i.call(s,h)}catch(t){e=[6,t],n=0}finally{r=o=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}},response_1=require("./response"),request_1=require("./request"),http_1=require("http"),https_1=require("https"),middleware_1=require("./middleware"),subapps_1=require("./subapps"),routes_1=require("./routes"),utils_1=require("./utils");function jups(t){return new jups.Jups(t)}!function(t){var e=(o.prototype.route=function(t,e,s){var i,r;return e instanceof RegExp?i=e:(e.startsWith("/")||(e="/"+e),i=routes_1.generateRouteRegex(e),r=utils_1.generateVariables(e)),this.routes.push({method:t,route:e,regex:i,callback:s,variables:r}),this},o.prototype.use=function(t){for(var e=[],s=1;s<arguments.length;s++)e[s-1]=arguments[s];if((t instanceof o||"function"==typeof t)&&(e.push(t),t="/"),!e.length)return console.trace("WARNING: Missing instance of Jups."),this;if(!t)return console.trace("WARNING: Missing base."),this;for(var i=t instanceof RegExp?t:routes_1.generateRouteRegex(t,!0),r=t instanceof RegExp?void 0:utils_1.generateVariables(t),n=0;n<e.length;n++)e[n]instanceof o?this.subApps.push({regex:i,base:t,app:e[n],variables:r}):this.middlewares.push({regex:i,route:t,callback:e[n],variables:r});return this},o.prototype.otherwise=function(t){return this._otherwise=t,this},o.prototype.error=function(t){return this._error=t,this},o.prototype.listen=function(t,e){return void 0===t&&(t=80),void 0===e&&(e=443),this._server.listen(t),this._sserver&&this._sserver.listen(e),this},o.prototype._listener=function(o,h){return __awaiter(this,void 0,void 0,function(){var e,s,i,r,n;return __generator(this,function(t){switch(t.label){case 0:if(!o.url)return[2];for(e=/(?:\?|&|;)([^=|&|;]+)(?:=([^&|;]+))?/g;null!==(s=e.exec(o.url));)s.index===e.lastIndex&&e.lastIndex++,o.query[s[1]]=s[2]||"";if(i=o.url.replace(e,""),this.subApps.length&&subapps_1.handleSubApps(this,o,h,i),this.middlewares.length&&middleware_1.fetchMiddleware(this,o,i),this.routes.length&&routes_1.handleRoutes(this,o,h,i),!o.routes.length){if(h.instantiated)return[2];this._otherwise&&this._otherwise(o,h)}return o.middlewares.length?[4,middleware_1.handleMiddleware(o,h)]:[3,2];case 1:t.sent(),t.label=2;case 2:r=0,t.label=3;case 3:if(!(r<o.routes.length))return[3,10];if(h.writableEnded)return[2];t.label=4;case 4:return t.trys.push([4,6,,9]),[4,Promise.resolve(o.routes[r].callback(o,h))];case 5:return t.sent(),[3,9];case 6:return n=t.sent(),o.routeErrorHandler?[4,Promise.resolve(o.routeErrorHandler(o,h,n))]:[3,8];case 7:t.sent(),t.label=8;case 8:return[3,9];case 9:return r++,[3,3];case 10:return[2]}})})},o);function o(t){var e,s=this;void 0===t&&(t={}),this.routes=[],this.subApps=[],this.middlewares=[],e=t.ssl&&t.ssl.redirect?function(t,e){e.setHeader("Location","https://"+t.headers.host+t.url),e.statusCode=302}:function(t,e){return s._listener(t,e)},this._server=http_1.createServer({ServerResponse:response_1.Response,IncomingMessage:request_1.Request},e),t.ssl&&(this._sserver=https_1.createServer(__assign({ServerResponse:response_1.Response,IncomingMessage:request_1.Request},t.ssl),function(t,e){s._listener(t,e)})),t.noOtherwise||(this._otherwise=function(t,e){return e.status(404).end()}),t.noErrorHandler||(this._error=function(t,e,s){return e.status(500).end(s)}),this.all=this.route.bind(this,"ALL"),this.get=this.route.bind(this,"GET"),this.head=this.route.bind(this,"HEAD"),this.patch=this.route.bind(this,"PATCH"),this.options=this.route.bind(this,"OPTIONS"),this.connect=this.route.bind(this,"CONNECT"),this.delete=this.route.bind(this,"DELETE"),this.trace=this.route.bind(this,"TRACE"),this.post=this.route.bind(this,"POST"),this.put=this.route.bind(this,"PUT"),this.acl=this.route.bind(this,"ACL"),this.bind=this.route.bind(this,"BIND"),this.checkout=this.route.bind(this,"CHECKOUT"),this.copy=this.route.bind(this,"COPY"),this.link=this.route.bind(this,"LINK"),this.lock=this.route.bind(this,"LOCK"),this.msearch=this.route.bind(this,"M-SEARCH"),this.merge=this.route.bind(this,"MERGE"),this.mkcol=this.route.bind(this,"MKCOL"),this.move=this.route.bind(this,"MOVE"),this.notify=this.route.bind(this,"NOTIFY"),this.propfind=this.route.bind(this,"PROPFIND"),this.proppatch=this.route.bind(this,"PROPPATCH"),this.purge=this.route.bind(this,"PURGE"),this.rebind=this.route.bind(this,"REBIND"),this.report=this.route.bind(this,"REPORT"),this.search=this.route.bind(this,"SEARCH"),this.source=this.route.bind(this,"SOURCE"),this.subscribe=this.route.bind(this,"SUBSCRIBE"),this.unbind=this.route.bind(this,"UNBIND"),this.unlink=this.route.bind(this,"UNLINK"),this.unlock=this.route.bind(this,"UNLOCK"),this.mkactivity=this.route.bind(this,"MKACTIVITY"),this.mkcalendar=this.route.bind(this,"MKCALENDAR"),this.unsubscribe=this.route.bind(this,"UNSUBSCRIBE")}t.Jups=e}(jups=jups||{}),module.exports=jups;