Socket
Socket
Sign inDemoInstall

redaxios

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redaxios - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

137

dist/index.d.ts
declare var _default: {
<T>(url: string | Options, config?: Options | undefined, _method?: any, _data?: any): Promise<Response<T>>;
<T>(urlOrConfig: string | Options, config?: Options | undefined, _method?: any, data?: any, _undefined?: undefined): Promise<Response<T>>;
/**

@@ -57,3 +57,3 @@ * @public

*/
create: (defaults?: Options) => any;
create: typeof create;
};

@@ -73,3 +73,3 @@ export default _default;

*/
headers?: Headers;
headers?: RequestHeaders;
/**

@@ -114,3 +114,5 @@ * a body, optionally encoded, to send

*/
transformRequest?: ((body: any, headers: Headers) => any | null)[];
transformRequest?: ((body: any, headers?: {
[name: string]: string;
} | Headers | undefined) => any | null)[];
/**

@@ -126,5 +128,5 @@ * a base URL from which to resolve all URLs

};
export type Headers = {
export type RequestHeaders = {
[name: string]: string;
};
} | Headers;
export type Response<T> = {

@@ -150,2 +152,125 @@ status: number;

export type BodyMethod = <T = any>(url: string, body?: any, config?: Options | undefined) => Promise<Response<T>>;
/**
* Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @public
* @typedef Options
* @property {string} [url] the URL to request
* @property {'get'|'post'|'put'|'patch'|'delete'|'options'|'head'|'GET'|'POST'|'PUT'|'PATCH'|'DELETE'|'OPTIONS'|'HEAD'} [method="get"] HTTP method, case-insensitive
* @property {RequestHeaders} [headers] Request headers
* @property {FormData|string|object} [body] a body, optionally encoded, to send
* @property {'text'|'json'|'stream'|'blob'|'arrayBuffer'|'formData'|'stream'} [responseType="json"] An encoding to use for the response
* @property {Record<string,any>|URLSearchParams} [params] querystring parameters
* @property {(params: Options['params']) => string} [paramsSerializer] custom function to stringify querystring parameters
* @property {boolean} [withCredentials] Send the request with credentials like cookies
* @property {string} [auth] Authorization header value to send with the request
* @property {string} [xsrfCookieName] Pass an Cross-site Request Forgery prevention cookie value as a header defined by `xsrfHeaderName`
* @property {string} [xsrfHeaderName] The name of a header to use for passing XSRF cookies
* @property {(status: number) => boolean} [validateStatus] Override status code handling (default: 200-399 is a success)
* @property {Array<(body: any, headers?: RequestHeaders) => any?>} [transformRequest] An array of transformations to apply to the outgoing request
* @property {string} [baseURL] a base URL from which to resolve all URLs
* @property {typeof window.fetch} [fetch] Custom window.fetch implementation
* @property {any} [data]
*/
/**
* @public
* @typedef RequestHeaders
* @type {{[name: string]: string} | Headers}
*/
/**
* @public
* @template T
* @typedef Response
* @property {number} status
* @property {string} statusText
* @property {Options} config the request configuration
* @property {T} data the decoded response body
* @property {Headers} headers
* @property {boolean} redirect
* @property {string} url
* @property {ResponseType} type
* @property {ReadableStream<Uint8Array> | null} body
* @property {boolean} bodyUsed
*/
/**
* @typedef BodylessMethod
* @type {<T=any>(url: string, config?: Options) => Promise<Response<T>>}
*/
/**
* @typedef BodyMethod
* @type {<T=any>(url: string, body?: any, config?: Options) => Promise<Response<T>>}
*/
/**
* @public
* @param {Options} [defaults = {}]
* @returns {redaxios}
*/
declare function create(defaults?: Options | undefined): {
<T>(urlOrConfig: string | Options, config?: Options | undefined, _method?: any, data?: any, _undefined?: undefined): Promise<Response<T>>;
/**
* @public
* @template T
* @type {(<T = any>(config?: Options) => Promise<Response<T>>) | (<T = any>(url: string, config?: Options) => Promise<Response<T>>)}
*/
request: (<T_1 = any>(config?: Options | undefined) => Promise<Response<T_1>>) | (<T_2 = any>(url: string, config?: Options | undefined) => Promise<Response<T_2>>);
/** @public @type {BodylessMethod} */
get<T_3 = any>(url: string, config?: Options | undefined): Promise<Response<T_3>>;
/** @public @type {BodylessMethod} */
delete<T_3 = any>(url: string, config?: Options | undefined): Promise<Response<T_3>>;
/** @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>>;
/** @public @type {BodyMethod} */
post<T_4 = any>(url: string, body?: any, config?: Options | undefined): Promise<Response<T_4>>;
/** @public @type {BodyMethod} */
put<T_4 = any>(url: string, body?: any, config?: Options | undefined): Promise<Response<T_4>>;
/** @public @type {BodyMethod} */
patch<T_4 = any>(url: string, body?: any, config?: Options | undefined): Promise<Response<T_4>>;
/** @public */
all: {
<T_5>(values: Iterable<T_5 | PromiseLike<T_5>>): Promise<T_5[]>;
<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
<T1_1, T2_1, T3_1, T4_1, T5_1, T6_1, T7_1, T8_1, T9_1>(values: readonly [T1_1 | PromiseLike<T1_1>, T2_1 | PromiseLike<T2_1>, T3_1 | PromiseLike<T3_1>, T4_1 | PromiseLike<T4_1>, T5_1 | PromiseLike<T5_1>, T6_1 | PromiseLike<T6_1>, T7_1 | PromiseLike<T7_1>, T8_1 | PromiseLike<T8_1>, T9_1 | PromiseLike<T9_1>]): Promise<[T1_1, T2_1, T3_1, T4_1, T5_1, T6_1, T7_1, T8_1, T9_1]>;
<T1_2, T2_2, T3_2, T4_2, T5_2, T6_2, T7_2, T8_2>(values: readonly [T1_2 | PromiseLike<T1_2>, T2_2 | PromiseLike<T2_2>, T3_2 | PromiseLike<T3_2>, T4_2 | PromiseLike<T4_2>, T5_2 | PromiseLike<T5_2>, T6_2 | PromiseLike<T6_2>, T7_2 | PromiseLike<T7_2>, T8_2 | PromiseLike<T8_2>]): Promise<[T1_2, T2_2, T3_2, T4_2, T5_2, T6_2, T7_2, T8_2]>;
<T1_3, T2_3, T3_3, T4_3, T5_3, T6_3, T7_3>(values: readonly [T1_3 | PromiseLike<T1_3>, T2_3 | PromiseLike<T2_3>, T3_3 | PromiseLike<T3_3>, T4_3 | PromiseLike<T4_3>, T5_3 | PromiseLike<T5_3>, T6_3 | PromiseLike<T6_3>, T7_3 | PromiseLike<T7_3>]): Promise<[T1_3, T2_3, T3_3, T4_3, T5_3, T6_3, T7_3]>;
<T1_4, T2_4, T3_4, T4_4, T5_4, T6_4>(values: readonly [T1_4 | PromiseLike<T1_4>, T2_4 | PromiseLike<T2_4>, T3_4 | PromiseLike<T3_4>, T4_4 | PromiseLike<T4_4>, T5_4 | PromiseLike<T5_4>, T6_4 | PromiseLike<T6_4>]): Promise<[T1_4, T2_4, T3_4, T4_4, T5_4, T6_4]>;
<T1_5, T2_5, T3_5, T4_5, T5_5>(values: readonly [T1_5 | PromiseLike<T1_5>, T2_5 | PromiseLike<T2_5>, T3_5 | PromiseLike<T3_5>, T4_5 | PromiseLike<T4_5>, T5_5 | PromiseLike<T5_5>]): Promise<[T1_5, T2_5, T3_5, T4_5, T5_5]>;
<T1_6, T2_6, T3_6, T4_6>(values: readonly [T1_6 | PromiseLike<T1_6>, T2_6 | PromiseLike<T2_6>, T3_6 | PromiseLike<T3_6>, T4_6 | PromiseLike<T4_6>]): Promise<[T1_6, T2_6, T3_6, T4_6]>;
<T1_7, T2_7, T3_7>(values: readonly [T1_7 | PromiseLike<T1_7>, T2_7 | PromiseLike<T2_7>, T3_7 | PromiseLike<T3_7>]): Promise<[T1_7, T2_7, T3_7]>;
<T1_8, T2_8>(values: readonly [T1_8 | PromiseLike<T1_8>, T2_8 | PromiseLike<T2_8>]): Promise<[T1_8, T2_8]>;
<T_6>(values: readonly (T_6 | PromiseLike<T_6>)[]): Promise<T_6[]>;
};
/**
* @public
* @template Args, R
* @param {(...args: Args[]) => R} fn
* @returns {(array: Args[]) => R}
*/
spread<Args, R>(fn: (...args: Args[]) => R): (array: Args[]) => R;
/**
* @public
* @type {AbortController}
*/
CancelToken: AbortController;
/**
* @public
* @type {Options}
*/
defaults: Options;
/**
* @public
*/
create: typeof create;
};
//# sourceMappingURL=index.d.ts.map

