Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@siberiacancode/fetches

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@siberiacancode/fetches - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

2

dist/cjs/index.js

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

/* @license @siberiacancode/fetches v1.1.3 */
/* @license @siberiacancode/fetches v1.2.0 */
"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function e(t,e,r,n,o,a,i){try{var u=t[a](i),s=u.value}catch(t){return void r(t)}u.done?e(s):Promise.resolve(s).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,a){var i=t.apply(r,n);function u(t){e(i,o,a,u,s,"next",t)}function s(t){e(i,o,a,u,s,"throw",t)}u(void 0)}))}}function n(t,e,r){return e&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,c(n.key),n)}}(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(e,r){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e))||r){n&&(e=n);var o=0,a=function(){};return{s:a,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var t=n.next();return u=t.done,t},e:function(t){s=!0,i=t},f:function(){try{u||null==n.return||n.return()}finally{if(s)throw i}}}}function a(t,e,r){return(e=c(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){a(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function s(){s=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",c=a.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var a=e&&e.prototype instanceof g?e:g,i=Object.create(a.prototype),u=new _(n||[]);return o(i,"_invoke",{value:P(t,r,u)}),i}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var p="suspendedStart",v="suspendedYield",y="executing",d="completed",b={};function g(){}function m(){}function w(){}var x={};f(x,i,(function(){return this}));var k=Object.getPrototypeOf,O=k&&k(k(F([])));O&&O!==r&&n.call(O,i)&&(x=O);var j=w.prototype=g.prototype=Object.create(x);function E(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function L(t,e){function r(o,a,i,u){var s=h(t[o],t,a);if("throw"!==s.type){var c=s.arg,f=c.value;return f&&"object"==typeof f&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,i,u)}),(function(t){r("throw",t,i,u)})):e.resolve(f).then((function(t){c.value=t,i(c)}),(function(t){return r("throw",t,i,u)}))}u(s.arg)}var a;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return a=a?a.then(o,o):o()}})}function P(e,r,n){var o=p;return function(a,i){if(o===y)throw Error("Generator is already running");if(o===d){if("throw"===a)throw i;return{value:t,done:!0}}for(n.method=a,n.arg=i;;){var u=n.delegate;if(u){var s=S(u,n);if(s){if(s===b)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var c=h(e,r,n);if("normal"===c.type){if(o=n.done?d:v,c.arg===b)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=d,n.method="throw",n.arg=c.arg)}}}function S(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,S(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),b;var a=h(o,e.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,b;var i=a.arg;return i?i.done?(r[e.resultName]=i.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,b):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,b)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function q(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function F(e){if(e||""===e){var r=e[i];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(typeof e+" is not iterable")}return m.prototype=w,o(j,"constructor",{value:w,configurable:!0}),o(w,"constructor",{value:m,configurable:!0}),m.displayName=f(w,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,f(t,c,"GeneratorFunction")),t.prototype=Object.create(j),t},e.awrap=function(t){return{__await:t}},E(L.prototype),f(L.prototype,u,(function(){return this})),e.AsyncIterator=L,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new L(l(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},E(j),f(j,c,"Generator"),f(j,i,(function(){return this})),f(j,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=F,_.prototype={constructor:_,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(q),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return u.type="throw",u.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],u=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,b):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),b},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),q(r),b}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;q(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:F(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),b}},e}function c(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}var f=function(){return n((function t(e){var r=this,n=e.baseURL,o=e.headers,a=void 0===o?{}:o;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.baseURL=n,this.headers=a,this.interceptorHandlers={request:[],response:[]},this.interceptors={request:{use:function(t,e){var n,o={onSuccess:t,onFailure:e};return null===(n=r.interceptorHandlers.request)||void 0===n||n.push(o),o},eject:function(t){var e;r.interceptorHandlers.request=null===(e=r.interceptorHandlers.request)||void 0===e?void 0:e.filter((function(e){return e!==t}))}},response:{use:function(t,e){var n,o={onSuccess:t,onFailure:e};return null===(n=r.interceptorHandlers.response)||void 0===n||n.push(o),o},eject:function(t){var e;r.interceptorHandlers.response=null===(e=r.interceptorHandlers.response)||void 0===e?void 0:e.filter((function(e){return e!==t}))}}}}),[{key:"setHeaders",value:function(t){this.headers=u(u({},this.headers),t)}},{key:"createSearchParams",value:function(t){var e=new URLSearchParams,r=function(r){if(Object.prototype.hasOwnProperty.call(t,r)){var n=t[r];if(null==n)return 1;Array.isArray(n)?n.forEach((function(t){return e.append(r,t)})):e.set(r,n.toString())}};for(var n in t)r(n);return"?".concat(e.toString())}},{key:"runResponseInterceptors",value:(i=r(s().mark((function t(e,r){var n,a,i,u,c,f,l,h;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.parseJson(e);case 2:if(a=t.sent,i={data:a,url:e.url,headers:e.headers,status:e.status,statusText:e.statusText,config:r},null!==(n=this.interceptorHandlers.response)&&void 0!==n&&n.length){t.next=6;break}return t.abrupt("return",i);case 6:u=o(this.interceptorHandlers.response),t.prev=7,u.s();case 9:if((c=u.n()).done){t.next=34;break}if(f=c.value,l=f.onSuccess,h=f.onFailure,t.prev=11,e.ok){t.next=14;break}throw new Error(e.statusText,{cause:{config:r,response:i}});case 14:if(l){t.next=16;break}return t.abrupt("continue",32);case 16:return t.next=18,l(i);case 18:i=t.sent,t.next=32;break;case 21:if(t.prev=21,t.t0=t.catch(11),t.t0.config=r,t.t0.response=i,!h){t.next=31;break}return t.next=28,h(t.t0);case 28:i=t.sent,t.next=32;break;case 31:Promise.reject(t.t0);case 32:t.next=9;break;case 34:t.next=39;break;case 36:t.prev=36,t.t1=t.catch(7),u.e(t.t1);case 39:return t.prev=39,u.f(),t.finish(39);case 42:return t.abrupt("return",i);case 43:case"end":return t.stop()}}),t,this,[[7,36,39,42],[11,21]])}))),function(t,e){return i.apply(this,arguments)})},{key:"runRequestInterceptors",value:(a=r(s().mark((function t(e){var r,n,a,i,u,c,f;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=e,null!==(r=this.interceptorHandlers.request)&&void 0!==r&&r.length){t.next=3;break}return t.abrupt("return",n);case 3:a=o(this.interceptorHandlers.request),t.prev=4,a.s();case 6:if((i=a.n()).done){t.next=27;break}if(u=i.value,c=u.onSuccess,f=u.onFailure,t.prev=8,c){t.next=11;break}return t.abrupt("continue",25);case 11:return t.next=13,c(n);case 13:n=t.sent,t.next=25;break;case 16:if(t.prev=16,t.t0=t.catch(8),t.t0.config=e,!f){t.next=24;break}return t.next=22,f(t.t0);case 22:t.next=25;break;case 24:Promise.reject(t.t0);case 25:t.next=6;break;case 27:t.next=32;break;case 29:t.prev=29,t.t1=t.catch(4),a.e(t.t1);case 32:return t.prev=32,a.f(),t.finish(32);case 35:return t.abrupt("return",n);case 36:case"end":return t.stop()}}),t,this,[[4,29,32,35],[8,16]])}))),function(t){return a.apply(this,arguments)})},{key:"parseJson",value:(e=r(s().mark((function t(e){return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,e.json();case 3:return t.abrupt("return",t.sent);case 6:return t.prev=6,t.t0=t.catch(0),t.abrupt("return",null);case 9:case"end":return t.stop()}}),t,null,[[0,6]])}))),function(t){return e.apply(this,arguments)})},{key:"request",value:(t=r(s().mark((function t(e,r){var n,o,a,i,c,f,l,h,p,v=arguments;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=u(u({},o=v.length>2&&void 0!==v[2]?v[2]:{}),{},{url:e,method:r,headers:u(u(u({},this.headers),(null==o?void 0:o.body)&&!(o.body instanceof FormData)&&{"content-type":"application/json"}),!(null==o||!o.headers)&&o.headers)}),t.next=4,this.runRequestInterceptors(a);case 4:return i=t.sent,c="".concat(this.baseURL,"/").concat(e),o.params&&(c+=this.createSearchParams(o.params)),t.next=9,fetch(c,i);case 9:if(f=t.sent,null===(n=this.interceptorHandlers.response)||void 0===n||!n.length){t.next=12;break}return t.abrupt("return",this.runResponseInterceptors(f,i));case 12:if(!(f.status>=400)){t.next=20;break}return l={},t.next=16,this.parseJson(f);case 16:throw h=t.sent,l.config=i,l.response={config:i,url:f.url,status:f.status,statusText:f.statusText,headers:f.headers,data:h},new Error(f.statusText,{cause:{config:i,response:f}});case 20:return t.next=22,this.parseJson(f);case 22:return p=t.sent,t.abrupt("return",{config:i,data:p,url:f.url,headers:f.headers,status:f.status,statusText:f.statusText});case 24:case"end":return t.stop()}}),t,this)}))),function(e,r){return t.apply(this,arguments)})},{key:"get",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.request(t,"GET",e)}},{key:"delete",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.request(t,"DELETE",e)}},{key:"post",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.request(t,"POST",u(u({},r),!!e&&{body:e instanceof FormData?e:JSON.stringify(e)}))}},{key:"put",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.request(t,"PUT",u(u({},r),!!e&&{body:e instanceof FormData?e:JSON.stringify(e)}))}},{key:"patch",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.request(t,"PATCH",u(u({},r),!!e&&{body:e instanceof FormData?e:JSON.stringify(e)}))}},{key:"call",value:function(t){return this.request(t.url,t.method,t)}}]);var t,e,a,i}();exports.Fetches=f;
//# sourceMappingURL=index.js.map

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

