You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

vue-use-async

Package Overview
Dependencies
Maintainers
1
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-use-async - npm Package Compare versions

Comparing version

to
0.3.18

2

dist/index.js

@@ -1,1 +0,1 @@

!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@vue/composition-api"));else if("function"==typeof define&&define.amd)define(["@vue/composition-api"],t);else{var r="object"==typeof exports?t(require("@vue/composition-api")):t(e["@vue/composition-api"]);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(self,(function(e){return(()=>{"use strict";var t={286:(e,t,r)=>{r.r(t),r.d(t,{Deferred:()=>u,Xhr:()=>b,cache:()=>o,cacheSize:()=>i,clearCache:()=>s,useAsync:()=>h,useSpinner:()=>S,useXhr:()=>w});var n=new Map;function o(e){var t,r,o=e||{},i=o.id,s=o.xhr,u="string"!=typeof e.duration&&e.duration||200;if("max"===e.duration&&(u=36e5),!n.get(i)&&s?(t=s(),n.set(i,t),t.then((function(e){return"[Log] add cache: ".concat(i),clearTimeout(r),r=setTimeout((function(){n.delete(i),"[Log] delete cache: ".concat(i),clearTimeout(r)}),u),e}),(function(){return n.delete(i),void"[Log] delete cache: ".concat(i)}))):i&&(t=n.get(i)),t)return t;throw Error("Call to undefined cache")}function i(){return n.size}function s(e){e?n.delete(e):n.forEach((function(e,t,r){r.delete(t)}))}var u=function e(){var t=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.resolve=void 0,this.reject=void 0,this.promise=void 0,this.resolve=function(){throw Error("Can t resolve")},this.reject=function(){throw Error("Can t reject")},this.promise=new Promise((function(e,r){t.resolve=e,t.reject=r}))},a=r(495);function c(e){return function(e){if(Array.isArray(e))return f(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function l(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:(0,a.ref)(!0),n=(0,a.ref)(),o=(0,a.ref)(),i=(0,a.ref)(),s=(0,a.isRef)(t)?t:(0,a.ref)(t),f=[],h=[],p=[],d=(0,a.ref)(new u),v=function(t){l.config.onStart(),h.forEach((function(e){return e(i.value)})),d.value=new u,n.value=!0,i.value=null;var r=Array.isArray(t)?e.call.apply(e,[null].concat(c(t))):e(t);r.then((function(e){o.value=e,d.value.resolve(e)}),(function(e){i.value=e||null,l.config.onError(e),f.forEach((function(e){return e(i.value)})),d.value.reject(e),i.value=e})),r.finally((function(){n.value=!1,l.config.onEnd(),p.forEach((function(e){return e()}))}))};return(0,a.watch)((function(){return s.value}),(function(e){r.value&&v(e)}),{immediate:r.value,deep:!0}),(0,a.watch)((function(){return r.value}),(function(e){e&&v(s.value)}),{immediate:!1}),{isPending:n,data:o,error:i,reload:function(){return v(s.value)},onError:function(e){return f.push(e)},onStart:function(e){return h.push(e)},onEnd:function(e){return p.push(e)},promise:(0,a.computed)((function(){return d.value.promise}))}}l.config={onError:function(e){},onStart:function(){},onEnd:function(){}};const h=l;function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function d(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function v(e){return(v="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})(e)}function y(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function m(e,t,r){return t&&y(e.prototype,t),r&&y(e,r),e}var b=function(){function e(t,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.onError=function(){},this.onStart=function(){},this.onAbort=function(){},this.onProgress=function(){},this.onEnd=function(){},this.token=null,this.url="",this.params={},this.sendAs="json",this.timeout=1e4,this.port=80,this.responseType="text",this._eventsReady=void 0,this._oXHR=void 0,this._onEnd=void 0,this._deferred=void 0,this._isXhrResolved=void 0,this._isXhrRejected=void 0,this._eventReady=void 0,this._eventsReady=!1,this._constructor(t,r)}return m(e,[{key:"_onError",value:function(e){this.onError(e),this._deferred.reject(e)}}],[{key:"parseResult",value:function(e){var t=e.response;try{var r=e.getResponseHeader("Content-Type");r&&r.toLowerCase().indexOf("json")>-1&&(t=JSON.parse(e.response))}catch(r){t=e.response}return t}}]),m(e,[{key:"removeEvents",value:function(){var e=this,t=function(){e._oXHR.removeEventListener("load",e._onEnd,!1),e._oXHR.removeEventListener("error",e.onError,!1),e._oXHR.removeEventListener("loadstart",e.onStart,!1),e._oXHR.removeEventListener("abort",e.onAbort,!1),e._oXHR.upload.removeEventListener("progress",e.onProgress,!1),e._oXHR.removeEventListener("progress",e.onProgress,!1),e._oXHR.removeEventListener("timeout",e.onError,!1)};this._deferred.promise.then(t,t)}},{key:"post",value:function(e){return this._constructor(e),this._oXHR.open("POST",this.url,!0),this._send(),this._deferred.promise}},{key:"put",value:function(e){return this._constructor(e),this._oXHR.open("PUT",this.url,!0),this._send(),this._deferred.promise}},{key:"get",value:function(t){this._constructor(t),this._oXHR.open("GET",e.stringifyUrl(this.url,this.params),!0),this._send();var r=this._deferred.promise;return r.abortXhr=this.abort.bind(this),r}},{key:"delete",value:function(t){return this._constructor(t),this._oXHR.open("DELETE",e.stringifyUrl(this.url,this.params),!0),this._send(),this._deferred.promise}},{key:"abort",value:function(){return this._isXhrResolved&&!this._isXhrRejected||(this._oXHR.abort(null,this),this._isXhrRejected=!0,this._deferred.reject({error:"Xhr aborted: ".concat(this.url),code:"HTTP-ABORTED"})),this._deferred.promise}},{key:"resolve",value:function(e){return this._deferred.resolve(e),this._deferred.promise}},{key:"reject",value:function(e){return this._deferred.reject(e),this._deferred.promise}},{key:"_setEvents",value:function(e){this._eventsReady||(this._eventReady=!0,e.addEventListener("load",this._onEnd,!1),e.addEventListener("error",this.onError,!1),e.addEventListener("loadstart",this.onStart,!1),e.addEventListener("abort",this.onAbort,!1),e.upload.addEventListener("progress",this.onProgress,!1),e.addEventListener("progress",this.onProgress,!1),e.addEventListener("timeout",this.onError,!1))}},{key:"_send",value:function(){var t;"multipart"===this.sendAs?t=e.getFormData(this.params):"json"===this.sendAs&&(this._oXHR.setRequestHeader("content-type","application/json; charset=utf-8"),t=JSON.stringify(this.params)),this.token&&this._oXHR.setRequestHeader("Authorization","Bearer ".concat(this.token)),this._oXHR.send(t,this)}},{key:"_constructor",value:function(t,r){var n=this;t&&"object"===v(t)?(this.sendAs=t.sendAs||this.sendAs,this.url=t.url||this.url,this.port=t.port||this.port,this.params=t.params||this.params,this.timeout=t.timeout||this.timeout,this.responseType=t.responseType||this.responseType,this.onProgress=(t.onProgress||this.onProgress).bind(this,this),this.onStart=(t.onStart||this.onStart).bind(this,this),this.onAbort=(t.onAbort||this.onAbort).bind(this,this),this.onEnd=(t.onEnd||this.onEnd).bind(this,this),this.onError=(t.onError||this.onError).bind(this,this),this.token=t.token||this.token):t&&"string"==typeof t&&(this.url=t,this.params=r||this.params),80!==this.port&&(this.url="".concat(window.location.protocol,"//").concat(window.location.hostname,":").concat(this.port).concat(this.url)),this._deferred=new u,this._oXHR=new XMLHttpRequest,this._oXHR.timeout=this.timeout,this._oXHR.responseType=this.responseType,this._isXhrResolved=!1,this._isXhrRejected=!1;var o=e._injectParamsInUrl(this.url,this.params);this.url=o.url,this.params=o.params,this._onEnd=function(t){var r=e.parseResult(n._oXHR);return n._oXHR.status>=400?(n._isXhrRejected=!0,n._onError(r),n._deferred.reject(r)):(n.onEnd(r,t),n._isXhrResolved=!0,n.removeEvents(),n.resolve(r))},this._setEvents(this._oXHR)}}],[{key:"new",value:function(t){return new e(t)}},{key:"stringifyUrl",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e._injectParamsInUrl(t,r);t=n.url,r=n.params;var o=t.indexOf("?")>-1?"&":"?",i="";return Object.keys(r).forEach((function(e){i+="".concat(o+e,"=").concat(encodeURIComponent(JSON.stringify(r[e]))),o="&"})),(t=t.replace(/\/:[^/]*/gi,""))+i}},{key:"getFormData",value:function(e){var t,r=new FormData;return Object.keys(e).forEach((function(n){if(e[n]instanceof FileList)for(var o=0;o<e[n].length;o+=1)r.append(n,e[n][o]);else e[n]instanceof File?r.append(n,e[n]):("object"!==v(t=e[n])&&!Array.isArray(t)||null===t||(t=JSON.stringify(t)),r.append(n,t))})),r}},{key:"_injectParamsInUrl",value:function(e,t){var r=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){d(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},t);return((e=e.replace(/#/,"%23")).match(/:[a-z0-9]+/gi)||[]).forEach((function(t){t=t.substr(1,t.length),void 0!==r[t]&&(e=e.replace(":".concat(t),null===r[t]||""===r[t]?"null":r[t]),delete r[t])})),{url:e,params:r}}}]),e}();function g(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function E(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?g(Object(r),!0).forEach((function(t){_(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):g(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function j(e){return(j="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})(e)}function O(e){}var R=function(e){return(0,a.isRef)(e)?e.value:e};function w(e){var t=e||{onError:function(){},onStart:function(){},onEnd:function(){},context:null,legacy:!1,token:null},r=t.onError,n=t.onStart,i=t.onEnd,u=t.context,c=t.legacy,f=t.token,l=function(e){var t=R(f);return t?((0,a.isRef)(e)?e.value.token=t:e.token=t,e):e},p=(0,a.ref)([]);return c||(0,a.onBeforeUnmount)((function(){p.value.forEach((function(e){return e.abort()}))})),{get:function(t,c,l){var h,d=this,v=new b,y=(r||O).bind(u),m=(n||O).bind(u),g=(i||O).bind(u),_=[y],w=[m],S=[g],P=(0,a.ref)();p.value.push(v);var X,k=(0,a.ref)(),H=(0,a.ref)(),A="",T=0,x=(0,a.computed)((function(){var r={};return"string"==typeof t?(A=t,r.url=A,r.params={}):t&&"object"===j(t)&&(A=t.url,c||(c=t.params||{}),T=t.cacheDuration,r=E(E({},r),t)),f&&(r.token=R(e.token)),c&&"object"===j(r)&&r.params&&(r.params=E(E({},(0,a.isRef)(r.params)?r.params.value:r.params),(0,a.isRef)(c)?c.value||{}:c)),r})),L=(0,a.ref)(!1),D=(null===(h=x.value)||void 0===h?void 0:h.enabled)||l;L=(0,a.isRef)(D)?D:(0,a.ref)(void 0===D||D);var U=(0,a.ref)(),C=function(){k.value&&v.abort(),w.forEach((function(e){return e(v)})),k.value=!0,P.value=null,X&&s(X),X=decodeURIComponent(b.stringifyUrl(A,"object"===j(x.value.params)?x.value.params:{})),U.value=o({id:X,xhr:v.get.bind(v,x.value),duration:T}),U.value.then((function(e){H.value=e}),(function(e){_.forEach((function(e){return e(P.value,d)})),P.value=e})),U.value.finally((function(){var e;(e=p.value.indexOf(v))>-1&&p.value.splice(e,1),k.value=!1,S.forEach((function(e){return e(v)}))}))};return(0,a.watch)((function(){return x.value}),(function(){L.value&&C()}),{immediate:L.value}),(0,a.watch)((function(){return L.value}),(function(e){e&&C()}),{immediate:!1}),{isPending:(0,a.computed)((function(){return k.value})),data:H,onError:function(e){return _.push(e)},onStart:function(e){return w.push(e)},onEnd:function(e){return S.push(e)},error:P,abort:function(){return U.value.abortXhr()},promise:(0,a.computed)((function(){return U.value})),reload:C,xhr:v}},post:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=new b;return E(E({},h((function(){return r.post(e)}),l(t))),{},{xhr:r})},put:function(e,t){var r=new b;return E(E({},h((function(){return r.put(e)}),l(t))),{},{xhr:r})},delete:function(e,t){var r=new b;return E(E({},h((function(){return r.delete(e)}),l(t))),{},{xhr:r})}}}function S(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,n=(0,a.ref)(!1);return(0,a.watch)((function(){return e.value}),(function(){n.value&&!e.value?(t&&clearTimeout(t),t=setTimeout((function(){n.value=e.value}),r)):n.value=e.value}),{immediate:!0}),(0,a.computed)((function(){return n.value}))}},495:t=>{t.exports=e}},r={};function n(e){if(r[e])return r[e].exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.exports}return n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(286)})()}));
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@vue/composition-api"));else if("function"==typeof define&&define.amd)define(["@vue/composition-api"],t);else{var r="object"==typeof exports?t(require("@vue/composition-api")):t(e["@vue/composition-api"]);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(self,(function(e){return(()=>{"use strict";var t={286:(e,t,r)=>{r.r(t),r.d(t,{Deferred:()=>u,Xhr:()=>b,cache:()=>o,cacheSize:()=>i,clearCache:()=>s,useAsync:()=>h,useSpinner:()=>S,useXhr:()=>w});var n=new Map;function o(e){var t,r,o=e||{},i=o.id,s=o.xhr,u="string"!=typeof e.duration&&e.duration||200;if("max"===e.duration&&(u=36e5),!n.get(i)&&s?(t=s(),n.set(i,t),t.then((function(e){return"[Log] add cache: ".concat(i),clearTimeout(r),r=setTimeout((function(){n.delete(i),"[Log] delete cache: ".concat(i),clearTimeout(r)}),u),e}),(function(){return n.delete(i),void"[Log] delete cache: ".concat(i)}))):i&&(t=n.get(i)),t)return t;throw Error("Call to undefined cache")}function i(){return n.size}function s(e){e?n.delete(e):n.forEach((function(e,t,r){r.delete(t)}))}var u=function e(){var t=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.resolve=void 0,this.reject=void 0,this.promise=void 0,this.resolve=function(){throw Error("Can t resolve")},this.reject=function(){throw Error("Can t reject")},this.promise=new Promise((function(e,r){t.resolve=e,t.reject=r}))},a=r(495);function c(e){return function(e){if(Array.isArray(e))return f(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function l(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:(0,a.ref)(!0),n=(0,a.ref)(),o=(0,a.ref)(),i=(0,a.ref)(),s=(0,a.isRef)(t)?t:(0,a.ref)(t),f=[],h=[],p=[],d=(0,a.ref)(new u),v=function(t){l.config.onStart(),h.forEach((function(e){return e(i.value)})),d.value=new u,n.value=!0,i.value=null;var r=Array.isArray(t)?e.call.apply(e,[null].concat(c(t))):e(t);r.then((function(e){o.value=e,d.value.resolve(e)}),(function(e){i.value=e||null,l.config.onError(e),f.forEach((function(e){return e(i.value)})),d.value.reject(e),i.value=e})),r.finally((function(){n.value=!1,l.config.onEnd(),p.forEach((function(e){return e()}))}))};return(0,a.watch)((function(){return s.value}),(function(e){r.value&&v(e)}),{immediate:r.value,deep:!0}),(0,a.watch)((function(){return r.value}),(function(e){e&&v(s.value)}),{immediate:!1}),{isPending:n,data:o,error:i,reload:function(){return v(s.value)},onError:function(e){return f.push(e)},onStart:function(e){return h.push(e)},onEnd:function(e){return p.push(e)},promise:(0,a.computed)((function(){return d.value.promise}))}}l.config={onError:function(e){},onStart:function(){},onEnd:function(){}};const h=l;function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function d(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function v(e){return(v="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})(e)}function y(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function m(e,t,r){return t&&y(e.prototype,t),r&&y(e,r),e}var b=function(){function e(t,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.onError=function(){},this.onStart=function(){},this.onAbort=function(){},this.onProgress=function(){},this.onEnd=function(){},this.token=null,this.url="",this.params={},this.sendAs="json",this.timeout=1e4,this.port=80,this.responseType="text",this._eventsReady=void 0,this._oXHR=void 0,this._onEnd=void 0,this._deferred=void 0,this._isXhrResolved=void 0,this._isXhrRejected=void 0,this._eventReady=void 0,this._eventsReady=!1,this._constructor(t,r)}return m(e,[{key:"_onError",value:function(e){this.onError(e),this._deferred.reject(e)}}],[{key:"parseResult",value:function(e){var t=e.response;try{var r=e.getResponseHeader("Content-Type");r&&r.toLowerCase().indexOf("json")>-1&&(t=JSON.parse(e.response))}catch(r){t=e.response}return t}}]),m(e,[{key:"removeEvents",value:function(){var e=this,t=function(){e._oXHR.removeEventListener("load",e._onEnd,!1),e._oXHR.removeEventListener("error",e.onError,!1),e._oXHR.removeEventListener("loadstart",e.onStart,!1),e._oXHR.removeEventListener("abort",e.onAbort,!1),e._oXHR.upload.removeEventListener("progress",e.onProgress,!1),e._oXHR.removeEventListener("progress",e.onProgress,!1),e._oXHR.removeEventListener("timeout",e.onError,!1)};this._deferred.promise.then(t,t)}},{key:"post",value:function(e){return this._constructor(e),this._oXHR.open("POST",this.url,!0),this._send(),this._deferred.promise}},{key:"put",value:function(e){return this._constructor(e),this._oXHR.open("PUT",this.url,!0),this._send(),this._deferred.promise}},{key:"get",value:function(t){this._constructor(t),this._oXHR.open("GET",e.stringifyUrl(this.url,this.params),!0),this._send();var r=this._deferred.promise;return r.abortXhr=this.abort.bind(this),r}},{key:"delete",value:function(t){return this._constructor(t),this._oXHR.open("DELETE",e.stringifyUrl(this.url,this.params),!0),this._send(),this._deferred.promise}},{key:"abort",value:function(){return this._isXhrResolved&&!this._isXhrRejected||(this._oXHR.abort(null,this),this._isXhrRejected=!0,this._deferred.reject({error:"Xhr aborted: ".concat(this.url),code:"HTTP-ABORTED"})),this._deferred.promise}},{key:"resolve",value:function(e){return this._deferred.resolve(e),this._deferred.promise}},{key:"reject",value:function(e){return this._deferred.reject(e),this._deferred.promise}},{key:"_setEvents",value:function(e){this._eventsReady||(this._eventReady=!0,e.addEventListener("load",this._onEnd,!1),e.addEventListener("error",this.onError,!1),e.addEventListener("loadstart",this.onStart,!1),e.addEventListener("abort",this.onAbort,!1),e.upload.addEventListener("progress",this.onProgress,!1),e.addEventListener("progress",this.onProgress,!1),e.addEventListener("timeout",this.onError,!1))}},{key:"_send",value:function(){var t;"multipart"===this.sendAs?t=e.getFormData(this.params):"json"===this.sendAs&&(this._oXHR.setRequestHeader("content-type","application/json; charset=utf-8"),t=JSON.stringify(this.params)),this.token&&this._oXHR.setRequestHeader("Authorization","Bearer ".concat(this.token)),this._oXHR.send(t,this)}},{key:"_constructor",value:function(t,r){var n=this;t&&"object"===v(t)?(this.sendAs=t.sendAs||this.sendAs,this.url=t.url||this.url,this.port=t.port||this.port,this.params=t.params||this.params,this.timeout=t.timeout||this.timeout,this.responseType=t.responseType||this.responseType,this.onProgress=(t.onProgress||this.onProgress).bind(this,this),this.onStart=(t.onStart||this.onStart).bind(this,this),this.onAbort=(t.onAbort||this.onAbort).bind(this,this),this.onEnd=(t.onEnd||this.onEnd).bind(this,this),this.onError=(t.onError||this.onError).bind(this,this),this.token=t.token||this.token):t&&"string"==typeof t&&(this.url=t,this.params=r||this.params),80!==this.port&&(this.url="".concat(window.location.protocol,"//").concat(window.location.hostname,":").concat(this.port).concat(this.url)),this._deferred=new u,this._oXHR=new XMLHttpRequest,this._oXHR.timeout=this.timeout,this._oXHR.responseType=this.responseType,this._isXhrResolved=!1,this._isXhrRejected=!1;var o=e._injectParamsInUrl(this.url,this.params);this.url=o.url,this.params=o.params,this._onEnd=function(t){var r=e.parseResult(n._oXHR);return n._oXHR.status>=400?(n._isXhrRejected=!0,n._onError(r),n._deferred.reject(r)):(n.onEnd(r,t),n._isXhrResolved=!0,n.removeEvents(),n.resolve(r))},this._setEvents(this._oXHR)}}],[{key:"new",value:function(t){return new e(t)}},{key:"stringifyUrl",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e._injectParamsInUrl(t,r);t=n.url,r=n.params;var o=t.indexOf("?")>-1?"&":"?",i="";return Object.keys(r).forEach((function(e){i+="".concat(o+e,"=").concat(encodeURIComponent(JSON.stringify(r[e]))),o="&"})),(t=t.replace(/\/:[^/]*/gi,""))+i}},{key:"getFormData",value:function(e){var t,r=new FormData;return Object.keys(e).forEach((function(n){if(e[n]instanceof FileList)for(var o=0;o<e[n].length;o+=1)r.append(n,e[n][o]);else e[n]instanceof File?r.append(n,e[n]):("object"!==v(t=e[n])&&!Array.isArray(t)||null===t||(t=JSON.stringify(t)),r.append(n,t))})),r}},{key:"_injectParamsInUrl",value:function(e,t){var r=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){d(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},t);return((e=e.replace(/#/,"%23")).match(/:[a-z0-9]+/gi)||[]).forEach((function(t){t=t.substr(1,t.length),void 0!==r[t]&&(e=e.replace(":".concat(t),null===r[t]||""===r[t]?"null":r[t]),delete r[t])})),{url:e,params:r}}}]),e}();function g(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function E(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?g(Object(r),!0).forEach((function(t){_(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):g(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function j(e){return(j="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})(e)}function O(e){}var R=function(e){return(0,a.isRef)(e)?e.value:e};function w(e){var t=e||{onError:function(){},onStart:function(){},onEnd:function(){},context:null,legacy:!1,token:null},r=t.onError,n=t.onStart,i=t.onEnd,u=t.context,c=t.legacy,f=t.token,l=function(e){var t=R(f);return t?((0,a.isRef)(e)?e.value.token=t:e.token=t,e):e},p=(0,a.ref)([]);return c||(0,a.onBeforeUnmount)((function(){p.value.forEach((function(e){return e.abort()}))})),{get:function(t,c,l){var h,d=new b,v=(r||O).bind(u),y=(n||O).bind(u),m=(i||O).bind(u),g=[v],_=[y],w=[m],S=(0,a.ref)();p.value.push(d);var P,X=(0,a.ref)(),k=(0,a.ref)(),H="",A=0,T=(0,a.computed)((function(){var r={};return"string"==typeof t?(H=t,r.url=H,r.params={}):t&&"object"===j(t)&&(H=t.url,c||(c=t.params||{}),A=t.cacheDuration,r=E(E({},r),t)),f&&(r.token=R(e.token)),c&&"object"===j(r)&&r.params&&(r.params=E(E({},(0,a.isRef)(r.params)?r.params.value:r.params),(0,a.isRef)(c)?c.value||{}:c)),r})),x=(0,a.ref)(!1),L=(null===(h=T.value)||void 0===h?void 0:h.enabled)||l;x=(0,a.isRef)(L)?L:(0,a.ref)(void 0===L||L);var D=(0,a.ref)(),U=function(){X.value&&d.abort(),_.forEach((function(e){return e(d)})),X.value=!0,S.value=null,P&&s(P),P=decodeURIComponent(b.stringifyUrl(H,"object"===j(T.value.params)?T.value.params:{})),D.value=o({id:P,xhr:d.get.bind(d,T.value),duration:A}),D.value.then((function(e){k.value=e}),(function(e){g.forEach((function(t){return t(e,d)})),S.value=e})),D.value.finally((function(){var e;(e=p.value.indexOf(d))>-1&&p.value.splice(e,1),X.value=!1,w.forEach((function(e){return e(d)}))}))};return(0,a.watch)((function(){return T.value}),(function(){x.value&&U()}),{immediate:x.value}),(0,a.watch)((function(){return x.value}),(function(e){e&&U()}),{immediate:!1}),{isPending:(0,a.computed)((function(){return X.value})),data:k,onError:function(e){return g.push(e)},onStart:function(e){return _.push(e)},onEnd:function(e){return w.push(e)},error:S,abort:function(){return D.value.abortXhr()},promise:(0,a.computed)((function(){return D.value})),reload:U,xhr:d}},post:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=new b;return E(E({},h((function(){return r.post(e)}),l(t))),{},{xhr:r})},put:function(e,t){var r=new b;return E(E({},h((function(){return r.put(e)}),l(t))),{},{xhr:r})},delete:function(e,t){var r=new b;return E(E({},h((function(){return r.delete(e)}),l(t))),{},{xhr:r})}}}function S(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,n=(0,a.ref)(!1);return(0,a.watch)((function(){return e.value}),(function(){n.value&&!e.value?(t&&clearTimeout(t),t=setTimeout((function(){n.value=e.value}),r)):n.value=e.value}),{immediate:!0}),(0,a.computed)((function(){return n.value}))}},495:t=>{t.exports=e}},r={};function n(e){if(r[e])return r[e].exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.exports}return n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(286)})()}));
{
"name": "vue-use-async",
"version": "0.3.17",
"version": "0.3.18",
"description": "Xhr and async helpers",

@@ -5,0 +5,0 @@ "repository": {