🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

ajax-client

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajax-client - npm Package Compare versions

Comparing version

to
2.0.2

2

lib/ajax-client.js
/*! For license information please see ajax-client.js.LICENSE */
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var r in s)("object"==typeof exports?exports:t)[r]=s[r]}}(this,(function(){return function(t){var e={};function s(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,s),n.l=!0,n.exports}return s.m=t,s.c=e,s.d=function(t,e,r){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(s.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)s.d(r,n,function(e){return t[e]}.bind(null,n));return r},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="/",s(s.s=0)}([function(t,e,s){t.exports=s(9)},function(t,e,s){"use strict";var r=s(2),n=s(5);function o(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}e.parse=v,e.resolve=function(t,e){return v(t,!1,!0).resolve(e)},e.resolveObject=function(t,e){return t?v(t,!1,!0).resolveObject(e):e},e.format=function(t){n.isString(t)&&(t=v(t));return t instanceof o?t.format():o.prototype.format.call(t)},e.Url=o;var a=/^([a-z0-9.+-]+:)/i,i=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,h=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),u=["'"].concat(h),p=["%","/","?",";","#"].concat(u),l=["/","?","#"],f=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,y={javascript:!0,"javascript:":!0},m={javascript:!0,"javascript:":!0},g={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},x=s(6);function v(t,e,s){if(t&&n.isObject(t)&&t instanceof o)return t;var r=new o;return r.parse(t,e,s),r}o.prototype.parse=function(t,e,s){if(!n.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var o=t.indexOf("?"),i=-1!==o&&o<t.indexOf("#")?"?":"#",h=t.split(i);h[0]=h[0].replace(/\\/g,"/");var v=t=h.join(i);if(v=v.trim(),!s&&1===t.split("#").length){var j=c.exec(v);if(j)return this.path=v,this.href=v,this.pathname=j[1],j[2]?(this.search=j[2],this.query=e?x.parse(this.search.substr(1)):this.search.substr(1)):e&&(this.search="",this.query={}),this}var b=a.exec(v);if(b){var w=(b=b[0]).toLowerCase();this.protocol=w,v=v.substr(b.length)}if(s||b||v.match(/^\/\/[^@\/]+@[^@\/]+/)){var O="//"===v.substr(0,2);!O||b&&m[b]||(v=v.substr(2),this.slashes=!0)}if(!m[b]&&(O||b&&!g[b])){for(var C,T,_=-1,P=0;P<l.length;P++){-1!==(S=v.indexOf(l[P]))&&(-1===_||S<_)&&(_=S)}-1!==(T=-1===_?v.lastIndexOf("@"):v.lastIndexOf("@",_))&&(C=v.slice(0,T),v=v.slice(T+1),this.auth=decodeURIComponent(C)),_=-1;for(P=0;P<p.length;P++){var S;-1!==(S=v.indexOf(p[P]))&&(-1===_||S<_)&&(_=S)}-1===_&&(_=v.length),this.host=v.slice(0,_),v=v.slice(_),this.parseHost(),this.hostname=this.hostname||"";var A="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!A)for(var I=this.hostname.split(/\./),U=(P=0,I.length);P<U;P++){var E=I[P];if(E&&!E.match(f)){for(var q="",F=0,R=E.length;F<R;F++)E.charCodeAt(F)>127?q+="x":q+=E[F];if(!q.match(f)){var k=I.slice(0,P),L=I.slice(P+1),N=E.match(d);N&&(k.push(N[1]),L.unshift(N[2])),L.length&&(v="/"+L.join(".")+v),this.hostname=k.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),A||(this.hostname=r.toASCII(this.hostname));var M=this.port?":"+this.port:"",J=this.hostname||"";this.host=J+M,this.href+=this.host,A&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==v[0]&&(v="/"+v))}if(!y[w])for(P=0,U=u.length;P<U;P++){var H=u[P];if(-1!==v.indexOf(H)){var D=encodeURIComponent(H);D===H&&(D=escape(H)),v=v.split(H).join(D)}}var $=v.indexOf("#");-1!==$&&(this.hash=v.substr($),v=v.slice(0,$));var z=v.indexOf("?");if(-1!==z?(this.search=v.substr(z),this.query=v.substr(z+1),e&&(this.query=x.parse(this.query)),v=v.slice(0,z)):e&&(this.search="",this.query={}),v&&(this.pathname=v),g[w]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){M=this.pathname||"";var B=this.search||"";this.path=M+B}return this.href=this.format(),this},o.prototype.format=function(){var t=this.auth||"";t&&(t=(t=encodeURIComponent(t)).replace(/%3A/i,":"),t+="@");var e=this.protocol||"",s=this.pathname||"",r=this.hash||"",o=!1,a="";this.host?o=t+this.host:this.hostname&&(o=t+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(o+=":"+this.port)),this.query&&n.isObject(this.query)&&Object.keys(this.query).length&&(a=x.stringify(this.query));var i=this.search||a&&"?"+a||"";return e&&":"!==e.substr(-1)&&(e+=":"),this.slashes||(!e||g[e])&&!1!==o?(o="//"+(o||""),s&&"/"!==s.charAt(0)&&(s="/"+s)):o||(o=""),r&&"#"!==r.charAt(0)&&(r="#"+r),i&&"?"!==i.charAt(0)&&(i="?"+i),e+o+(s=s.replace(/[?#]/g,(function(t){return encodeURIComponent(t)})))+(i=i.replace("#","%23"))+r},o.prototype.resolve=function(t){return this.resolveObject(v(t,!1,!0)).format()},o.prototype.resolveObject=function(t){if(n.isString(t)){var e=new o;e.parse(t,!1,!0),t=e}for(var s=new o,r=Object.keys(this),a=0;a<r.length;a++){var i=r[a];s[i]=this[i]}if(s.hash=t.hash,""===t.href)return s.href=s.format(),s;if(t.slashes&&!t.protocol){for(var c=Object.keys(t),h=0;h<c.length;h++){var u=c[h];"protocol"!==u&&(s[u]=t[u])}return g[s.protocol]&&s.hostname&&!s.pathname&&(s.path=s.pathname="/"),s.href=s.format(),s}if(t.protocol&&t.protocol!==s.protocol){if(!g[t.protocol]){for(var p=Object.keys(t),l=0;l<p.length;l++){var f=p[l];s[f]=t[f]}return s.href=s.format(),s}if(s.protocol=t.protocol,t.host||m[t.protocol])s.pathname=t.pathname;else{for(var d=(t.pathname||"").split("/");d.length&&!(t.host=d.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==d[0]&&d.unshift(""),d.length<2&&d.unshift(""),s.pathname=d.join("/")}if(s.search=t.search,s.query=t.query,s.host=t.host||"",s.auth=t.auth,s.hostname=t.hostname||t.host,s.port=t.port,s.pathname||s.search){var y=s.pathname||"",x=s.search||"";s.path=y+x}return s.slashes=s.slashes||t.slashes,s.href=s.format(),s}var v=s.pathname&&"/"===s.pathname.charAt(0),j=t.host||t.pathname&&"/"===t.pathname.charAt(0),b=j||v||s.host&&t.pathname,w=b,O=s.pathname&&s.pathname.split("/")||[],C=(d=t.pathname&&t.pathname.split("/")||[],s.protocol&&!g[s.protocol]);if(C&&(s.hostname="",s.port=null,s.host&&(""===O[0]?O[0]=s.host:O.unshift(s.host)),s.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===d[0]?d[0]=t.host:d.unshift(t.host)),t.host=null),b=b&&(""===d[0]||""===O[0])),j)s.host=t.host||""===t.host?t.host:s.host,s.hostname=t.hostname||""===t.hostname?t.hostname:s.hostname,s.search=t.search,s.query=t.query,O=d;else if(d.length)O||(O=[]),O.pop(),O=O.concat(d),s.search=t.search,s.query=t.query;else if(!n.isNullOrUndefined(t.search)){if(C)s.hostname=s.host=O.shift(),(A=!!(s.host&&s.host.indexOf("@")>0)&&s.host.split("@"))&&(s.auth=A.shift(),s.host=s.hostname=A.shift());return s.search=t.search,s.query=t.query,n.isNull(s.pathname)&&n.isNull(s.search)||(s.path=(s.pathname?s.pathname:"")+(s.search?s.search:"")),s.href=s.format(),s}if(!O.length)return s.pathname=null,s.search?s.path="/"+s.search:s.path=null,s.href=s.format(),s;for(var T=O.slice(-1)[0],_=(s.host||t.host||O.length>1)&&("."===T||".."===T)||""===T,P=0,S=O.length;S>=0;S--)"."===(T=O[S])?O.splice(S,1):".."===T?(O.splice(S,1),P++):P&&(O.splice(S,1),P--);if(!b&&!w)for(;P--;P)O.unshift("..");!b||""===O[0]||O[0]&&"/"===O[0].charAt(0)||O.unshift(""),_&&"/"!==O.join("/").substr(-1)&&O.push("");var A,I=""===O[0]||O[0]&&"/"===O[0].charAt(0);C&&(s.hostname=s.host=I?"":O.length?O.shift():"",(A=!!(s.host&&s.host.indexOf("@")>0)&&s.host.split("@"))&&(s.auth=A.shift(),s.host=s.hostname=A.shift()));return(b=b||s.host&&O.length)&&!I&&O.unshift(""),O.length?s.pathname=O.join("/"):(s.pathname=null,s.path=null),n.isNull(s.pathname)&&n.isNull(s.search)||(s.path=(s.pathname?s.pathname:"")+(s.search?s.search:"")),s.auth=t.auth||s.auth,s.slashes=s.slashes||t.slashes,s.href=s.format(),s},o.prototype.parseHost=function(){var t=this.host,e=i.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},function(t,e,s){(function(t,r){var n;!function(o){e&&e.nodeType,t&&t.nodeType;var a="object"==typeof r&&r;a.global!==a&&a.window!==a&&a.self;var i,c=2147483647,h=/^xn--/,u=/[^\x20-\x7E]/,p=/[\x2E\u3002\uFF0E\uFF61]/g,l={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},f=Math.floor,d=String.fromCharCode;function y(t){throw new RangeError(l[t])}function m(t,e){for(var s=t.length,r=[];s--;)r[s]=e(t[s]);return r}function g(t,e){var s=t.split("@"),r="";return s.length>1&&(r=s[0]+"@",t=s[1]),r+m((t=t.replace(p,".")).split("."),e).join(".")}function x(t){for(var e,s,r=[],n=0,o=t.length;n<o;)(e=t.charCodeAt(n++))>=55296&&e<=56319&&n<o?56320==(64512&(s=t.charCodeAt(n++)))?r.push(((1023&e)<<10)+(1023&s)+65536):(r.push(e),n--):r.push(e);return r}function v(t){return m(t,(function(t){var e="";return t>65535&&(e+=d((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=d(t)})).join("")}function j(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function b(t,e,s){var r=0;for(t=s?f(t/700):t>>1,t+=f(t/e);t>455;r+=36)t=f(t/35);return f(r+36*t/(t+38))}function w(t){var e,s,r,n,o,a,i,h,u,p,l,d=[],m=t.length,g=0,x=128,j=72;for((s=t.lastIndexOf("-"))<0&&(s=0),r=0;r<s;++r)t.charCodeAt(r)>=128&&y("not-basic"),d.push(t.charCodeAt(r));for(n=s>0?s+1:0;n<m;){for(o=g,a=1,i=36;n>=m&&y("invalid-input"),((h=(l=t.charCodeAt(n++))-48<10?l-22:l-65<26?l-65:l-97<26?l-97:36)>=36||h>f((c-g)/a))&&y("overflow"),g+=h*a,!(h<(u=i<=j?1:i>=j+26?26:i-j));i+=36)a>f(c/(p=36-u))&&y("overflow"),a*=p;j=b(g-o,e=d.length+1,0==o),f(g/e)>c-x&&y("overflow"),x+=f(g/e),g%=e,d.splice(g++,0,x)}return v(d)}function O(t){var e,s,r,n,o,a,i,h,u,p,l,m,g,v,w,O=[];for(m=(t=x(t)).length,e=128,s=0,o=72,a=0;a<m;++a)(l=t[a])<128&&O.push(d(l));for(r=n=O.length,n&&O.push("-");r<m;){for(i=c,a=0;a<m;++a)(l=t[a])>=e&&l<i&&(i=l);for(i-e>f((c-s)/(g=r+1))&&y("overflow"),s+=(i-e)*g,e=i,a=0;a<m;++a)if((l=t[a])<e&&++s>c&&y("overflow"),l==e){for(h=s,u=36;!(h<(p=u<=o?1:u>=o+26?26:u-o));u+=36)w=h-p,v=36-p,O.push(d(j(p+w%v,0))),h=f(w/v);O.push(d(j(h,0))),o=b(s,g,r==n),s=0,++r}++s,++e}return O.join("")}i={version:"1.4.1",ucs2:{decode:x,encode:v},decode:w,encode:O,toASCII:function(t){return g(t,(function(t){return u.test(t)?"xn--"+O(t):t}))},toUnicode:function(t){return g(t,(function(t){return h.test(t)?w(t.slice(4).toLowerCase()):t}))}},void 0===(n=function(){return i}.call(e,s,e,t))||(t.exports=n)}()}).call(this,s(3)(t),s(4))},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e){var s;s=function(){return this}();try{s=s||new Function("return this")()}catch(t){"object"==typeof window&&(s=window)}t.exports=s},function(t,e,s){"use strict";t.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},function(t,e,s){"use strict";e.decode=e.parse=s(7),e.encode=e.stringify=s(8)},function(t,e,s){"use strict";function r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.exports=function(t,e,s,o){e=e||"&",s=s||"=";var a={};if("string"!=typeof t||0===t.length)return a;var i=/\+/g;t=t.split(e);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var h=t.length;c>0&&h>c&&(h=c);for(var u=0;u<h;++u){var p,l,f,d,y=t[u].replace(i,"%20"),m=y.indexOf(s);m>=0?(p=y.substr(0,m),l=y.substr(m+1)):(p=y,l=""),f=decodeURIComponent(p),d=decodeURIComponent(l),r(a,f)?n(a[f])?a[f].push(d):a[f]=[a[f],d]:a[f]=d}return a};var n=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},function(t,e,s){"use strict";var r=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};t.exports=function(t,e,s,i){return e=e||"&",s=s||"=",null===t&&(t=void 0),"object"==typeof t?o(a(t),(function(a){var i=encodeURIComponent(r(a))+s;return n(t[a])?o(t[a],(function(t){return i+encodeURIComponent(r(t))})).join(e):i+encodeURIComponent(r(t[a]))})).join(e):i?encodeURIComponent(r(i))+s+encodeURIComponent(r(t)):""};var n=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function o(t,e){if(t.map)return t.map(e);for(var s=[],r=0;r<t.length;r++)s.push(e(t[r],r));return s}var a=Object.keys||function(t){var e=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.push(s);return e}},function(t,e,s){"use strict";s.r(e),s.d(e,"AjaxClient",(function(){return r})),s.d(e,"AjaxClient2",(function(){return o}));class r{constructor(){}getAsync(t){t.type="get",this.ajax(t)}postAsync(t){t.type="post",this.ajax(t)}async get(t){if(t.type="get","application/json"===t.contentType)if("String"===this.typeOf(t.data));else{const e=t.data;t.data=JSON.stringify(e)}return new Promise(e=>{t.success=(t,s)=>{e({success:!0,data:t,response:s})},t.error=(t,s)=>{e({success:!1,cause:"error",error:t,response:s})},t.timeout=t=>{e({success:!1,cause:"timeout",error:t,response:null})},this.ajax(t)})}async post(t){if(t.type="post","application/json"===t.contentType)if("String"===this.typeOf(t.data));else{const e=t.data;t.data=JSON.stringify(e)}return new Promise(e=>{t.success=t=>{e({success:!0,data:t})},t.error=t=>{e({success:!1,cause:"error",error:t})},t.timeout=t=>{e({success:!1,cause:"timeout",error:t})},this.ajax(t)})}ajax(t){const e=new XMLHttpRequest;if(!t)throw Error("Please specify options like #ajax(options)");if(!t.url)throw Error("Please specify url.");if(t.type&&"post"===t.type.toLowerCase())e.open("POST",t.url,!0);else{if(!t.type||"get"!==t.type.toLowerCase())throw Error("type:".concat(t.type," is not supported"));e.open("GET",t.url,!0)}if(t.dataType&&"json"===t.dataType)e.responseType="text";else{if(!t.dataType||"text"!==t.dataType)throw Error("Please check dataType:".concat(t.dataType,'. "json" or "text" is supported as dataType now.'));e.responseType="text"}if(t.contentType)try{e.setRequestHeader("Content-Type",t.contentType)}catch(e){throw Error("Invalid content type ".concat(t.contentType))}else if(t.type&&"post"===t.type.toLowerCase()||t.type&&"put"===t.type.toLowerCase())throw Error("Please specify contentType.");if(t.headers)for(const s in t.headers){const r=t.headers[s];e.setRequestHeader(s,r)}if(t.xhrFields){const{xhrFields:s}=t;!0===s.withCredentials&&(e.withCredentials=!0)}if(t.timeoutMillis&&(e.timeout=t.timeoutMillis),e.onload=s=>{if(200==e.status){let s="";s="json"==t.dataType?JSON.parse(e.response):e.response,t.success&&t.success(s,e)}else t.error&&t.error(s,e)},t.timeout&&(e.ontimeout=s=>{t.timeout(s,e)}),t.error&&(e.onerror=s=>{t.error(s,e)}),t.type&&"post"===t.type.toLowerCase()){if(!t.data)throw Error('.data is not specified.data must be specified on "POST" mode.');if(t.contentType.startsWith("application/x-www-form-urlencoded")){const s=(t=>{const e=[];for(const s in t){const r=t[s],n=encodeURIComponent(s)+"="+encodeURIComponent(r);e.push(n)}return e.join("&").replace(/%20/g,"+")})(t.data);e.send(s)}else e.send(t.data)}else t.type&&"get"===t.type.toLowerCase()&&e.send(null)}typeOf(t){return Object.prototype.toString.call(t).slice(8,-1)}}const{URLSearchParams:n}=s(1);class o{constructor(t){this.opt=t||{}}getAsync(t){t.type="get",this.ajax(t)}postAsync(t){t.type="post",this.ajax(t)}async get(t){if(t.type="get","application/json"===t.contentType)if("String"===this.typeOf(t.data));else{const e=t.data;t.data=JSON.stringify(e)}return new Promise(e=>{t.success=(t,s)=>{e({success:!0,data:t,response:s})},t.error=(t,s,r,n)=>{e({success:!1,cause:r,error:n,response:s})},t.timeout=(t,s,r,n)=>{e({success:!1,cause:r,error:n,response:s})},this.ajax(t)})}async post(t){if(t.type="post","application/json"===t.contentType)if("String"===this.typeOf(t.data));else{const e=t.data;t.data=JSON.stringify(e)}return new Promise(e=>{t.success=(t,s)=>{e({success:!0,data:t,response:s})},t.error=(t,s)=>{e({success:!1,cause:"error",error:t,response:s})},t.timeout=t=>{e({success:!1,cause:"timeout",error:t,response:null})},this.ajax(t)})}ajax(t){const e=this._createUrl(t),s=t.type,r=t.dataType,n=t.data,o=t.headers,a=t.contentType;let i=null;if(!e)throw Error("Please specify url.");if(s&&"post"===s.toLowerCase()&&(i=n,"jsonp"===r))throw new Error("type:'POST' and 'dataType:jsonp' are specified together.\n 'POST' and 'jsonp' can not be specified together");if(o&&"jsonp"===r)throw new Error("'headers' and 'dataType:jsonp' can not be specified together.\n Http headers cannot be sent when using jsonp.");const c={url:e,method:s,body:i,contentType:a};if(o&&(c.headers=o),"json"===r||"text"===r){return this._handleData(c,r,t)}if("jsonp"===r){return this._handleJsonp(c,t)}throw new Error("Please check dataType:".concat(r," dataType must be 'json' or 'jsonp'"))}_getFetchParam(t,e){const s=t.method.toUpperCase(),r={method:s,mode:"cors",cache:"no-cache",headers:{}};if(t.contentType)r.headers["Content-Type"]=t.contentType;else if("POST"===s||"PUT"===s)throw Error("Please specify contentType.");if(e.xhrFields){const{xhrFields:t}=e;!0===t.withCredentials&&(r.credentials="include")}if(t.credentials&&(r.credentials=t.credentials),t.headers)for(const e in t.headers){const s=t.headers[e];r.headers[e]=s}if(t.body)if(t.contentType.startsWith("application/x-www-form-urlencoded")){const e=t=>{const e=[];for(const s in t){const r=t[s],n=encodeURIComponent(s)+"="+encodeURIComponent(r);e.push(n)}return e.join("&").replace(/%20/g,"+")},s=e(t.body);r.body=s}else r.body=t.body;return r}_handleData(t,e,s){const r=new a,n=this._getFetchParam(t,s);return((t,s)=>new Promise((r,n)=>{s&&s.timeoutMillis&&setTimeout(()=>{n({data:null,cause:"timeout,".concat(s.timeoutMillis,"ms elapsed"),response:null})},s.timeoutMillis),t.then(t=>{t.ok?"json"===e?t.json().then(e=>{r({data:e,response:t})}).catch(e=>{n({data:null,cause:"client error,".concat(e),response:t})}):"text"===e&&t.text().then(e=>{r({data:e,response:t})}).catch(e=>{n({data:null,cause:"client error,".concat(e),response:t})}):"json"===e?t.json().then(e=>{n({data:e,cause:"server error,statusCode:".concat(t.status),response:t})}).catch(e=>{n({data:null,cause:"client error,".concat(e),response:t})}):"text"===e&&t.text().then(e=>{n({data:e,cause:"server error,statusCode:".concat(t.status),response:t})}).catch(e=>{n({data:null,cause:"client error,".concat(e),response:t})})}).catch(t=>{n({data:null,cause:"network error",response:null,err:t})})}))((this.opt.fetch||fetch)(t.url,n),s).then(t=>{r._success(t),s&&s.success&&s.success(t.data,t.response)}).catch(t=>{r._fail(t),"timeout"===t.cause?s&&s.timeout&&s.timeout(t.data,t.response,t.cause,t.err):s&&s.error&&s.error(t.data,t.response,t.cause,t.err)}),r}_handleJsonp(t,e){const s=new a,r=document.createElement("script"),n="ajaxclient2_".concat(this._createUUID());let o=t.url;o.indexOf("?")>=0?o+="&callback=".concat(n):o+="?callback=".concat(n),r.src=o,r.addEventListener("error",t=>{s._fail(t),e&&e.error&&e.error(t,null)}),window[n]=t=>{delete window[n],s._success({data:t,response:null}),e&&e.success&&e.success(t,null)};return(document.getElementsByTagName("head")?document.getElementsByTagName("head")[0]:document.body).appendChild(r),s}_createUrl(t){if(t.type&&"post"===t.type.toLowerCase())return t.url;if(t.type&&"get"===t.type.toLowerCase()){let e=t.url;if(t.data){const s=JSON.parse(t.data);e+="?";for(let t of Object.keys(s)){const r=s[t];e+="".concat(t,"=").concat(r,"&")}e=e.substring(0,e.length-1)}return e}throw Error("Invalid type ".concat(t.type," is not supported"))}_createUUID(){const t=(new Date).getTime();return"xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const s=(t+16*Math.random())%16|0;return("x"==e?s:3&s|8).toString(16)}))}typeOf(t){return Object.prototype.toString.call(t).slice(8,-1)}}class a{constructor(){this._successFunc=()=>{},this._failFunc=()=>{}}done(t){return this._successFunc=t,this}fail(t){return this._failFunc=t,this}_success(t){this._successFunc&&this._successFunc(t.data,t.response)}_fail(t){this._failFunc&&this._failFunc(t.data,t.response,t.cause,t.err)}}}])}));
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var r in s)("object"==typeof exports?exports:t)[r]=s[r]}}(this,(function(){return function(t){var e={};function s(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,s),n.l=!0,n.exports}return s.m=t,s.c=e,s.d=function(t,e,r){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(s.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)s.d(r,n,function(e){return t[e]}.bind(null,n));return r},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="/",s(s.s=0)}([function(t,e,s){t.exports=s(9)},function(t,e,s){"use strict";var r=s(2),n=s(5);function o(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}e.parse=v,e.resolve=function(t,e){return v(t,!1,!0).resolve(e)},e.resolveObject=function(t,e){return t?v(t,!1,!0).resolveObject(e):e},e.format=function(t){n.isString(t)&&(t=v(t));return t instanceof o?t.format():o.prototype.format.call(t)},e.Url=o;var a=/^([a-z0-9.+-]+:)/i,i=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,h=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),u=["'"].concat(h),p=["%","/","?",";","#"].concat(u),l=["/","?","#"],f=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,y={javascript:!0,"javascript:":!0},m={javascript:!0,"javascript:":!0},g={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},x=s(6);function v(t,e,s){if(t&&n.isObject(t)&&t instanceof o)return t;var r=new o;return r.parse(t,e,s),r}o.prototype.parse=function(t,e,s){if(!n.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var o=t.indexOf("?"),i=-1!==o&&o<t.indexOf("#")?"?":"#",h=t.split(i);h[0]=h[0].replace(/\\/g,"/");var v=t=h.join(i);if(v=v.trim(),!s&&1===t.split("#").length){var j=c.exec(v);if(j)return this.path=v,this.href=v,this.pathname=j[1],j[2]?(this.search=j[2],this.query=e?x.parse(this.search.substr(1)):this.search.substr(1)):e&&(this.search="",this.query={}),this}var b=a.exec(v);if(b){var w=(b=b[0]).toLowerCase();this.protocol=w,v=v.substr(b.length)}if(s||b||v.match(/^\/\/[^@\/]+@[^@\/]+/)){var O="//"===v.substr(0,2);!O||b&&m[b]||(v=v.substr(2),this.slashes=!0)}if(!m[b]&&(O||b&&!g[b])){for(var C,T,_=-1,P=0;P<l.length;P++){-1!==(S=v.indexOf(l[P]))&&(-1===_||S<_)&&(_=S)}-1!==(T=-1===_?v.lastIndexOf("@"):v.lastIndexOf("@",_))&&(C=v.slice(0,T),v=v.slice(T+1),this.auth=decodeURIComponent(C)),_=-1;for(P=0;P<p.length;P++){var S;-1!==(S=v.indexOf(p[P]))&&(-1===_||S<_)&&(_=S)}-1===_&&(_=v.length),this.host=v.slice(0,_),v=v.slice(_),this.parseHost(),this.hostname=this.hostname||"";var A="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!A)for(var I=this.hostname.split(/\./),U=(P=0,I.length);P<U;P++){var E=I[P];if(E&&!E.match(f)){for(var q="",F=0,R=E.length;F<R;F++)E.charCodeAt(F)>127?q+="x":q+=E[F];if(!q.match(f)){var k=I.slice(0,P),L=I.slice(P+1),N=E.match(d);N&&(k.push(N[1]),L.unshift(N[2])),L.length&&(v="/"+L.join(".")+v),this.hostname=k.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),A||(this.hostname=r.toASCII(this.hostname));var M=this.port?":"+this.port:"",J=this.hostname||"";this.host=J+M,this.href+=this.host,A&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==v[0]&&(v="/"+v))}if(!y[w])for(P=0,U=u.length;P<U;P++){var H=u[P];if(-1!==v.indexOf(H)){var D=encodeURIComponent(H);D===H&&(D=escape(H)),v=v.split(H).join(D)}}var $=v.indexOf("#");-1!==$&&(this.hash=v.substr($),v=v.slice(0,$));var z=v.indexOf("?");if(-1!==z?(this.search=v.substr(z),this.query=v.substr(z+1),e&&(this.query=x.parse(this.query)),v=v.slice(0,z)):e&&(this.search="",this.query={}),v&&(this.pathname=v),g[w]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){M=this.pathname||"";var B=this.search||"";this.path=M+B}return this.href=this.format(),this},o.prototype.format=function(){var t=this.auth||"";t&&(t=(t=encodeURIComponent(t)).replace(/%3A/i,":"),t+="@");var e=this.protocol||"",s=this.pathname||"",r=this.hash||"",o=!1,a="";this.host?o=t+this.host:this.hostname&&(o=t+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(o+=":"+this.port)),this.query&&n.isObject(this.query)&&Object.keys(this.query).length&&(a=x.stringify(this.query));var i=this.search||a&&"?"+a||"";return e&&":"!==e.substr(-1)&&(e+=":"),this.slashes||(!e||g[e])&&!1!==o?(o="//"+(o||""),s&&"/"!==s.charAt(0)&&(s="/"+s)):o||(o=""),r&&"#"!==r.charAt(0)&&(r="#"+r),i&&"?"!==i.charAt(0)&&(i="?"+i),e+o+(s=s.replace(/[?#]/g,(function(t){return encodeURIComponent(t)})))+(i=i.replace("#","%23"))+r},o.prototype.resolve=function(t){return this.resolveObject(v(t,!1,!0)).format()},o.prototype.resolveObject=function(t){if(n.isString(t)){var e=new o;e.parse(t,!1,!0),t=e}for(var s=new o,r=Object.keys(this),a=0;a<r.length;a++){var i=r[a];s[i]=this[i]}if(s.hash=t.hash,""===t.href)return s.href=s.format(),s;if(t.slashes&&!t.protocol){for(var c=Object.keys(t),h=0;h<c.length;h++){var u=c[h];"protocol"!==u&&(s[u]=t[u])}return g[s.protocol]&&s.hostname&&!s.pathname&&(s.path=s.pathname="/"),s.href=s.format(),s}if(t.protocol&&t.protocol!==s.protocol){if(!g[t.protocol]){for(var p=Object.keys(t),l=0;l<p.length;l++){var f=p[l];s[f]=t[f]}return s.href=s.format(),s}if(s.protocol=t.protocol,t.host||m[t.protocol])s.pathname=t.pathname;else{for(var d=(t.pathname||"").split("/");d.length&&!(t.host=d.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==d[0]&&d.unshift(""),d.length<2&&d.unshift(""),s.pathname=d.join("/")}if(s.search=t.search,s.query=t.query,s.host=t.host||"",s.auth=t.auth,s.hostname=t.hostname||t.host,s.port=t.port,s.pathname||s.search){var y=s.pathname||"",x=s.search||"";s.path=y+x}return s.slashes=s.slashes||t.slashes,s.href=s.format(),s}var v=s.pathname&&"/"===s.pathname.charAt(0),j=t.host||t.pathname&&"/"===t.pathname.charAt(0),b=j||v||s.host&&t.pathname,w=b,O=s.pathname&&s.pathname.split("/")||[],C=(d=t.pathname&&t.pathname.split("/")||[],s.protocol&&!g[s.protocol]);if(C&&(s.hostname="",s.port=null,s.host&&(""===O[0]?O[0]=s.host:O.unshift(s.host)),s.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===d[0]?d[0]=t.host:d.unshift(t.host)),t.host=null),b=b&&(""===d[0]||""===O[0])),j)s.host=t.host||""===t.host?t.host:s.host,s.hostname=t.hostname||""===t.hostname?t.hostname:s.hostname,s.search=t.search,s.query=t.query,O=d;else if(d.length)O||(O=[]),O.pop(),O=O.concat(d),s.search=t.search,s.query=t.query;else if(!n.isNullOrUndefined(t.search)){if(C)s.hostname=s.host=O.shift(),(A=!!(s.host&&s.host.indexOf("@")>0)&&s.host.split("@"))&&(s.auth=A.shift(),s.host=s.hostname=A.shift());return s.search=t.search,s.query=t.query,n.isNull(s.pathname)&&n.isNull(s.search)||(s.path=(s.pathname?s.pathname:"")+(s.search?s.search:"")),s.href=s.format(),s}if(!O.length)return s.pathname=null,s.search?s.path="/"+s.search:s.path=null,s.href=s.format(),s;for(var T=O.slice(-1)[0],_=(s.host||t.host||O.length>1)&&("."===T||".."===T)||""===T,P=0,S=O.length;S>=0;S--)"."===(T=O[S])?O.splice(S,1):".."===T?(O.splice(S,1),P++):P&&(O.splice(S,1),P--);if(!b&&!w)for(;P--;P)O.unshift("..");!b||""===O[0]||O[0]&&"/"===O[0].charAt(0)||O.unshift(""),_&&"/"!==O.join("/").substr(-1)&&O.push("");var A,I=""===O[0]||O[0]&&"/"===O[0].charAt(0);C&&(s.hostname=s.host=I?"":O.length?O.shift():"",(A=!!(s.host&&s.host.indexOf("@")>0)&&s.host.split("@"))&&(s.auth=A.shift(),s.host=s.hostname=A.shift()));return(b=b||s.host&&O.length)&&!I&&O.unshift(""),O.length?s.pathname=O.join("/"):(s.pathname=null,s.path=null),n.isNull(s.pathname)&&n.isNull(s.search)||(s.path=(s.pathname?s.pathname:"")+(s.search?s.search:"")),s.auth=t.auth||s.auth,s.slashes=s.slashes||t.slashes,s.href=s.format(),s},o.prototype.parseHost=function(){var t=this.host,e=i.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},function(t,e,s){(function(t,r){var n;!function(o){e&&e.nodeType,t&&t.nodeType;var a="object"==typeof r&&r;a.global!==a&&a.window!==a&&a.self;var i,c=2147483647,h=/^xn--/,u=/[^\x20-\x7E]/,p=/[\x2E\u3002\uFF0E\uFF61]/g,l={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},f=Math.floor,d=String.fromCharCode;function y(t){throw new RangeError(l[t])}function m(t,e){for(var s=t.length,r=[];s--;)r[s]=e(t[s]);return r}function g(t,e){var s=t.split("@"),r="";return s.length>1&&(r=s[0]+"@",t=s[1]),r+m((t=t.replace(p,".")).split("."),e).join(".")}function x(t){for(var e,s,r=[],n=0,o=t.length;n<o;)(e=t.charCodeAt(n++))>=55296&&e<=56319&&n<o?56320==(64512&(s=t.charCodeAt(n++)))?r.push(((1023&e)<<10)+(1023&s)+65536):(r.push(e),n--):r.push(e);return r}function v(t){return m(t,(function(t){var e="";return t>65535&&(e+=d((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=d(t)})).join("")}function j(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function b(t,e,s){var r=0;for(t=s?f(t/700):t>>1,t+=f(t/e);t>455;r+=36)t=f(t/35);return f(r+36*t/(t+38))}function w(t){var e,s,r,n,o,a,i,h,u,p,l,d=[],m=t.length,g=0,x=128,j=72;for((s=t.lastIndexOf("-"))<0&&(s=0),r=0;r<s;++r)t.charCodeAt(r)>=128&&y("not-basic"),d.push(t.charCodeAt(r));for(n=s>0?s+1:0;n<m;){for(o=g,a=1,i=36;n>=m&&y("invalid-input"),((h=(l=t.charCodeAt(n++))-48<10?l-22:l-65<26?l-65:l-97<26?l-97:36)>=36||h>f((c-g)/a))&&y("overflow"),g+=h*a,!(h<(u=i<=j?1:i>=j+26?26:i-j));i+=36)a>f(c/(p=36-u))&&y("overflow"),a*=p;j=b(g-o,e=d.length+1,0==o),f(g/e)>c-x&&y("overflow"),x+=f(g/e),g%=e,d.splice(g++,0,x)}return v(d)}function O(t){var e,s,r,n,o,a,i,h,u,p,l,m,g,v,w,O=[];for(m=(t=x(t)).length,e=128,s=0,o=72,a=0;a<m;++a)(l=t[a])<128&&O.push(d(l));for(r=n=O.length,n&&O.push("-");r<m;){for(i=c,a=0;a<m;++a)(l=t[a])>=e&&l<i&&(i=l);for(i-e>f((c-s)/(g=r+1))&&y("overflow"),s+=(i-e)*g,e=i,a=0;a<m;++a)if((l=t[a])<e&&++s>c&&y("overflow"),l==e){for(h=s,u=36;!(h<(p=u<=o?1:u>=o+26?26:u-o));u+=36)w=h-p,v=36-p,O.push(d(j(p+w%v,0))),h=f(w/v);O.push(d(j(h,0))),o=b(s,g,r==n),s=0,++r}++s,++e}return O.join("")}i={version:"1.4.1",ucs2:{decode:x,encode:v},decode:w,encode:O,toASCII:function(t){return g(t,(function(t){return u.test(t)?"xn--"+O(t):t}))},toUnicode:function(t){return g(t,(function(t){return h.test(t)?w(t.slice(4).toLowerCase()):t}))}},void 0===(n=function(){return i}.call(e,s,e,t))||(t.exports=n)}()}).call(this,s(3)(t),s(4))},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e){var s;s=function(){return this}();try{s=s||new Function("return this")()}catch(t){"object"==typeof window&&(s=window)}t.exports=s},function(t,e,s){"use strict";t.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},function(t,e,s){"use strict";e.decode=e.parse=s(7),e.encode=e.stringify=s(8)},function(t,e,s){"use strict";function r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.exports=function(t,e,s,o){e=e||"&",s=s||"=";var a={};if("string"!=typeof t||0===t.length)return a;var i=/\+/g;t=t.split(e);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var h=t.length;c>0&&h>c&&(h=c);for(var u=0;u<h;++u){var p,l,f,d,y=t[u].replace(i,"%20"),m=y.indexOf(s);m>=0?(p=y.substr(0,m),l=y.substr(m+1)):(p=y,l=""),f=decodeURIComponent(p),d=decodeURIComponent(l),r(a,f)?n(a[f])?a[f].push(d):a[f]=[a[f],d]:a[f]=d}return a};var n=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},function(t,e,s){"use strict";var r=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};t.exports=function(t,e,s,i){return e=e||"&",s=s||"=",null===t&&(t=void 0),"object"==typeof t?o(a(t),(function(a){var i=encodeURIComponent(r(a))+s;return n(t[a])?o(t[a],(function(t){return i+encodeURIComponent(r(t))})).join(e):i+encodeURIComponent(r(t[a]))})).join(e):i?encodeURIComponent(r(i))+s+encodeURIComponent(r(t)):""};var n=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function o(t,e){if(t.map)return t.map(e);for(var s=[],r=0;r<t.length;r++)s.push(e(t[r],r));return s}var a=Object.keys||function(t){var e=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.push(s);return e}},function(t,e,s){"use strict";s.r(e),s.d(e,"AjaxClient",(function(){return r})),s.d(e,"AjaxClient2",(function(){return o}));class r{constructor(){}getAsync(t){t.type="get",this.ajax(t)}postAsync(t){t.type="post",this.ajax(t)}async get(t){if(t.type="get","application/json"===t.contentType)if("String"===this.typeOf(t.data));else{const e=t.data;t.data=JSON.stringify(e)}return new Promise(e=>{t.success=(t,s)=>{e({success:!0,data:t,response:s})},t.error=(t,s)=>{e({success:!1,cause:"error",error:t,response:s})},t.timeout=t=>{e({success:!1,cause:"timeout",error:t,response:null})},this.ajax(t)})}async post(t){if(t.type="post","application/json"===t.contentType)if("String"===this.typeOf(t.data));else{const e=t.data;t.data=JSON.stringify(e)}return new Promise(e=>{t.success=t=>{e({success:!0,data:t})},t.error=t=>{e({success:!1,cause:"error",error:t})},t.timeout=t=>{e({success:!1,cause:"timeout",error:t})},this.ajax(t)})}ajax(t){const e=new XMLHttpRequest;if(!t)throw Error("Please specify options like #ajax(options)");if(!t.url)throw Error("Please specify url.");if(t.type&&"post"===t.type.toLowerCase())e.open("POST",t.url,!0);else{if(!t.type||"get"!==t.type.toLowerCase())throw Error("type:".concat(t.type," is not supported"));e.open("GET",t.url,!0)}if(t.dataType&&"json"===t.dataType)e.responseType="text";else{if(!t.dataType||"text"!==t.dataType)throw Error("Please check dataType:".concat(t.dataType,'. "json" or "text" is supported as dataType now.'));e.responseType="text"}if(t.contentType)try{e.setRequestHeader("Content-Type",t.contentType)}catch(e){throw Error("Invalid content type ".concat(t.contentType))}else if(t.type&&"post"===t.type.toLowerCase()||t.type&&"put"===t.type.toLowerCase())throw Error("Please specify contentType.");if(t.headers)for(const s in t.headers){const r=t.headers[s];e.setRequestHeader(s,r)}if(t.xhrFields){const{xhrFields:s}=t;!0===s.withCredentials&&(e.withCredentials=!0)}if(t.timeoutMillis&&(e.timeout=t.timeoutMillis),e.onload=s=>{if(200==e.status){let s="";s="json"==t.dataType?JSON.parse(e.response):e.response,t.success&&t.success(s,e)}else t.error&&t.error(s,e)},t.timeout&&(e.ontimeout=s=>{t.timeout(s,e)}),t.error&&(e.onerror=s=>{t.error(s,e)}),t.type&&"post"===t.type.toLowerCase()){if(!t.data)throw Error('.data is not specified.data must be specified on "POST" mode.');if(t.contentType.startsWith("application/x-www-form-urlencoded")){const s=(t=>{const e=[];for(const s in t){const r=t[s],n=encodeURIComponent(s)+"="+encodeURIComponent(r);e.push(n)}return e.join("&").replace(/%20/g,"+")})(t.data);e.send(s)}else e.send(t.data)}else t.type&&"get"===t.type.toLowerCase()&&e.send(null)}typeOf(t){return Object.prototype.toString.call(t).slice(8,-1)}}const{URLSearchParams:n}=s(1);class o{constructor(t){this.opt=t||{}}getAsync(t){t.type="get",this.ajax(t)}postAsync(t){t.type="post",this.ajax(t)}async get(t){if(t.type="get","application/json"===t.contentType)if("String"===this.typeOf(t.data));else{const e=t.data;t.data=JSON.stringify(e)}return new Promise(e=>{t.success=(t,s)=>{e({success:!0,data:t,response:s})},t.error=(t,s,r,n)=>{e({success:!1,cause:r,error:n,response:s})},t.timeout=(t,s,r,n)=>{e({success:!1,cause:r,error:n,response:s})},this.ajax(t)})}async post(t){if(t.type="post","application/json"===t.contentType)if("String"===this.typeOf(t.data));else{const e=t.data;t.data=JSON.stringify(e)}return new Promise(e=>{t.success=(t,s)=>{e({success:!0,data:t,response:s})},t.error=(t,s,r,n)=>{e({success:!1,cause:r,error:n,response:s})},t.timeout=(t,s,r,n)=>{e({success:!1,cause:r,error:n,response:s})},this.ajax(t)})}ajax(t){const e=this._createUrl(t),s=t.type,r=t.dataType,n=t.data,o=t.headers,a=t.contentType;let i=null;if(!e)throw Error("Please specify url.");if(s&&"post"===s.toLowerCase()&&(i=n,"jsonp"===r))throw new Error("type:'POST' and 'dataType:jsonp' are specified together.\n 'POST' and 'jsonp' can not be specified together");if(o&&"jsonp"===r)throw new Error("'headers' and 'dataType:jsonp' can not be specified together.\n Http headers cannot be sent when using jsonp.");const c={url:e,method:s,body:i,contentType:a};if(o&&(c.headers=o),"json"===r||"text"===r){return this._handleData(c,r,t)}if("jsonp"===r){return this._handleJsonp(c,t)}throw new Error("Please check dataType:".concat(r," dataType must be 'json' or 'jsonp'"))}_getFetchParam(t,e){const s=t.method.toUpperCase(),r={method:s,mode:"cors",cache:"no-cache",headers:{}};if(t.contentType)r.headers["Content-Type"]=t.contentType;else if("POST"===s||"PUT"===s)throw Error("Please specify contentType.");if(e.xhrFields){const{xhrFields:t}=e;!0===t.withCredentials&&(r.credentials="include")}if(t.credentials&&(r.credentials=t.credentials),t.headers)for(const e in t.headers){const s=t.headers[e];r.headers[e]=s}if(t.body)if(t.contentType.startsWith("application/x-www-form-urlencoded")){const e=t=>{const e=[];for(const s in t){const r=t[s],n=encodeURIComponent(s)+"="+encodeURIComponent(r);e.push(n)}return e.join("&").replace(/%20/g,"+")},s=e(t.body);r.body=s}else r.body=t.body;return r}_handleData(t,e,s){const r=new a,n=this._getFetchParam(t,s);return((t,s)=>new Promise((r,n)=>{s&&s.timeoutMillis&&setTimeout(()=>{n({data:null,cause:"timeout,".concat(s.timeoutMillis,"ms elapsed"),response:null})},s.timeoutMillis),t.then(t=>{t.ok?"json"===e?t.json().then(e=>{r({data:e,response:t})}).catch(e=>{n({data:null,cause:"client error,".concat(e),response:t})}):"text"===e&&t.text().then(e=>{r({data:e,response:t})}).catch(e=>{n({data:null,cause:"client error,".concat(e),response:t})}):"json"===e?t.json().then(e=>{n({data:e,cause:"server error,statusCode:".concat(t.status),response:t})}).catch(e=>{n({data:null,cause:"client error,".concat(e),response:t})}):"text"===e&&t.text().then(e=>{n({data:e,cause:"server error,statusCode:".concat(t.status),response:t})}).catch(e=>{n({data:null,cause:"client error,".concat(e),response:t})})}).catch(t=>{n({data:null,cause:"network error",response:null,err:t})})}))((this.opt.fetch||fetch)(t.url,n),s).then(t=>{r._success(t),s&&s.success&&s.success(t.data,t.response)}).catch(t=>{r._fail(t),"timeout"===t.cause?s&&s.timeout&&s.timeout(t.data,t.response,t.cause,t.err):s&&s.error&&s.error(t.data,t.response,t.cause,t.err)}),r}_handleJsonp(t,e){const s=new a,r=document.createElement("script"),n="ajaxclient2_".concat(this._createUUID());let o=t.url;o.indexOf("?")>=0?o+="&callback=".concat(n):o+="?callback=".concat(n),r.src=o,r.addEventListener("error",t=>{s._fail(t),e&&e.error&&e.error(t,null)}),window[n]=t=>{delete window[n],s._success({data:t,response:null}),e&&e.success&&e.success(t,null)};return(document.getElementsByTagName("head")?document.getElementsByTagName("head")[0]:document.body).appendChild(r),s}_createUrl(t){if(t.type&&"post"===t.type.toLowerCase())return t.url;if(t.type&&"get"===t.type.toLowerCase()){let e=t.url;if(t.data){const s=JSON.parse(t.data);e+="?";for(let t of Object.keys(s)){const r=s[t];e+="".concat(t,"=").concat(r,"&")}e=e.substring(0,e.length-1)}return e}throw Error("Invalid type ".concat(t.type," is not supported"))}_createUUID(){const t=(new Date).getTime();return"xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const s=(t+16*Math.random())%16|0;return("x"==e?s:3&s|8).toString(16)}))}typeOf(t){return Object.prototype.toString.call(t).slice(8,-1)}}class a{constructor(){this._successFunc=()=>{},this._failFunc=()=>{}}done(t){return this._successFunc=t,this}fail(t){return this._failFunc=t,this}_success(t){this._successFunc&&this._successFunc(t.data,t.response)}_fail(t){this._failFunc&&this._failFunc(t.data,t.response,t.cause,t.err)}}}])}));
{
"name": "ajax-client",
"version": "2.0.1",
"version": "2.0.2",
"description": "A simple ajax client with 'jquery-like' API",

@@ -5,0 +5,0 @@ "main": "lib/ajax-client.js",