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

@svkhrobbeck/fetcher

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@svkhrobbeck/fetcher - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

2

dist/index.cjs.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={method:"GET",timeout:0,headers:{"Content-Type":"application/json"},transformRequest:[(e,t)=>e],transformResponse:[e=>e],adapter:"fetch"};function t(e,t){const r=t?new URLSearchParams(t).toString():"";return r?`${e}?${r}`:e}function r(e,t={}){const r={...e,...t};return e.headers&&t.headers&&(r.headers={...e.headers,...t.headers}),r}function s(e,t,r){return r.forEach((r=>{e=r(e,t)})),e}function n(e,t){if(!e)return null;if(t&&t.includes("application/json"))return JSON.stringify(e);if(t&&t.includes("multipart/form-data")){const t=new FormData;return Object.keys(e).forEach((r=>t.append(r,e[r]))),t}if(t&&t.includes("application/x-www-form-urlencoded")){const t=new URLSearchParams;return Object.keys(e).forEach((r=>t.append(r,e[r]))),t.toString()}return e}class o{constructor(t){this.defaults=r(e,t),this.interceptors={request:new l,response:new l}}async request(e){const s=Date.now(),o=r(this.defaults,e);o.url=t(o.url,o.params);const a=new i(o.headers);o.headers=a.toObject(),o.data&&(o.data=n(o.data,a.get("Content-Type")));const u=[d,void 0];this.interceptors.request.forEach((e=>{u.unshift(e.fulfilled,e.rejected)})),this.interceptors.response.forEach((e=>{u.push(e.fulfilled,e.rejected)}));let c=Promise.resolve(o);for(;u.length;)c=c.then(u.shift(),u.shift());try{const e=await c,t=Date.now();return e.duration=t-s,e.statusText=p[e.status]||"Unknown Status",e}catch(e){const t=Date.now();throw"object"==typeof e&&null!==e&&(e.duration=t-s),e}}get(e,t={}){return this.request({...t,method:"GET",url:e})}post(e,t,r={}){return this.request({...r,method:"POST",url:e,data:t})}put(e,t,r={}){return this.request({...r,method:"PUT",url:e,data:t})}delete(e,t={}){return this.request({...t,method:"DELETE",url:e})}}class a{constructor(e){if(this.reason=null,"function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((e=>{t=e})),e((e=>{this.reason||(this.reason=new Error(e),t(this.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}static source(){let e;return{token:new a((t=>{e=t})),cancel:e}}}class u extends Error{constructor(e,t,r,s,n){super(e),this.name="FetcherError",this.code=t,this.config=r,this.request=s,this.response=n,Error.captureStackTrace(this,this.constructor)}static from(e,t,r,s){return new u(e.message,e.name,t,r,s)}}class i{constructor(e){this.headers=e||{}}set(e,t){this.headers[e.toLowerCase()]=t}get(e){return this.headers[e.toLowerCase()]}remove(e){delete this.headers[e.toLowerCase()]}toObject(){return{...this.headers}}}function c(e){return new Promise(((t,r)=>{if("undefined"==typeof window||void 0===window.XMLHttpRequest)return void r(new Error("XMLHttpRequest is not supported in Node.js environment."));const{url:s,method:n,headers:o,data:a}=e,u=new XMLHttpRequest;u.open(n.toUpperCase(),s,!0),o&&Object.keys(o).forEach((e=>{u.setRequestHeader(e,o[e])})),u.onload=()=>{const r={data:u.response,status:u.status,statusText:u.statusText,headers:u.getAllResponseHeaders(),config:e,request:u};t(r)},u.onerror=()=>r(new Error("Network Error")),u.ontimeout=()=>r(new Error(`Timeout of ${e.timeout}ms exceeded`)),u.send(a)}))}function h(e){return new Promise(((t,r)=>{if("undefined"==typeof fetch)return void r(new Error("Fetch API not found in this environment."));const{url:s,method:n,headers:o,data:a}=e;fetch(s,{method:n,headers:o,body:a}).then((t=>t.json().then((r=>({data:r,status:t.status,statusText:t.statusText,headers:t.headers,config:e,request:t}))))).then(t).catch((e=>{r(e)}))}))}function d(e){const t="xhr"===e.adapter?c:h;return new Promise(((r,n)=>{e.cancelToken&&e.cancelToken.throwIfRequested(),t(e).then((t=>{t.data=s(t.data,t.headers,e.transformResponse||[]),t.status>=200&&t.status<300?r(t):n(u.from(new Error("Request failed"),e,null,t))})).catch((t=>{n(u.from(t,e,null,null))}))}))}class l{constructor(){this.handlers=[]}use(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}forEach(e){this.handlers.forEach((t=>{null!==t&&e(t)}))}}function f(e){const t=new o(e),r=o.prototype.request.bind(t);return Object.setPrototypeOf(r,o.prototype),Object.assign(r,t),r}const p={200:"OK",201:"Created",202:"Accepted",204:"No Content",400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout"},w=f(e);w.create=e=>f(e),exports.CancelToken=a,exports.FetcherError=u,exports.FetcherHeaders=i,exports.HTTP_STATUS_CODES=p,exports.InterceptorManager=l,exports.buildURL=t,exports.createInstance=f,exports.default=w,exports.fetchAdapter=h,exports.formatRequestBody=n,exports.mergeConfig=r,exports.transformData=s,exports.xhrAdapter=c;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={method:"GET",timeout:0,headers:{"Content-Type":"application/json"},transformRequest:[(e,t)=>e],transformResponse:[e=>e],adapter:"fetch"};function t(e,t){const r=t?new URLSearchParams(t).toString():"";return r?`${e}?${r}`:e}function r(e,t={}){const r={...e,...t};return e.headers&&t.headers&&(r.headers={...e.headers,...t.headers}),r}function s(e,t,r){return r.forEach((r=>{e=r(e,t)})),e}function n(e,t){if(!e)return null;if(t&&t.includes("application/json"))return JSON.stringify(e);if(t&&t.includes("multipart/form-data")){const t=new FormData;return Object.keys(e).forEach((r=>t.append(r,e[r]))),t}if(t&&t.includes("application/x-www-form-urlencoded")){const t=new URLSearchParams;return Object.keys(e).forEach((r=>t.append(r,e[r]))),t.toString()}return e}class o{constructor(t){this.defaults=r(e,t),this.interceptors={request:new l,response:new l}}async request(e){const s=Date.now(),o=r(this.defaults,e);o.url=t(o.url,o.params);const a=new c(o.headers);o.headers=a.toObject(),o.data&&(o.data=n(o.data,a.get("Content-Type")));const u=[d,void 0];this.interceptors.request.forEach((e=>{u.unshift(e.fulfilled,e.rejected)})),this.interceptors.response.forEach((e=>{u.push(e.fulfilled,e.rejected)}));let i=Promise.resolve(o);for(;u.length;)i=i.then(u.shift(),u.shift());try{const e=await i,t=Date.now();return e.duration=t-s,e.statusText=p[e.status]||"Unknown Status",e}catch(e){const t=Date.now();throw"object"==typeof e&&null!==e&&(e.duration=t-s),e}}get(e,t={}){return this.request({...t,method:"GET",url:e})}post(e,t,r={}){return this.request({...r,method:"POST",url:e,data:t})}put(e,t,r={}){return this.request({...r,method:"PUT",url:e,data:t})}delete(e,t={}){return this.request({...t,method:"DELETE",url:e})}}class a{constructor(e){if(this.reason=null,"function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((e=>{t=e})),e((e=>{this.reason||(this.reason=new Error(e),t(this.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}static source(){let e;return{token:new a((t=>{e=t})),cancel:e}}}class u extends Error{constructor(e,t,r,s,n){super(e),this.name="FetcherError",this.code=t,this.config=r,this.request=s,this.response=n,Error.captureStackTrace(this,this.constructor)}static from(e,t,r,s){return new u(e.message,e.name,t,r,s)}}class c{constructor(e){this.headers=e||{}}set(e,t){this.headers[e.toLowerCase()]=t}get(e){return this.headers[e.toLowerCase()]}remove(e){delete this.headers[e.toLowerCase()]}toObject(){return{...this.headers}}}function i(e){return new Promise(((t,r)=>{if("undefined"==typeof window||void 0===window.XMLHttpRequest)return void r(new Error("XMLHttpRequest is not supported in Node.js environment."));const{url:s,method:n,headers:o,data:a}=e,u=new XMLHttpRequest;u.open(n.toUpperCase(),s,!0),o&&Object.keys(o).forEach((e=>{u.setRequestHeader(e,o[e])})),u.onload=()=>{const r={data:u.response,status:u.status,statusText:u.statusText,headers:u.getAllResponseHeaders(),config:e,request:u};t(r)},u.onerror=()=>r(new Error("Network Error")),u.ontimeout=()=>r(new Error(`Timeout of ${e.timeout}ms exceeded`)),u.send(a)}))}function h(e){return new Promise(((t,r)=>{if("undefined"==typeof fetch)return void r(new Error("Fetch API not found in this environment."));const{url:s,method:n,headers:o,data:a}=e;fetch(s,{method:n,headers:o,body:a}).then((t=>t.json().then((r=>({data:r,status:t.status,statusText:t.statusText,headers:t.headers,config:e,request:t}))))).then(t).catch((e=>{r(e)}))}))}function d(e){const t="xhr"===e.adapter?i:h;return new Promise(((r,n)=>{e.cancelToken&&e.cancelToken.throwIfRequested(),t(e).then((t=>{t.data=s(t.data,t.headers,e.transformResponse||[]),t.status>=200&&t.status<300?r(t):n(u.from(new Error("Request failed"),e,null,t))})).catch((t=>{n(u.from(t,e,null,null))}))}))}class l{constructor(){this.handlers=[]}use(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}forEach(e){this.handlers.forEach((t=>{null!==t&&e(t)}))}}function f(e){const t=new o(e),r=function(e){return t.request(e)};return Object.setPrototypeOf(r,o.prototype),Object.assign(r,t),r}const p={200:"OK",201:"Created",202:"Accepted",204:"No Content",400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout"},w=f(e);w.create=e=>f(e),exports.CancelToken=a,exports.FetcherError=u,exports.FetcherHeaders=c,exports.HTTP_STATUS_CODES=p,exports.InterceptorManager=l,exports.buildURL=t,exports.createInstance=f,exports.default=w,exports.fetchAdapter=h,exports.formatRequestBody=n,exports.mergeConfig=r,exports.transformData=s,exports.xhrAdapter=i;

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

const e={method:"GET",timeout:0,headers:{"Content-Type":"application/json"},transformRequest:[(e,t)=>e],transformResponse:[e=>e],adapter:"fetch"};function t(e,t){const r=t?new URLSearchParams(t).toString():"";return r?`${e}?${r}`:e}function r(e,t={}){const r={...e,...t};return e.headers&&t.headers&&(r.headers={...e.headers,...t.headers}),r}function s(e,t,r){return r.forEach((r=>{e=r(e,t)})),e}function n(e,t){if(!e)return null;if(t&&t.includes("application/json"))return JSON.stringify(e);if(t&&t.includes("multipart/form-data")){const t=new FormData;return Object.keys(e).forEach((r=>t.append(r,e[r]))),t}if(t&&t.includes("application/x-www-form-urlencoded")){const t=new URLSearchParams;return Object.keys(e).forEach((r=>t.append(r,e[r]))),t.toString()}return e}class o{constructor(t){this.defaults=r(e,t),this.interceptors={request:new l,response:new l}}async request(e){const s=Date.now(),o=r(this.defaults,e);o.url=t(o.url,o.params);const a=new i(o.headers);o.headers=a.toObject(),o.data&&(o.data=n(o.data,a.get("Content-Type")));const u=[d,void 0];this.interceptors.request.forEach((e=>{u.unshift(e.fulfilled,e.rejected)})),this.interceptors.response.forEach((e=>{u.push(e.fulfilled,e.rejected)}));let c=Promise.resolve(o);for(;u.length;)c=c.then(u.shift(),u.shift());try{const e=await c,t=Date.now();return e.duration=t-s,e.statusText=p[e.status]||"Unknown Status",e}catch(e){const t=Date.now();throw"object"==typeof e&&null!==e&&(e.duration=t-s),e}}get(e,t={}){return this.request({...t,method:"GET",url:e})}post(e,t,r={}){return this.request({...r,method:"POST",url:e,data:t})}put(e,t,r={}){return this.request({...r,method:"PUT",url:e,data:t})}delete(e,t={}){return this.request({...t,method:"DELETE",url:e})}}class a{constructor(e){if(this.reason=null,"function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((e=>{t=e})),e((e=>{this.reason||(this.reason=new Error(e),t(this.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}static source(){let e;return{token:new a((t=>{e=t})),cancel:e}}}class u extends Error{constructor(e,t,r,s,n){super(e),this.name="FetcherError",this.code=t,this.config=r,this.request=s,this.response=n,Error.captureStackTrace(this,this.constructor)}static from(e,t,r,s){return new u(e.message,e.name,t,r,s)}}class i{constructor(e){this.headers=e||{}}set(e,t){this.headers[e.toLowerCase()]=t}get(e){return this.headers[e.toLowerCase()]}remove(e){delete this.headers[e.toLowerCase()]}toObject(){return{...this.headers}}}function c(e){return new Promise(((t,r)=>{if("undefined"==typeof window||void 0===window.XMLHttpRequest)return void r(new Error("XMLHttpRequest is not supported in Node.js environment."));const{url:s,method:n,headers:o,data:a}=e,u=new XMLHttpRequest;u.open(n.toUpperCase(),s,!0),o&&Object.keys(o).forEach((e=>{u.setRequestHeader(e,o[e])})),u.onload=()=>{const r={data:u.response,status:u.status,statusText:u.statusText,headers:u.getAllResponseHeaders(),config:e,request:u};t(r)},u.onerror=()=>r(new Error("Network Error")),u.ontimeout=()=>r(new Error(`Timeout of ${e.timeout}ms exceeded`)),u.send(a)}))}function h(e){return new Promise(((t,r)=>{if("undefined"==typeof fetch)return void r(new Error("Fetch API not found in this environment."));const{url:s,method:n,headers:o,data:a}=e;fetch(s,{method:n,headers:o,body:a}).then((t=>t.json().then((r=>({data:r,status:t.status,statusText:t.statusText,headers:t.headers,config:e,request:t}))))).then(t).catch((e=>{r(e)}))}))}function d(e){const t="xhr"===e.adapter?c:h;return new Promise(((r,n)=>{e.cancelToken&&e.cancelToken.throwIfRequested(),t(e).then((t=>{t.data=s(t.data,t.headers,e.transformResponse||[]),t.status>=200&&t.status<300?r(t):n(u.from(new Error("Request failed"),e,null,t))})).catch((t=>{n(u.from(t,e,null,null))}))}))}class l{constructor(){this.handlers=[]}use(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}forEach(e){this.handlers.forEach((t=>{null!==t&&e(t)}))}}function f(e){const t=new o(e),r=o.prototype.request.bind(t);return Object.setPrototypeOf(r,o.prototype),Object.assign(r,t),r}const p={200:"OK",201:"Created",202:"Accepted",204:"No Content",400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout"},w=f(e);w.create=e=>f(e);export{a as CancelToken,u as FetcherError,i as FetcherHeaders,p as HTTP_STATUS_CODES,l as InterceptorManager,t as buildURL,f as createInstance,w as default,h as fetchAdapter,n as formatRequestBody,r as mergeConfig,s as transformData,c as xhrAdapter};
const e={method:"GET",timeout:0,headers:{"Content-Type":"application/json"},transformRequest:[(e,t)=>e],transformResponse:[e=>e],adapter:"fetch"};function t(e,t){const r=t?new URLSearchParams(t).toString():"";return r?`${e}?${r}`:e}function r(e,t={}){const r={...e,...t};return e.headers&&t.headers&&(r.headers={...e.headers,...t.headers}),r}function s(e,t,r){return r.forEach((r=>{e=r(e,t)})),e}function n(e,t){if(!e)return null;if(t&&t.includes("application/json"))return JSON.stringify(e);if(t&&t.includes("multipart/form-data")){const t=new FormData;return Object.keys(e).forEach((r=>t.append(r,e[r]))),t}if(t&&t.includes("application/x-www-form-urlencoded")){const t=new URLSearchParams;return Object.keys(e).forEach((r=>t.append(r,e[r]))),t.toString()}return e}class o{constructor(t){this.defaults=r(e,t),this.interceptors={request:new l,response:new l}}async request(e){const s=Date.now(),o=r(this.defaults,e);o.url=t(o.url,o.params);const a=new i(o.headers);o.headers=a.toObject(),o.data&&(o.data=n(o.data,a.get("Content-Type")));const u=[d,void 0];this.interceptors.request.forEach((e=>{u.unshift(e.fulfilled,e.rejected)})),this.interceptors.response.forEach((e=>{u.push(e.fulfilled,e.rejected)}));let c=Promise.resolve(o);for(;u.length;)c=c.then(u.shift(),u.shift());try{const e=await c,t=Date.now();return e.duration=t-s,e.statusText=p[e.status]||"Unknown Status",e}catch(e){const t=Date.now();throw"object"==typeof e&&null!==e&&(e.duration=t-s),e}}get(e,t={}){return this.request({...t,method:"GET",url:e})}post(e,t,r={}){return this.request({...r,method:"POST",url:e,data:t})}put(e,t,r={}){return this.request({...r,method:"PUT",url:e,data:t})}delete(e,t={}){return this.request({...t,method:"DELETE",url:e})}}class a{constructor(e){if(this.reason=null,"function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((e=>{t=e})),e((e=>{this.reason||(this.reason=new Error(e),t(this.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}static source(){let e;return{token:new a((t=>{e=t})),cancel:e}}}class u extends Error{constructor(e,t,r,s,n){super(e),this.name="FetcherError",this.code=t,this.config=r,this.request=s,this.response=n,Error.captureStackTrace(this,this.constructor)}static from(e,t,r,s){return new u(e.message,e.name,t,r,s)}}class i{constructor(e){this.headers=e||{}}set(e,t){this.headers[e.toLowerCase()]=t}get(e){return this.headers[e.toLowerCase()]}remove(e){delete this.headers[e.toLowerCase()]}toObject(){return{...this.headers}}}function c(e){return new Promise(((t,r)=>{if("undefined"==typeof window||void 0===window.XMLHttpRequest)return void r(new Error("XMLHttpRequest is not supported in Node.js environment."));const{url:s,method:n,headers:o,data:a}=e,u=new XMLHttpRequest;u.open(n.toUpperCase(),s,!0),o&&Object.keys(o).forEach((e=>{u.setRequestHeader(e,o[e])})),u.onload=()=>{const r={data:u.response,status:u.status,statusText:u.statusText,headers:u.getAllResponseHeaders(),config:e,request:u};t(r)},u.onerror=()=>r(new Error("Network Error")),u.ontimeout=()=>r(new Error(`Timeout of ${e.timeout}ms exceeded`)),u.send(a)}))}function h(e){return new Promise(((t,r)=>{if("undefined"==typeof fetch)return void r(new Error("Fetch API not found in this environment."));const{url:s,method:n,headers:o,data:a}=e;fetch(s,{method:n,headers:o,body:a}).then((t=>t.json().then((r=>({data:r,status:t.status,statusText:t.statusText,headers:t.headers,config:e,request:t}))))).then(t).catch((e=>{r(e)}))}))}function d(e){const t="xhr"===e.adapter?c:h;return new Promise(((r,n)=>{e.cancelToken&&e.cancelToken.throwIfRequested(),t(e).then((t=>{t.data=s(t.data,t.headers,e.transformResponse||[]),t.status>=200&&t.status<300?r(t):n(u.from(new Error("Request failed"),e,null,t))})).catch((t=>{n(u.from(t,e,null,null))}))}))}class l{constructor(){this.handlers=[]}use(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}forEach(e){this.handlers.forEach((t=>{null!==t&&e(t)}))}}function f(e){const t=new o(e),r=function(e){return t.request(e)};return Object.setPrototypeOf(r,o.prototype),Object.assign(r,t),r}const p={200:"OK",201:"Created",202:"Accepted",204:"No Content",400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout"},w=f(e);w.create=e=>f(e);export{a as CancelToken,u as FetcherError,i as FetcherHeaders,p as HTTP_STATUS_CODES,l as InterceptorManager,t as buildURL,f as createInstance,w as default,h as fetchAdapter,n as formatRequestBody,r as mergeConfig,s as transformData,c as xhrAdapter};
{
"name": "@svkhrobbeck/fetcher",
"version": "1.0.2",
"version": "1.0.3",
"main": "dist/index.cjs.js",

@@ -5,0 +5,0 @@ "module": "dist/index.esm.js",

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