2

dist/redaxios.js

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

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;
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,i){var u="string"!=typeof e?(n=e).url:e,c={config:n},s=r(t,n),p={};o=o||s.data,(s.transformRequest||[]).map(function(e){o=e(o,s.headers)||o}),s.auth&&(p.authorization=s.auth),o&&"object"==typeof o&&"function"!=typeof o.append&&"function"!=typeof o.text&&(o=JSON.stringify(o),p["content-type"]="application/json");try{p[s.xsrfHeaderName]=decodeURIComponent(document.cookie.match(RegExp("(^|; )"+s.xsrfCookieName+"=([^;]*)"))[2])}catch(e){}return s.baseURL&&(u=u.replace(/^(?!.*\/\/)\/?/,s.baseURL+"/")),s.params&&(u+=(~u.indexOf("?")?"&":"?")+(s.paramsSerializer?s.paramsSerializer(s.params):new URLSearchParams(s.params))),(s.fetch||fetch)(u,{method:(a||s.method||"get").toUpperCase(),body:o,headers:r(s.headers,p,!0),credentials:s.withCredentials?"include":i}).then(function(e){for(var t in e)"function"!=typeof e[t]&&(c[t]=e[t]);return"stream"==s.responseType?(c.data=e.body,c):e[s.responseType||"text"]().then(function(e){c.data=e,c.data=JSON.parse(e)}).catch(Object).then(function(){return(s.validateStatus?s.validateStatus(e.status):e.ok)?c:Promise.reject(c)})})}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 e.apply.bind(e,e)},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 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}());
export default(function e(t){function n(e,t,r){var a,o={};if(Array.isArray(e))return e.concat(t);for(a in e)o[r?a.toLowerCase():a]=e[a];for(a in t){var i=r?a.toLowerCase():a,u=t[a];o[i]=i in o&&"object"==typeof u?n(o[i],u,"headers"==i):u}return o}function r(e,r,a,o,i){var u="string"!=typeof e?(r=e).url:e,c={config:r},s=n(t,r),f={};o=o||s.data,(s.transformRequest||[]).map(function(e){o=e(o,s.headers)||o}),s.auth&&(f.authorization=s.auth),o&&"object"==typeof o&&"function"!=typeof o.append&&"function"!=typeof o.text&&(o=JSON.stringify(o),f["content-type"]="application/json");try{f[s.xsrfHeaderName]=decodeURIComponent(document.cookie.match(RegExp("(^|; )"+s.xsrfCookieName+"=([^;]*)"))[2])}catch(e){}return s.baseURL&&(u=u.replace(/^(?!.*\/\/)\/?/,s.baseURL+"/")),s.params&&(u+=(~u.indexOf("?")?"&":"?")+(s.paramsSerializer?s.paramsSerializer(s.params):new URLSearchParams(s.params))),(s.fetch||fetch)(u,{method:(a||s.method||"get").toUpperCase(),body:o,headers:n(s.headers,f,!0),credentials:s.withCredentials?"include":i}).then(function(e){for(var t in e)"function"!=typeof e[t]&&(c[t]=e[t]);return"stream"==s.responseType?(c.data=e.body,c):e[s.responseType||"text"]().then(function(e){c.data=e,c.data=JSON.parse(e)}).catch(Object).then(function(){return(s.validateStatus?s.validateStatus(e.status):e.ok)?c:Promise.reject(c)})})}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 e.apply.bind(e,e)},r.CancelToken="function"==typeof AbortController?AbortController:Object,r.defaults=t,r.create=e,r}());
//# 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="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}()});
!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,i){var u="string"!=typeof e?(r=e).url:e,c={config:r},f=n(t,r),s={};a=a||f.data,(f.transformRequest||[]).map(function(e){a=e(a,f.headers)||a}),f.auth&&(s.authorization=f.auth),a&&"object"==typeof a&&"function"!=typeof a.append&&"function"!=typeof a.text&&(a=JSON.stringify(a),s["content-type"]="application/json");try{s[f.xsrfHeaderName]=decodeURIComponent(document.cookie.match(RegExp("(^|; )"+f.xsrfCookieName+"=([^;]*)"))[2])}catch(e){}return f.baseURL&&(u=u.replace(/^(?!.*\/\/)\/?/,f.baseURL+"/")),f.params&&(u+=(~u.indexOf("?")?"&":"?")+(f.paramsSerializer?f.paramsSerializer(f.params):new URLSearchParams(f.params))),(f.fetch||fetch)(u,{method:(o||f.method||"get").toUpperCase(),body:a,headers:n(f.headers,s,!0),credentials:f.withCredentials?"include":i}).then(function(e){for(var t in e)"function"!=typeof e[t]&&(c[t]=e[t]);return"stream"==f.responseType?(c.data=e.body,c):e[f.responseType||"text"]().then(function(e){c.data=e,c.data=JSON.parse(e)}).catch(Object).then(function(){return(f.validateStatus?f.validateStatus(e.status):e.ok)?c:Promise.reject(c)})})}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 e.apply.bind(e,e)},r.CancelToken="function"==typeof AbortController?AbortController:Object,r.defaults=t,r.create=e,r}()});
//# sourceMappingURL=redaxios.umd.js.map
{
"name": "redaxios",
"version": "0.4.1",
"version": "0.5.0",
"description": "The API from Axios, as a tiny abstraction over Fetch.",

@@ -5,0 +5,0 @@ "source": "src/index.js",

@@ -19,3 +19,3 @@ /**

* @property {'get'|'post'|'put'|'patch'|'delete'|'options'|'head'|'GET'|'POST'|'PUT'|'PATCH'|'DELETE'|'OPTIONS'|'HEAD'} [method="get"] HTTP method, case-insensitive
* @property {Headers} [headers] Request headers
* @property {RequestHeaders} [headers] Request headers
* @property {FormData|string|object} [body] a body, optionally encoded, to send

@@ -30,3 +30,3 @@ * @property {'text'|'json'|'stream'|'blob'|'arrayBuffer'|'formData'|'stream'} [responseType="json"] An encoding to use for the response

* @property {(status: number) => boolean} [validateStatus] Override status code handling (default: 200-399 is a success)
* @property {Array<(body: any, headers: Headers) => any?>} [transformRequest] An array of transformations to apply to the outgoing request
* @property {Array<(body: any, headers?: RequestHeaders) => any?>} [transformRequest] An array of transformations to apply to the outgoing request
* @property {string} [baseURL] a base URL from which to resolve all URLs

@@ -39,4 +39,4 @@ * @property {typeof window.fetch} [fetch] Custom window.fetch implementation

* @public
* @typedef Headers
* @type {{[name: string]: string}}
* @typedef RequestHeaders
* @type {{[name: string]: string} | Headers}
*/

@@ -70,4 +70,8 @@

/** */
export default (function create(/** @type {Options} */ defaults) {
/**
* @public
* @param {Options} [defaults = {}]
* @returns {redaxios}
*/
function create(defaults) {
defaults = defaults || {};

@@ -112,21 +116,17 @@

*/
redaxios.spread = function (fn) {
return function (results) {
return fn.apply(this, results);
};
};
// 3b smaller:
// redaxios.spread = (fn) => /** @type {any} */ (fn.apply.bind(fn, fn));
redaxios.spread = (fn) => /** @type {any} */ (fn.apply.bind(fn, fn));
/**
* @private
* @param {Record<string,any>} opts
* @param {Record<string,any>} [overrides]
* @template T, U
* @param {T} opts
* @param {U} [overrides]
* @param {boolean} [lowerCase]
* @returns {Partial<opts>}
* @returns {{} & (T | U)}
*/
function deepMerge(opts, overrides, lowerCase) {
let out = {},
let out = /** @type {any} */ ({}),
i;
if (Array.isArray(opts)) {
// @ts-ignore
return opts.concat(overrides);

@@ -141,3 +141,3 @@ }

const value = /** @type {any} */ (overrides)[i];
out[key] = key in out && typeof value == 'object' ? deepMerge(out[key], value, key === 'headers') : value;
out[key] = key in out && typeof value == 'object' ? deepMerge(out[key], value, key == 'headers') : value;
}

@@ -151,13 +151,11 @@ return out;

* @template T
* @param {string | Options} url
* @param {Options} [config]
* @param {any} [_method]
* @param {any} [_data]
* @param {string | Options} urlOrConfig
* @param {Options} [config = {}]
* @param {any} [_method] (internal)
* @param {any} [data] (internal)
* @param {never} [_undefined] (internal)
* @returns {Promise<Response<T>>}
*/
function redaxios(url, config, _method, _data) {
if (typeof url !== 'string') {
config = url;
url = config.url;
}
function redaxios(urlOrConfig, config, _method, data, _undefined) {
let url = /** @type {string} */ (typeof urlOrConfig != 'string' ? (config = urlOrConfig).url : urlOrConfig);

@@ -169,6 +167,6 @@ const response = /** @type {Response<any>} */ ({ config });

/** @type {Headers} */
/** @type {RequestHeaders} */
const customHeaders = {};
let data = _data || options.data;
data = data || options.data;

@@ -179,3 +177,7 @@ (options.transformRequest || []).map((f) => {

if (data && typeof data === 'object' && typeof data.append !== 'function') {
if (options.auth) {
customHeaders.authorization = options.auth;
}
if (data && typeof data === 'object' && typeof data.append !== 'function' && typeof data.text !== 'function') {
data = JSON.stringify(data);

@@ -185,20 +187,18 @@ customHeaders['content-type'] = 'application/json';

const m =
typeof document !== 'undefined' && document.cookie.match(RegExp('(^|; )' + options.xsrfCookieName + '=([^;]*)'));
if (m) customHeaders[options.xsrfHeaderName] = m[2];
try {
// @ts-ignore providing the cookie name without header name is nonsensical anyway
customHeaders[options.xsrfHeaderName] = decodeURIComponent(
// @ts-ignore accessing match()[2] throws for no match, which is intentional
document.cookie.match(RegExp('(^|; )' + options.xsrfCookieName + '=([^;]*)'))[2]
);
} catch (e) {}
if (options.auth) {
customHeaders.authorization = options.auth;
}
if (options.baseURL) {
url = url.replace(/^(?!.*\/\/)\/?(.*)$/, options.baseURL + '/$1');
url = url.replace(/^(?!.*\/\/)\/?/, options.baseURL + '/');
}
if (options.params) {
const divider = ~url.indexOf('?') ? '&' : '?';
const query = options.paramsSerializer
? options.paramsSerializer(options.params)
: new URLSearchParams(options.params);
url += divider + query;
url +=
(~url.indexOf('?') ? '&' : '?') +
(options.paramsSerializer ? options.paramsSerializer(options.params) : new URLSearchParams(options.params));
}

@@ -209,6 +209,6 @@

return fetchFunc(url, {
method: _method || options.method,
method: (_method || options.method || 'get').toUpperCase(),
body: data,
headers: deepMerge(options.headers, customHeaders, true),
credentials: options.withCredentials ? 'include' : 'same-origin'
credentials: options.withCredentials ? 'include' : _undefined
}).then((res) => {

@@ -219,4 +219,2 @@ for (const i in res) {

const ok = options.validateStatus ? options.validateStatus(res.status) : res.ok;
if (options.responseType == 'stream') {

@@ -234,3 +232,6 @@ response.data = res.body;

.catch(Object)
.then(() => (ok ? response : Promise.reject(response)));
.then(() => {
const ok = options.validateStatus ? options.validateStatus(res.status) : res.ok;
return ok ? response : Promise.reject(response);
});
});

@@ -257,2 +258,4 @@ }

return redaxios;
})();
}
export default create();

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