UNPKG

4.16 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.beta=t():e.beta=t()}("undefined"!=typeof self?self:this,(function(){return e={10:(e,t,r)=>{"use strict";var n=r(546);n.env.XMLHttpRequest=window.XMLHttpRequest,n.env.window=window,e.exports=n},546:(e,t,r)=>{var n=r(259),o="Content-Type",s="application/x-www-form-urlencoded",i="application/json; charset=utf-8";function u(e,t){return Object.assign(e.clone(),t)}function a(e){return(e||"").trim()}function c(e){return e&&"[object Function]"==={}.toString.call(e)}function f(e,t,r){if(!e||0===e.length)return r(t);var n=e.shift();if(!c(n))return f(e,t,r);n(t,(function(n){return!1===n?r(t):f(e,t,r)}))}var h,d=(h={parser:"",beforehooks:[],afterhooks:[],baseurl:"",query:{},meta:{},clone:function(){return Object.assign({},this,{query:Object.assign({},this.query),meta:Object.assign({},this.meta)})},addQuery:function(e,t){var r=this.clone();return r.query[e]=t,r},removeQuery:function(e){var t=this.clone();return void 0!==t.query[e]&&(t.query[e]=void 0),t},withCredentials:function(e){return u(this,{withCredentials:e})},setQuery:function(e){return u(this,{query:e})},clearHooks:function(){return u(this,{beforehooks:[],afterhooks:[]})},beforeHook:function(e){var t=this.beforehooks.slice();return t.push(e),u(this,{beforehooks:t})},afterHook:function(e){var t=this.afterhooks.slice();return t.push(e),u(this,{afterhooks:t})},setHeader:function(e){return(e=Object.assign({},this.headers,e))[o]=void 0,u(this,{headers:e})}},["put","head","patch","delete","post","get"].map((function(e){h[e]=function(t,r,h){return function(e,t,r){r=r||function(){},c(t)&&(r=t,t=void 0);var u,a=new Promise((function(e){u=function(t){try{r(t.error,t.body,t.code)}catch(e){}e(t)}}));return t&&((e=e.clone()).body=t,e.content_type===i&&(e.body=p.Jsonify(t)),e.content_type===s&&(e.body=n.stringify(t))),f(e.beforehooks.slice(),{request:e},(function(t){if(t.error)return u({body:void 0,code:0,error:t.error});!function(e,t){var r=n.stringify(e.query);r&&(r="?"+r);var s=new p.XMLHttpRequest;for(var i in s.onreadystatechange=function(e){4===s.readyState&&(0===s.status?t("network_error",s.responseText,s.status):t(void 0,s.responseText,s.status))},s.open(e.method,e.baseurl+r),s.withCredentials=e.withCredentials,e.headers)s.setRequestHeader(i,e.headers[i]);e.content_type&&s.setRequestHeader(o,e.content_type),s.send(e.body)}(t.request,(function(t,r,n){f(e.afterhooks.slice(),{request:e,code:n,body:r,err:t},(function(t){var r=t.body;if("json"==e.parser&&t.body)try{r=p.ParseJson(t.body)}catch(e){t.err=t.err||"invalid json"}var o=t.err;(n<200||n>299)&&(o="not 200"),u({body:r,code:t.code,error:o})}))}))})),a}(u(this,{method:e,baseurl:(d=this.baseurl,y=t,d=a(d),(y=a(y))&&d?y.startsWith("http://")||y.startsWith("https://")||y.startsWith("//")?y:(d.endsWith("/")||(d+="/"),y.startsWith("/")&&(y=y.substring(1)),d+y):d+y)}),r,h);var d,y}})),h.setBaseUrl=function(e){return u(this,{baseurl:e})},h.contentTypeJson=function(){return u(this,{content_type:i})},h.contentTypeForm=function(){return u(this,{content_type:s})},h.setContentType=function(e){return u(this,{content_type:a(e)})},h.setParser=function(e){return u(this,{parser:a(e)})},h.setBody=function(e){return u(this,{body:e})},h.setMeta=function(e,t){var r=this.clone();return r.meta[e]=t,r},h),p={XMLHttpRequest:{},Jsonify:JSON.stringify,ParseJson:JSON.parse};d.env=p,d.waterfall=f,e.exports=d},259:e=>{function t(e){return encodeURIComponent(e).replace(/[!'()*]/g,(function(e){return"%"+e.charCodeAt(0).toString(16)}))}function r(e,r){return null===r?t(e):[t(e),"=",t(r)].join("")}e.exports={stringify:function(e){if(!e)return"";for(var n=Object.keys(e),o=[],s=0;s<n.length;s++){var i=n[s],u="",a=e[i];if(void 0!==a){if(null===a)u=t(i);else if(Array.isArray(a)){for(var c=[],f=0;f<a.length;f++)void 0!==a[f]&&c.push(r(i,a[f],c.length));u=c.join("&")}else u=t(i)+"="+t(a);u.length>0&&o.push(u)}}return o.join("&")}}}},t={},function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}(10);var e,t}));
\No newline at end of file