/* @license @siberiacancode/fetches v1.1.3 */
/* @license @siberiacancode/fetches v1.2.0 */
function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function e(t,e,r,n,o,a,i){try{var u=t[a](i),s=u.value}catch(t){return void r(t)}u.done?e(s):Promise.resolve(s).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,a){var i=t.apply(r,n);function u(t){e(i,o,a,u,s,"next",t)}function s(t){e(i,o,a,u,s,"throw",t)}u(void 0)}))}}function n(t,e,r){return e&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,c(n.key),n)}}(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(e,r){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e))||r){n&&(e=n);var o=0,a=function(){};return{s:a,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var t=n.next();return u=t.done,t},e:function(t){s=!0,i=t},f:function(){try{u||null==n.return||n.return()}finally{if(s)throw i}}}}function a(t,e,r){return(e=c(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){a(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function s(){s=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",c=a.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var a=e&&e.prototype instanceof g?e:g,i=Object.create(a.prototype),u=new _(n||[]);return o(i,"_invoke",{value:P(t,r,u)}),i}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var p="suspendedStart",v="suspendedYield",y="executing",d="completed",b={};function g(){}function m(){}function w(){}var x={};f(x,i,(function(){return this}));var k=Object.getPrototypeOf,O=k&&k(k(H([])));O&&O!==r&&n.call(O,i)&&(x=O);var j=w.prototype=g.prototype=Object.create(x);function E(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function L(t,e){function r(o,a,i,u){var s=h(t[o],t,a);if("throw"!==s.type){var c=s.arg,f=c.value;return f&&"object"==typeof f&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,i,u)}),(function(t){r("throw",t,i,u)})):e.resolve(f).then((function(t){c.value=t,i(c)}),(function(t){return r("throw",t,i,u)}))}u(s.arg)}var a;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return a=a?a.then(o,o):o()}})}function P(e,r,n){var o=p;return function(a,i){if(o===y)throw Error("Generator is already running");if(o===d){if("throw"===a)throw i;return{value:t,done:!0}}for(n.method=a,n.arg=i;;){var u=n.delegate;if(u){var s=S(u,n);if(s){if(s===b)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var c=h(e,r,n);if("normal"===c.type){if(o=n.done?d:v,c.arg===b)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=d,n.method="throw",n.arg=c.arg)}}}function S(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,S(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),b;var a=h(o,e.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,b;var i=a.arg;return i?i.done?(r[e.resultName]=i.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,b):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,b)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function q(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function H(e){if(e||""===e){var r=e[i];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(typeof e+" is not iterable")}return m.prototype=w,o(j,"constructor",{value:w,configurable:!0}),o(w,"constructor",{value:m,configurable:!0}),m.displayName=f(w,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,f(t,c,"GeneratorFunction")),t.prototype=Object.create(j),t},e.awrap=function(t){return{__await:t}},E(L.prototype),f(L.prototype,u,(function(){return this})),e.AsyncIterator=L,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new L(l(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},E(j),f(j,c,"Generator"),f(j,i,(function(){return this})),f(j,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=H,_.prototype={constructor:_,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(q),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return u.type="throw",u.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],u=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,b):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),b},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),q(r),b}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;q(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:H(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),b}},e}function c(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}var f=function(){return n((function t(e){var r=this,n=e.baseURL,o=e.headers,a=void 0===o?{}:o;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.baseURL=n,this.headers=a,this.interceptorHandlers={request:[],response:[]},this.interceptors={request:{use:function(t,e){var n,o={onSuccess:t,onFailure:e};return null===(n=r.interceptorHandlers.request)||void 0===n||n.push(o),o},eject:function(t){var e;r.interceptorHandlers.request=null===(e=r.interceptorHandlers.request)||void 0===e?void 0:e.filter((function(e){return e!==t}))}},response:{use:function(t,e){var n,o={onSuccess:t,onFailure:e};return null===(n=r.interceptorHandlers.response)||void 0===n||n.push(o),o},eject:function(t){var e;r.interceptorHandlers.response=null===(e=r.interceptorHandlers.response)||void 0===e?void 0:e.filter((function(e){return e!==t}))}}}}),[{key:"setHeaders",value:function(t){this.headers=u(u({},this.headers),t)}},{key:"createSearchParams",value:function(t){var e=new URLSearchParams,r=function(r){if(Object.prototype.hasOwnProperty.call(t,r)){var n=t[r];if(null==n)return 1;Array.isArray(n)?n.forEach((function(t){return e.append(r,t)})):e.set(r,n.toString())}};for(var n in t)r(n);return"?".concat(e.toString())}},{key:"runResponseInterceptors",value:(i=r(s().mark((function t(e,r){var n,a,i,u,c,f,l,h;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.parseJson(e);case 2:if(a=t.sent,i={data:a,url:e.url,headers:e.headers,status:e.status,statusText:e.statusText,config:r},null!==(n=this.interceptorHandlers.response)&&void 0!==n&&n.length){t.next=6;break}return t.abrupt("return",i);case 6:u=o(this.interceptorHandlers.response),t.prev=7,u.s();case 9:if((c=u.n()).done){t.next=34;break}if(f=c.value,l=f.onSuccess,h=f.onFailure,t.prev=11,e.ok){t.next=14;break}throw new Error(e.statusText,{cause:{config:r,response:i}});case 14:if(l){t.next=16;break}return t.abrupt("continue",32);case 16:return t.next=18,l(i);case 18:i=t.sent,t.next=32;break;case 21:if(t.prev=21,t.t0=t.catch(11),t.t0.config=r,t.t0.response=i,!h){t.next=31;break}return t.next=28,h(t.t0);case 28:i=t.sent,t.next=32;break;case 31:Promise.reject(t.t0);case 32:t.next=9;break;case 34:t.next=39;break;case 36:t.prev=36,t.t1=t.catch(7),u.e(t.t1);case 39:return t.prev=39,u.f(),t.finish(39);case 42:return t.abrupt("return",i);case 43:case"end":return t.stop()}}),t,this,[[7,36,39,42],[11,21]])}))),function(t,e){return i.apply(this,arguments)})},{key:"runRequestInterceptors",value:(a=r(s().mark((function t(e){var r,n,a,i,u,c,f;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=e,null!==(r=this.interceptorHandlers.request)&&void 0!==r&&r.length){t.next=3;break}return t.abrupt("return",n);case 3:a=o(this.interceptorHandlers.request),t.prev=4,a.s();case 6:if((i=a.n()).done){t.next=27;break}if(u=i.value,c=u.onSuccess,f=u.onFailure,t.prev=8,c){t.next=11;break}return t.abrupt("continue",25);case 11:return t.next=13,c(n);case 13:n=t.sent,t.next=25;break;case 16:if(t.prev=16,t.t0=t.catch(8),t.t0.config=e,!f){t.next=24;break}return t.next=22,f(t.t0);case 22:t.next=25;break;case 24:Promise.reject(t.t0);case 25:t.next=6;break;case 27:t.next=32;break;case 29:t.prev=29,t.t1=t.catch(4),a.e(t.t1);case 32:return t.prev=32,a.f(),t.finish(32);case 35:return t.abrupt("return",n);case 36:case"end":return t.stop()}}),t,this,[[4,29,32,35],[8,16]])}))),function(t){return a.apply(this,arguments)})},{key:"parseJson",value:(e=r(s().mark((function t(e){return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,e.json();case 3:return t.abrupt("return",t.sent);case 6:return t.prev=6,t.t0=t.catch(0),t.abrupt("return",null);case 9:case"end":return t.stop()}}),t,null,[[0,6]])}))),function(t){return e.apply(this,arguments)})},{key:"request",value:(t=r(s().mark((function t(e,r){var n,o,a,i,c,f,l,h,p,v=arguments;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=u(u({},o=v.length>2&&void 0!==v[2]?v[2]:{}),{},{url:e,method:r,headers:u(u(u({},this.headers),(null==o?void 0:o.body)&&!(o.body instanceof FormData)&&{"content-type":"application/json"}),!(null==o||!o.headers)&&o.headers)}),t.next=4,this.runRequestInterceptors(a);case 4:return i=t.sent,c="".concat(this.baseURL,"/").concat(e),o.params&&(c+=this.createSearchParams(o.params)),t.next=9,fetch(c,i);case 9:if(f=t.sent,null===(n=this.interceptorHandlers.response)||void 0===n||!n.length){t.next=12;break}return t.abrupt("return",this.runResponseInterceptors(f,i));case 12:if(!(f.status>=400)){t.next=20;break}return l={},t.next=16,this.parseJson(f);case 16:throw h=t.sent,l.config=i,l.response={config:i,url:f.url,status:f.status,statusText:f.statusText,headers:f.headers,data:h},new Error(f.statusText,{cause:{config:i,response:f}});case 20:return t.next=22,this.parseJson(f);case 22:return p=t.sent,t.abrupt("return",{config:i,data:p,url:f.url,headers:f.headers,status:f.status,statusText:f.statusText});case 24:case"end":return t.stop()}}),t,this)}))),function(e,r){return t.apply(this,arguments)})},{key:"get",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.request(t,"GET",e)}},{key:"delete",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.request(t,"DELETE",e)}},{key:"post",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.request(t,"POST",u(u({},r),!!e&&{body:e instanceof FormData?e:JSON.stringify(e)}))}},{key:"put",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.request(t,"PUT",u(u({},r),!!e&&{body:e instanceof FormData?e:JSON.stringify(e)}))}},{key:"patch",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.request(t,"PATCH",u(u({},r),!!e&&{body:e instanceof FormData?e:JSON.stringify(e)}))}},{key:"call",value:function(t){return this.request(t.url,t.method,t)}}]);var t,e,a,i}();export{f as Fetches};
//# sourceMappingURL=index.js.map

@@ -76,10 +76,10 @@ type BaseUrl = string;

private request;
get<T, R>(endpoint: string, options?: Omit<RequestOptions, 'body'>): Promise<R>;
delete<T, R>(endpoint: string, options?: Omit<RequestOptions, 'body'>): Promise<R>;
post<T, R>(endpoint: string, body?: RequestBody, options?: RequestOptions): Promise<R>;
put<T, R>(endpoint: string, body?: RequestBody, options?: RequestOptions): Promise<R>;
patch<T, R>(endpoint: string, body?: RequestBody, options?: RequestOptions): Promise<R>;
call<T, R>(options: _RequestConfig): Promise<R>;
get<T, R = FetchesResponse<T>>(endpoint: string, options?: Omit<RequestOptions, 'body'>): Promise<R>;
delete<T, R = FetchesResponse<T>>(endpoint: string, options?: Omit<RequestOptions, 'body'>): Promise<R>;
post<T, R = FetchesResponse<T>>(endpoint: string, body?: RequestBody, options?: RequestOptions): Promise<R>;
put<T, R = FetchesResponse<T>>(endpoint: string, body?: RequestBody, options?: RequestOptions): Promise<R>;
patch<T, R = FetchesResponse<T>>(endpoint: string, body?: RequestBody, options?: RequestOptions): Promise<R>;
call<T, R = FetchesResponse<T>>(options: _RequestConfig): Promise<R>;
}
export { type BaseUrl, type FailureRequestFun, type FailureResponseFun, Fetches, type FetchesParams, type FetchesRequestConfig, type FetchesResponse, type FetchesSearchParams, type Interceptors, type RequestBody, type RequestInterceptor, type RequestMethod, type RequestOptions, type ResponseError, type ResponseInterceptor, type SuccessRequestFun, type SuccessResponseFun };
{
"name": "@siberiacancode/fetches",
"type": "module",
"version": "1.1.3",
"version": "1.2.0",
"description": "fetch instance",

@@ -6,0 +6,0 @@ "author": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc