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

xior

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xior - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

1

dist/index.esm.d.ts

@@ -92,2 +92,3 @@ export { merge } from 'ts-deepmerge';

config?: XiorRequestConfig;
defaults: XiorInterceptorRequestConfig;
constructor(options?: XiorRequestConfig);

@@ -94,0 +95,0 @@ private requestInterceptors;

2

dist/index.esm.js

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

import{merge as e}from"ts-deepmerge";export{merge}from"ts-deepmerge";function t(e,t){let r=new globalThis.AbortController;function s(e){r.abort(e),o()}let n=[];for(let t of e){if((null==t?void 0:t.aborted)===!0){s(t.reason);break}if((null==t?void 0:t.addEventListener)!=null){let e=()=>{s(t.reason)};n.push(()=>{(null==t?void 0:t.removeEventListener)!=null&&t.removeEventListener("abort",e)}),t.addEventListener("abort",e)}}function o(){n.forEach(e=>{e()}),null==t||t()}let a=r.signal;return a.clear=o,a}function r(e,t,r){let s=t?r(t):"";s&&(s=e.includes("?")?e+"&"+s:e+"?"+s);let[n,o]=s.split("?");if(o){let e=o.split("&");return`${n}?${e.sort().join("&")}`}return s||e}function s(e){return new Promise(t=>{setTimeout(()=>{t("ok")},e)})}function n(e,t=!0,r=null){if(null==e)return"";let s=[],o=t?encodeURIComponent:e=>e;for(let a in e)if(Object.prototype.hasOwnProperty.call(e,a)){let i=e[a],u=r?`${r}[${o(a)}]`:o(a);if("object"==typeof i){let e=n(i,t,u);""!==e&&s.push(e)}else Array.isArray(i)?i.forEach((e,t)=>{let r=`${u}[${t}]`;s.push(`${o(r)}=${o(e)}`)}):s.push(`${o(u)}=${o(i)}`)}return s.join("&")}function o(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}class a extends Error{constructor(e,t,r){super(e),this.request=t,this.config=t,this.response=r}}class i extends a{}function u(e,t,r,s,n,o,a){try{var i=e[o](a),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(s,n)}function l(){return(l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e}).apply(this,arguments)}let c="application/x-www-form-urlencoded",p="application/json";function d(e){return h.apply(this,arguments)}function h(){var t;return t=function*(t){let r=t.encode||t.paramsSerializer||n,s=!1!==t.encodeURI,o=t.method?t.method.toUpperCase():"GET",a=t.url||"",i=a,u=t.data,d=!1,h=(null==t?void 0:t.headers)||{};if(u&&!(u instanceof FormData)){let n="";if(null==t?void 0:t.headers){let e=Object.keys(t.headers).find(e=>"content-type"===e.toLowerCase());e&&(n=t.headers[e])}if(n||(n="GET"===o||"HEAD"===o?c:p,h["Content-Type"]=n),n===c&&("object"==typeof u||t.params)){d=!0;let n=r(e(u||{},t.params||{}),s);n&&(a=a.includes("?")?a+=`&${n}`:`${a}?${n}`),u=null}else n===p&&(u=JSON.stringify(u))}return!d&&t.params&&Object.keys(t.params).length>0&&(a=a.includes("?")?a+=`&${r(t.params,s)}`:`${a}?${r(t.params,s)}`),l({},t,{data:u,url:i,_url:a,method:o,headers:h,encode:r,paramsSerializer:r})},(h=function(){var e=this,r=arguments;return new Promise(function(s,n){var o=t.apply(e,r);function a(e){u(o,s,n,a,i,"next",e)}function i(e){u(o,s,n,a,i,"throw",e)}a(void 0)})}).apply(this,arguments)}function f(e,t,r,s,n,o,a){try{var i=e[o](a),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(s,n)}function y(e){return function(){var t=this,r=arguments;return new Promise(function(s,n){var o=e.apply(t,r);function a(e){f(o,s,n,a,i,"next",e)}function i(e){f(o,s,n,a,i,"throw",e)}a(void 0)})}}function m(){return(m=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e}).apply(this,arguments)}let v="undefined"!=typeof AbortController;class g{static create(e){return new g(e)}get interceptors(){return{request:{use:(e,t)=>(this.requestInterceptors.push(e),e),eject:e=>{this.requestInterceptors=this.requestInterceptors.filter(t=>t!==e)},clear:()=>{this.requestInterceptors=[this.requestInterceptors[0]]}},response:{use:(e,t)=>(this.responseInterceptors.push({fn:e,onRejected:t}),e),eject:e=>{this.responseInterceptors=this.responseInterceptors.filter(t=>t.fn!==e)},clear:()=>{this.responseInterceptors=[]}}}}get plugins(){return{use:e=>(this._plugins.push(e),e),eject:e=>{this._plugins=this._plugins.filter(t=>t!==e)},clear:()=>{this._plugins=[]}}}request(t){var r=this;return y(function*(){let s=e({},r.config||{},"string"==typeof t?{url:t}:t||{},{headers:{},params:{}});for(let e of r.requestInterceptors)s=yield e(s);let n=r.handlerFetch.bind(r);return r._plugins.forEach(e=>{n=e(n)}),n(s)})()}handlerFetch(e){var r=this;return y(function*(){var s;let n,u;let{url:l,method:c,headers:p,timeout:d,signal:h,data:f}=e,y=function(e,t){if(null==e)return{};var r,s,n={},o=Object.keys(e);for(s=0;s<o.length;s++)t.indexOf(r=o[s])>=0||(n[r]=e[r]);return n}(e,["url","method","headers","timeout","signal","data"]),g=[];if(d&&v){let t=new AbortController;u=setTimeout(()=>{t.abort(new i(`timeout of ${d}ms exceeded`,e))},d),g.push(t.signal)}h&&g.push(h),n=g[0],g.length>1&&(n=t(g,()=>{clearTimeout(u)}));let T=e._url||l||"";e.baseURL&&!o(T)&&(T=(e.baseURL.endsWith("/")?e.baseURL:e.baseURL+"/")+(T.startsWith("/")?T.slice(1):T));let b=yield fetch(T,m({body:["HEAD","GET"].includes(e.method||"GET")?void 0:f},y,{signal:n,method:c,headers:p}));if(u&&clearTimeout(u),null==n||null==(s=n.clear)||s.call(n),!b.ok){let t;try{(t=yield b.text())&&(t=JSON.parse(t))}catch(e){}let s=new a(b.status?`Request failed with status code ${b.status}`:"Network error",e,{response:b,data:t,config:e,status:b.status,statusText:b.statusText,headers:b.headers});for(let e of r.responseInterceptors)e.onRejected&&(yield e.onRejected(s));throw s}if("HEAD"===e.method)return{data:void 0,request:e,config:e,response:b,headers:b.headers,status:b.status,statusText:b.statusText};if(!e.responseType||"json"===e.responseType||"text"===e.responseType){let t;try{t={data:yield b.text()};try{t.data&&"text"!==e.responseType&&(t.data=JSON.parse(t.data))}catch(e){}}catch(e){t={data:void 0}}let s={data:t.data,request:e,response:b};for(let e of r.responseInterceptors)s=yield e.fn(s);return{data:s.data,request:e,config:e,response:b,headers:b.headers,status:b.status,statusText:b.statusText}}return{data:void 0,request:e,config:e,response:b,headers:b.headers,status:b.status,statusText:b.statusText}})()}createGetHandler(e){return(t,r)=>this.request(r?m({},r,{method:e,url:t}):{method:e,url:t})}createPostHandler(e){return(t,r,s)=>this.request(s?m({},s,{method:e,url:t,data:r}):{method:e,url:t,data:r})}get(e,t){return this.createGetHandler("GET")(e,t)}head(e,t){return this.createGetHandler("HEAD")(e,t)}post(e,t,r){return this.createPostHandler("POST")(e,t,r)}put(e,t,r){return this.createPostHandler("PUT")(e,t,r)}patch(e,t,r){return this.createPostHandler("PATCH")(e,t,r)}delete(e,t){return this.createGetHandler("DELETE")(e,t)}options(e,t,r){return this.createPostHandler("OPTIONS")(e,t,r)}constructor(e){this.requestInterceptors=[d],this.responseInterceptors=[],this._plugins=[],this.config=e}}export{a as XiorError,i as XiorTimeoutError,t as anySignal,r as buildSortedURL,g as default,s as delay,n as encodeParams,o as isAbsoluteURL,g as xior};
import{merge as e}from"ts-deepmerge";export{merge}from"ts-deepmerge";function t(e,t){let r=new globalThis.AbortController;function s(e){r.abort(e),o()}let n=[];for(let t of e){if((null==t?void 0:t.aborted)===!0){s(t.reason);break}if((null==t?void 0:t.addEventListener)!=null){let e=()=>{s(t.reason)};n.push(()=>{(null==t?void 0:t.removeEventListener)!=null&&t.removeEventListener("abort",e)}),t.addEventListener("abort",e)}}function o(){n.forEach(e=>{e()}),null==t||t()}let a=r.signal;return a.clear=o,a}function r(e,t,r){let s=t?r(t):"";s&&(s=e.includes("?")?e+"&"+s:e+"?"+s);let[n,o]=s.split("?");if(o){let e=o.split("&");return`${n}?${e.sort().join("&")}`}return s||e}function s(e){return new Promise(t=>{setTimeout(()=>{t("ok")},e)})}function n(e,t=!0,r=null){if(null==e)return"";let s=[],o=t?encodeURIComponent:e=>e;for(let a in e)if(Object.prototype.hasOwnProperty.call(e,a)){let i=e[a],u=r?`${r}[${o(a)}]`:o(a);if("object"==typeof i){let e=n(i,t,u);""!==e&&s.push(e)}else Array.isArray(i)?i.forEach((e,t)=>{let r=`${u}[${t}]`;s.push(`${o(r)}=${o(e)}`)}):s.push(`${o(u)}=${o(i)}`)}return s.join("&")}function o(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}class a extends Error{constructor(e,t,r){super(e),this.request=t,this.config=t,this.response=r}}class i extends a{}function u(e,t,r,s,n,o,a){try{var i=e[o](a),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(s,n)}function l(){return(l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e}).apply(this,arguments)}let c="application/x-www-form-urlencoded",p="application/json";function d(e){return h.apply(this,arguments)}function h(){var t;return t=function*(t){let r=t.encode||t.paramsSerializer||n,s=!1!==t.encodeURI,o=t.method?t.method.toUpperCase():"GET",a=t.url||"",i=a,u=t.data,d=!1,h=(null==t?void 0:t.headers)||{};if(u&&!(u instanceof FormData)){let n="";if(null==t?void 0:t.headers){let e=Object.keys(t.headers).find(e=>"content-type"===e.toLowerCase());e&&(n=t.headers[e])}if(n||(n="GET"===o||"HEAD"===o?c:p,h["Content-Type"]=n),n===c&&("object"==typeof u||t.params)){d=!0;let n=r(e(u||{},t.params||{}),s);n&&(a=a.includes("?")?a+=`&${n}`:`${a}?${n}`),u=null}else n===p&&(u=JSON.stringify(u))}return!d&&t.params&&Object.keys(t.params).length>0&&(a=a.includes("?")?a+=`&${r(t.params,s)}`:`${a}?${r(t.params,s)}`),l({},t,{data:u,url:i,_url:a,method:o,headers:h,encode:r,paramsSerializer:r})},(h=function(){var e=this,r=arguments;return new Promise(function(s,n){var o=t.apply(e,r);function a(e){u(o,s,n,a,i,"next",e)}function i(e){u(o,s,n,a,i,"throw",e)}a(void 0)})}).apply(this,arguments)}function f(e,t,r,s,n,o,a){try{var i=e[o](a),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(s,n)}function y(e){return function(){var t=this,r=arguments;return new Promise(function(s,n){var o=e.apply(t,r);function a(e){f(o,s,n,a,i,"next",e)}function i(e){f(o,s,n,a,i,"throw",e)}a(void 0)})}}function m(){return(m=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e}).apply(this,arguments)}let v="undefined"!=typeof AbortController;class g{static create(e){return new g(e)}get interceptors(){return{request:{use:(e,t)=>(this.requestInterceptors.push(e),e),eject:e=>{this.requestInterceptors=this.requestInterceptors.filter(t=>t!==e)},clear:()=>{this.requestInterceptors=[this.requestInterceptors[0]]}},response:{use:(e,t)=>(this.responseInterceptors.push({fn:e,onRejected:t}),e),eject:e=>{this.responseInterceptors=this.responseInterceptors.filter(t=>t.fn!==e)},clear:()=>{this.responseInterceptors=[]}}}}get plugins(){return{use:e=>(this._plugins.push(e),e),eject:e=>{this._plugins=this._plugins.filter(t=>t!==e)},clear:()=>{this._plugins=[]}}}request(t){var r=this;return y(function*(){let s=e({},r.config||{},r.defaults||{},"string"==typeof t?{url:t}:t||{},{headers:{},params:{}});for(let e of r.requestInterceptors)s=yield e(s);let n=r.handlerFetch.bind(r);return r._plugins.forEach(e=>{n=e(n)}),n(s)})()}handlerFetch(e){var r=this;return y(function*(){var s;let n,u;let{url:l,method:c,headers:p,timeout:d,signal:h,data:f}=e,y=function(e,t){if(null==e)return{};var r,s,n={},o=Object.keys(e);for(s=0;s<o.length;s++)t.indexOf(r=o[s])>=0||(n[r]=e[r]);return n}(e,["url","method","headers","timeout","signal","data"]),g=[];if(d&&v){let t=new AbortController;u=setTimeout(()=>{t.abort(new i(`timeout of ${d}ms exceeded`,e))},d),g.push(t.signal)}h&&g.push(h),n=g[0],g.length>1&&(n=t(g,()=>{clearTimeout(u)}));let T=e._url||l||"";e.baseURL&&!o(T)&&(T=(e.baseURL.endsWith("/")?e.baseURL:e.baseURL+"/")+(T.startsWith("/")?T.slice(1):T));let b=yield fetch(T,m({body:["HEAD","GET"].includes(e.method||"GET")?void 0:f},y,{signal:n,method:c,headers:p}));if(u&&clearTimeout(u),null==n||null==(s=n.clear)||s.call(n),!b.ok){let t;try{(t=yield b.text())&&(t=JSON.parse(t))}catch(e){}let s=new a(b.status?`Request failed with status code ${b.status}`:"Network error",e,{response:b,data:t,config:e,status:b.status,statusText:b.statusText,headers:b.headers});for(let e of r.responseInterceptors)e.onRejected&&(yield e.onRejected(s));throw s}if("HEAD"===e.method)return{data:void 0,request:e,config:e,response:b,headers:b.headers,status:b.status,statusText:b.statusText};if(!e.responseType||"json"===e.responseType||"text"===e.responseType){let t;try{t={data:yield b.text()};try{t.data&&"text"!==e.responseType&&(t.data=JSON.parse(t.data))}catch(e){}}catch(e){t={data:void 0}}let s={data:t.data,request:e,response:b};for(let e of r.responseInterceptors)s=yield e.fn(s);return{data:s.data,request:e,config:e,response:b,headers:b.headers,status:b.status,statusText:b.statusText}}return{data:void 0,request:e,config:e,response:b,headers:b.headers,status:b.status,statusText:b.statusText}})()}createGetHandler(e){return(t,r)=>this.request(r?m({},r,{method:e,url:t}):{method:e,url:t})}createPostHandler(e){return(t,r,s)=>this.request(s?m({},s,{method:e,url:t,data:r}):{method:e,url:t,data:r})}get(e,t){return this.createGetHandler("GET")(e,t)}head(e,t){return this.createGetHandler("HEAD")(e,t)}post(e,t,r){return this.createPostHandler("POST")(e,t,r)}put(e,t,r){return this.createPostHandler("PUT")(e,t,r)}patch(e,t,r){return this.createPostHandler("PATCH")(e,t,r)}delete(e,t){return this.createGetHandler("DELETE")(e,t)}options(e,t,r){return this.createPostHandler("OPTIONS")(e,t,r)}constructor(e){this.requestInterceptors=[d],this.responseInterceptors=[],this._plugins=[],this.config=e,this.defaults={params:{},headers:{}}}}export{a as XiorError,i as XiorTimeoutError,t as anySignal,r as buildSortedURL,g as default,s as delay,n as encodeParams,o as isAbsoluteURL,g as xior};

@@ -92,2 +92,3 @@ export { merge } from 'ts-deepmerge';

config?: XiorRequestConfig;
defaults: XiorInterceptorRequestConfig;
constructor(options?: XiorRequestConfig);

@@ -94,0 +95,0 @@ private requestInterceptors;

{
"name": "xior",
"version": "0.1.3",
"version": "0.1.4",
"description": "A lite request lib based on **fetch** with plugins support, and axios similar API",

@@ -5,0 +5,0 @@ "repository": "suhaotian/xior",

@@ -75,2 +75,4 @@ [![Build](https://github.com/suhaotian/xior/actions/workflows/check.yml/badge.svg)](https://github.com/suhaotian/xior/actions/workflows/check.yml)

> If you want proxy support, use `axios`, because `xior` doesn't support proxy feature yet
While popular and convenient, Axios currently lacks native edge runtime support (see: [https://github.com/axios/axios/issues/5523](https://github.com/axios/axios/issues/5523)). This can be an issue for specific use cases like Next.js serverless functions and middleware files, where fetch offers built-in caching and revalidation mechanisms (see: [https://nextjs.org/docs/app/api-reference/functions/fetch](https://nextjs.org/docs/app/api-reference/functions/fetch)).

@@ -77,0 +79,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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