Comparing version 0.3.0 to 0.4.0
@@ -14,2 +14,4 @@ declare var _default: { | ||
/** @public @type {BodylessMethod} */ | ||
head<T_3 = any>(url: string, config?: Options | undefined): Promise<Response<T_3>>; | ||
/** @public @type {BodylessMethod} */ | ||
options<T_3 = any>(url: string, config?: Options | undefined): Promise<Response<T_3>>; | ||
@@ -38,7 +40,7 @@ /** @public @type {BodyMethod} */ | ||
* @public | ||
* @template T,R | ||
* @param {(...args: T[]) => R} fn | ||
* @returns {(array: T[]) => R} | ||
* @template Args, R | ||
* @param {(...args: Args[]) => R} fn | ||
* @returns {(array: Args[]) => R} | ||
*/ | ||
spread<T_7, R>(fn: (...args: T_8[]) => R): (array: T_8[]) => R; | ||
spread<Args, R>(fn: (...args: Args[]) => R): (array: Args[]) => R; | ||
/** | ||
@@ -45,0 +47,0 @@ * @public |
@@ -1,2 +0,2 @@ | ||
var t=function t(e){function r(t,e,n){var a,o={};if(Array.isArray(t))return t.concat(e);for(a in t)o[n?a.toLowerCase():a]=t[a];for(a in e){var i=n?a.toLowerCase():a,u=e[a];o[i]=i in o&&"object"==typeof u?r(o[i],u,"headers"===i):u}return o}function n(t,n,a,o){"string"!=typeof t&&(t=(n=t).url);var i={config:n},u=r(e,n),s={},c=o||u.data;(u.transformRequest||[]).map(function(t){c=t(c,u.headers)||c}),c&&"object"==typeof c&&"function"!=typeof c.append&&(c=JSON.stringify(c),s["content-type"]="application/json");var f=document.cookie.match(RegExp("(^|; )"+u.xsrfCookieName+"=([^;]*)"));if(f&&(s[u.xsrfHeaderName]=f[2]),u.auth&&(s.authorization=u.auth),u.baseURL&&(t=new URL(t,u.baseURL)+""),u.params){var p=~t.indexOf("?")?"&":"?";t+=p+(u.paramsSerializer?u.paramsSerializer(u.params):new URLSearchParams(u.params))}return(u.fetch||fetch)(t,{method:a||u.method,body:c,headers:r(u.headers,s,!0),credentials:u.withCredentials?"include":void 0}).then(function(t){for(var e in t)"function"!=typeof t[e]&&(i[e]=t[e]);return(u.validateStatus?u.validateStatus(t.status):t.ok)?"stream"==u.responseType?(i.data=t.body,i):t[u.responseType||"text"]().then(function(t){i.data=t,i.data=JSON.parse(t)}).catch(Object).then(function(){return i}):Promise.reject(i)})}return e=e||{},n.request=n,n.get=function(t,e){return n(t,e,"get")},n.delete=function(t,e){return n(t,e,"delete")},n.options=function(t,e){return n(t,e,"options")},n.post=function(t,e,r){return n(t,r,"post",e)},n.put=function(t,e,r){return n(t,r,"put",e)},n.patch=function(t,e,r){return n(t,r,"patch",e)},n.all=Promise.all,n.spread=function(t){return function(e){return t.apply(this,e)}},n.CancelToken="function"==typeof AbortController?AbortController:Object,n.defaults=e,n.create=t,n}();module.exports=t; | ||
var e=function e(t){function r(e,t,n){var a,o={};if(Array.isArray(e))return e.concat(t);for(a in e)o[n?a.toLowerCase():a]=e[a];for(a in t){var i=n?a.toLowerCase():a,u=t[a];o[i]=i in o&&"object"==typeof u?r(o[i],u,"headers"===i):u}return o}function n(e,n,a,o){"string"!=typeof e&&(e=(n=e).url);var i={config:n},u=r(t,n),s={},c=o||u.data;(u.transformRequest||[]).map(function(e){c=e(c,u.headers)||c}),c&&"object"==typeof c&&"function"!=typeof c.append&&(c=JSON.stringify(c),s["content-type"]="application/json");var f="undefined"!=typeof document&&document.cookie.match(RegExp("(^|; )"+u.xsrfCookieName+"=([^;]*)"));if(f&&(s[u.xsrfHeaderName]=f[2]),u.auth&&(s.authorization=u.auth),u.baseURL&&(e=e.replace(/^(?!.*\/\/)\/?(.*)$/,u.baseURL+"/$1")),u.params){var p=~e.indexOf("?")?"&":"?";e+=p+(u.paramsSerializer?u.paramsSerializer(u.params):new URLSearchParams(u.params))}return(u.fetch||fetch)(e,{method:a||u.method,body:c,headers:r(u.headers,s,!0),credentials:u.withCredentials?"include":"same-origin"}).then(function(e){for(var t in e)"function"!=typeof e[t]&&(i[t]=e[t]);var r=u.validateStatus?u.validateStatus(e.status):e.ok;return"stream"==u.responseType?(i.data=e.body,i):e[u.responseType||"text"]().then(function(e){i.data=e,i.data=JSON.parse(e)}).catch(Object).then(function(){return r?i:Promise.reject(i)})})}return t=t||{},n.request=n,n.get=function(e,t){return n(e,t,"get")},n.delete=function(e,t){return n(e,t,"delete")},n.head=function(e,t){return n(e,t,"head")},n.options=function(e,t){return n(e,t,"options")},n.post=function(e,t,r){return n(e,r,"post",t)},n.put=function(e,t,r){return n(e,r,"put",t)},n.patch=function(e,t,r){return n(e,r,"patch",t)},n.all=Promise.all.bind(Promise),n.spread=function(e){return function(t){return e.apply(this,t)}},n.CancelToken="function"==typeof AbortController?AbortController:Object,n.defaults=t,n.create=e,n}();module.exports=e; | ||
//# sourceMappingURL=redaxios.js.map |
@@ -1,2 +0,2 @@ | ||
export default(function t(e){function r(t,e,n){var a,o={};if(Array.isArray(t))return t.concat(e);for(a in t)o[n?a.toLowerCase():a]=t[a];for(a in e){var i=n?a.toLowerCase():a,u=e[a];o[i]=i in o&&"object"==typeof u?r(o[i],u,"headers"===i):u}return o}function n(t,n,a,o){"string"!=typeof t&&(t=(n=t).url);var i={config:n},u=r(e,n),s={},c=o||u.data;(u.transformRequest||[]).map(function(t){c=t(c,u.headers)||c}),c&&"object"==typeof c&&"function"!=typeof c.append&&(c=JSON.stringify(c),s["content-type"]="application/json");var f=document.cookie.match(RegExp("(^|; )"+u.xsrfCookieName+"=([^;]*)"));if(f&&(s[u.xsrfHeaderName]=f[2]),u.auth&&(s.authorization=u.auth),u.baseURL&&(t=new URL(t,u.baseURL)+""),u.params){var p=~t.indexOf("?")?"&":"?";t+=p+(u.paramsSerializer?u.paramsSerializer(u.params):new URLSearchParams(u.params))}return(u.fetch||fetch)(t,{method:a||u.method,body:c,headers:r(u.headers,s,!0),credentials:u.withCredentials?"include":void 0}).then(function(t){for(var e in t)"function"!=typeof t[e]&&(i[e]=t[e]);return(u.validateStatus?u.validateStatus(t.status):t.ok)?"stream"==u.responseType?(i.data=t.body,i):t[u.responseType||"text"]().then(function(t){i.data=t,i.data=JSON.parse(t)}).catch(Object).then(function(){return i}):Promise.reject(i)})}return e=e||{},n.request=n,n.get=function(t,e){return n(t,e,"get")},n.delete=function(t,e){return n(t,e,"delete")},n.options=function(t,e){return n(t,e,"options")},n.post=function(t,e,r){return n(t,r,"post",e)},n.put=function(t,e,r){return n(t,r,"put",e)},n.patch=function(t,e,r){return n(t,r,"patch",e)},n.all=Promise.all,n.spread=function(t){return function(e){return t.apply(this,e)}},n.CancelToken="function"==typeof AbortController?AbortController:Object,n.defaults=e,n.create=t,n}()); | ||
export default(function e(t){function r(e,t,n){var a,o={};if(Array.isArray(e))return e.concat(t);for(a in e)o[n?a.toLowerCase():a]=e[a];for(a in t){var i=n?a.toLowerCase():a,u=t[a];o[i]=i in o&&"object"==typeof u?r(o[i],u,"headers"===i):u}return o}function n(e,n,a,o){"string"!=typeof e&&(e=(n=e).url);var i={config:n},u=r(t,n),s={},c=o||u.data;(u.transformRequest||[]).map(function(e){c=e(c,u.headers)||c}),c&&"object"==typeof c&&"function"!=typeof c.append&&(c=JSON.stringify(c),s["content-type"]="application/json");var f="undefined"!=typeof document&&document.cookie.match(RegExp("(^|; )"+u.xsrfCookieName+"=([^;]*)"));if(f&&(s[u.xsrfHeaderName]=f[2]),u.auth&&(s.authorization=u.auth),u.baseURL&&(e=e.replace(/^(?!.*\/\/)\/?(.*)$/,u.baseURL+"/$1")),u.params){var p=~e.indexOf("?")?"&":"?";e+=p+(u.paramsSerializer?u.paramsSerializer(u.params):new URLSearchParams(u.params))}return(u.fetch||fetch)(e,{method:a||u.method,body:c,headers:r(u.headers,s,!0),credentials:u.withCredentials?"include":"same-origin"}).then(function(e){for(var t in e)"function"!=typeof e[t]&&(i[t]=e[t]);var r=u.validateStatus?u.validateStatus(e.status):e.ok;return"stream"==u.responseType?(i.data=e.body,i):e[u.responseType||"text"]().then(function(e){i.data=e,i.data=JSON.parse(e)}).catch(Object).then(function(){return r?i:Promise.reject(i)})})}return t=t||{},n.request=n,n.get=function(e,t){return n(e,t,"get")},n.delete=function(e,t){return n(e,t,"delete")},n.head=function(e,t){return n(e,t,"head")},n.options=function(e,t){return n(e,t,"options")},n.post=function(e,t,r){return n(e,r,"post",t)},n.put=function(e,t,r){return n(e,r,"put",t)},n.patch=function(e,t,r){return n(e,r,"patch",t)},n.all=Promise.all.bind(Promise),n.spread=function(e){return function(t){return e.apply(this,t)}},n.CancelToken="function"==typeof AbortController?AbortController:Object,n.defaults=t,n.create=e,n}()); | ||
//# sourceMappingURL=redaxios.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.redaxios=t()}(this,function(){return function e(t){function n(e,t,r){var o,a={};if(Array.isArray(e))return e.concat(t);for(o in e)a[r?o.toLowerCase():o]=e[o];for(o in t){var i=r?o.toLowerCase():o,u=t[o];a[i]=i in a&&"object"==typeof u?n(a[i],u,"headers"===i):u}return a}function r(e,r,o,a){"string"!=typeof e&&(e=(r=e).url);var i={config:r},u=n(t,r),f={},s=a||u.data;(u.transformRequest||[]).map(function(e){s=e(s,u.headers)||s}),s&&"object"==typeof s&&"function"!=typeof s.append&&(s=JSON.stringify(s),f["content-type"]="application/json");var c=document.cookie.match(RegExp("(^|; )"+u.xsrfCookieName+"=([^;]*)"));if(c&&(f[u.xsrfHeaderName]=c[2]),u.auth&&(f.authorization=u.auth),u.baseURL&&(e=new URL(e,u.baseURL)+""),u.params){var p=~e.indexOf("?")?"&":"?";e+=p+(u.paramsSerializer?u.paramsSerializer(u.params):new URLSearchParams(u.params))}return(u.fetch||fetch)(e,{method:o||u.method,body:s,headers:n(u.headers,f,!0),credentials:u.withCredentials?"include":void 0}).then(function(e){for(var t in e)"function"!=typeof e[t]&&(i[t]=e[t]);return(u.validateStatus?u.validateStatus(e.status):e.ok)?"stream"==u.responseType?(i.data=e.body,i):e[u.responseType||"text"]().then(function(e){i.data=e,i.data=JSON.parse(e)}).catch(Object).then(function(){return i}):Promise.reject(i)})}return t=t||{},r.request=r,r.get=function(e,t){return r(e,t,"get")},r.delete=function(e,t){return r(e,t,"delete")},r.options=function(e,t){return r(e,t,"options")},r.post=function(e,t,n){return r(e,n,"post",t)},r.put=function(e,t,n){return r(e,n,"put",t)},r.patch=function(e,t,n){return r(e,n,"patch",t)},r.all=Promise.all,r.spread=function(e){return function(t){return e.apply(this,t)}},r.CancelToken="function"==typeof AbortController?AbortController:Object,r.defaults=t,r.create=e,r}()}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.redaxios=t()}(this,function(){return function e(t){function n(e,t,r){var o,a={};if(Array.isArray(e))return e.concat(t);for(o in e)a[r?o.toLowerCase():o]=e[o];for(o in t){var i=r?o.toLowerCase():o,u=t[o];a[i]=i in a&&"object"==typeof u?n(a[i],u,"headers"===i):u}return a}function r(e,r,o,a){"string"!=typeof e&&(e=(r=e).url);var i={config:r},u=n(t,r),f={},s=a||u.data;(u.transformRequest||[]).map(function(e){s=e(s,u.headers)||s}),s&&"object"==typeof s&&"function"!=typeof s.append&&(s=JSON.stringify(s),f["content-type"]="application/json");var c="undefined"!=typeof document&&document.cookie.match(RegExp("(^|; )"+u.xsrfCookieName+"=([^;]*)"));if(c&&(f[u.xsrfHeaderName]=c[2]),u.auth&&(f.authorization=u.auth),u.baseURL&&(e=e.replace(/^(?!.*\/\/)\/?(.*)$/,u.baseURL+"/$1")),u.params){var p=~e.indexOf("?")?"&":"?";e+=p+(u.paramsSerializer?u.paramsSerializer(u.params):new URLSearchParams(u.params))}return(u.fetch||fetch)(e,{method:o||u.method,body:s,headers:n(u.headers,f,!0),credentials:u.withCredentials?"include":"same-origin"}).then(function(e){for(var t in e)"function"!=typeof e[t]&&(i[t]=e[t]);var n=u.validateStatus?u.validateStatus(e.status):e.ok;return"stream"==u.responseType?(i.data=e.body,i):e[u.responseType||"text"]().then(function(e){i.data=e,i.data=JSON.parse(e)}).catch(Object).then(function(){return n?i:Promise.reject(i)})})}return t=t||{},r.request=r,r.get=function(e,t){return r(e,t,"get")},r.delete=function(e,t){return r(e,t,"delete")},r.head=function(e,t){return r(e,t,"head")},r.options=function(e,t){return r(e,t,"options")},r.post=function(e,t,n){return r(e,n,"post",t)},r.put=function(e,t,n){return r(e,n,"put",t)},r.patch=function(e,t,n){return r(e,n,"patch",t)},r.all=Promise.all.bind(Promise),r.spread=function(e){return function(t){return e.apply(this,t)}},r.CancelToken="function"==typeof AbortController?AbortController:Object,r.defaults=t,r.create=e,r}()}); | ||
//# sourceMappingURL=redaxios.umd.js.map |
{ | ||
"name": "redaxios", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "The API from Axios, as a tiny abstraction over Fetch.", | ||
@@ -68,5 +68,5 @@ "source": "src/index.js", | ||
"prettier": "2.0.5", | ||
"typescript": "3.9.3", | ||
"typescript": "3.9.7", | ||
"webpack": "^4.41.5" | ||
} | ||
} |
@@ -85,2 +85,5 @@ /** | ||
/** @public @type {BodylessMethod} */ | ||
redaxios.head = (url, config) => redaxios(url, config, 'head'); | ||
/** @public @type {BodylessMethod} */ | ||
redaxios.options = (url, config) => redaxios(url, config, 'options'); | ||
@@ -98,9 +101,9 @@ | ||
/** @public */ | ||
redaxios.all = Promise.all; | ||
redaxios.all = Promise.all.bind(Promise); | ||
/** | ||
* @public | ||
* @template T,R | ||
* @param {(...args: T[]) => R} fn | ||
* @returns {(array: T[]) => R} | ||
* @template Args, R | ||
* @param {(...args: Args[]) => R} fn | ||
* @returns {(array: Args[]) => R} | ||
*/ | ||
@@ -175,3 +178,4 @@ redaxios.spread = function (fn) { | ||
const m = document.cookie.match(RegExp('(^|; )' + options.xsrfCookieName + '=([^;]*)')); | ||
const m = | ||
typeof document !== 'undefined' && document.cookie.match(RegExp('(^|; )' + options.xsrfCookieName + '=([^;]*)')); | ||
if (m) customHeaders[options.xsrfHeaderName] = m[2]; | ||
@@ -184,3 +188,3 @@ | ||
if (options.baseURL) { | ||
url = new URL(url, options.baseURL) + ''; | ||
url = url.replace(/^(?!.*\/\/)\/?(.*)$/, options.baseURL + '/$1'); | ||
} | ||
@@ -202,3 +206,3 @@ | ||
headers: deepMerge(options.headers, customHeaders, true), | ||
credentials: options.withCredentials ? 'include' : undefined | ||
credentials: options.withCredentials ? 'include' : 'same-origin' | ||
}).then((res) => { | ||
@@ -210,3 +214,2 @@ for (const i in res) { | ||
const ok = options.validateStatus ? options.validateStatus(res.status) : res.ok; | ||
if (!ok) return Promise.reject(response); | ||
@@ -225,3 +228,3 @@ if (options.responseType == 'stream') { | ||
.catch(Object) | ||
.then(() => response); | ||
.then(() => (ok ? response : Promise.reject(response))); | ||
}); | ||
@@ -228,0 +231,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
69197
383
4