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.1.0 to 0.2.0

2

dist/redaxios.js

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

var e=function(e){function t(e,t){return function(r,n,a){var i;return t&&(i=n,n=a),o(r,i,n=Object.assign({method:e},n))}}function r(e,t,o){if(Array.isArray(e))return e.concat(t);if(t&&"object"==typeof t){var n,a={};if(e)for(n in e)a[o?n.toLowerCase():n]=e[n];for(n in t){var i=o?n.toLowerCase():n;"headers"===i&&(o=!0),a[i]=n in a?r(a[i],t[n],o):t[n]}return a}return t}function o(t,o,n){var a=n;if("string"!=typeof t?t=(a=t).url:void 0===n&&(a=o,o=void 0),(a=r(e,a)||{}).transformRequest)for(var i=0;i<a.transformRequest.length;i++){var s=a.transformRequest[i](o,a.headers);void 0!==s&&(o=s)}var u={};if(o&&"object"==typeof o&&(o=JSON.stringify(o),u["Content-Type"]="application/json"),a.xsrfCookieName)for(var f=document.cookie.split(/ *[;=] */),c=0;c<f.length;c+=2)if(f[c]==a.xsrfCookieName){u[a.xsrfHeaderName]=decodeURIComponent(f[c+1]);break}a.auth&&(u.Authorization=a.auth);var p={config:n};return fetch(t,{method:a.method,body:o,headers:r(a.headers,u,!0)}).then(function(e){var t;for(t in e)"function"!=typeof e[t]&&(p[t]=e[t]);return(a.validateStatus||function(e){return 2==(e/100|0)})(e.status)?("stream"===a.responseType?Promise.resolve(e.body):e[a.responseType||"text"]()).then(function(e){return p.data=e,p}):Promise.reject(e)})}return e=e||{},o.request=o,o.get=t("get",!1),o.delete=t("delete",!1),o.options=t("options",!1),o.post=t("post",!0),o.put=t("put",!0),o.patch=t("patch",!0),o.all=Promise.all,o.spread=function(e){return function(t){return e.apply(this,t)}},o.CancelToken=self.AbortController||Object,o}();module.exports=e;
var e=function e(t){function r(e){return function(t,r){return a(t,Object.assign({method:e},r))}}function o(e){return function(t,r,o){return a(t,Object.assign({method:e,data:r},o))}}function n(e,t,r){if(Array.isArray(e))return e.concat(t);if(t&&"object"==typeof t){var o,a={};if(e)for(o in e)a[r?o.toLowerCase():o]=e[o];for(o in t){var i=r?o.toLowerCase():o;"headers"===i&&(r=!0),a[i]=o in a?n(a[i],t[o],r):t[o]}return a}return t}function a(e,r){"string"!=typeof e&&(e=(r=e).url);var o=n(t,r||{}),a=o.data;if(o.transformRequest)for(var i=0;i<o.transformRequest.length;i++){var s=o.transformRequest[i](a,o.headers);void 0!==s&&(a=s)}var u={};if(a&&"object"==typeof a&&(a=JSON.stringify(a),u["Content-Type"]="application/json"),o.xsrfCookieName)for(var f=document.cookie.split(/ *[;=] */),c=0;c<f.length;c+=2)if(f[c]==o.xsrfCookieName){u[o.xsrfHeaderName]=decodeURIComponent(f[c+1]);break}o.auth&&(u.Authorization=o.auth);var p={};return p.config=r,fetch(e,{method:o.method,body:a,headers:n(o.headers,u,!0)}).then(function(e){var t;for(t in e)"function"!=typeof e[t]&&(p[t]=e[t]);return(o.validateStatus?o.validateStatus(e.status):e.ok)?("stream"===o.responseType?Promise.resolve(e.body):e[o.responseType||"text"]()).then(function(e){return p.data=e,p}):Promise.reject(e)})}return t=t||{},a.request=a,a.get=r("get"),a.delete=r("delete"),a.options=r("options"),a.post=o("post"),a.put=o("put"),a.patch=o("patch"),a.all=Promise.all,a.spread=function(e){return function(t){return e.apply(this,t)}},a.CancelToken=self.AbortController||Object,a.create=e,a}();module.exports=e;
//# sourceMappingURL=redaxios.js.map

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

export default(function(e){function t(e,t){return function(r,n,a){var i;return t&&(i=n,n=a),o(r,i,n=Object.assign({method:e},n))}}function r(e,t,o){if(Array.isArray(e))return e.concat(t);if(t&&"object"==typeof t){var n,a={};if(e)for(n in e)a[o?n.toLowerCase():n]=e[n];for(n in t){var i=o?n.toLowerCase():n;"headers"===i&&(o=!0),a[i]=n in a?r(a[i],t[n],o):t[n]}return a}return t}function o(t,o,n){var a=n;if("string"!=typeof t?t=(a=t).url:void 0===n&&(a=o,o=void 0),(a=r(e,a)||{}).transformRequest)for(var i=0;i<a.transformRequest.length;i++){var s=a.transformRequest[i](o,a.headers);void 0!==s&&(o=s)}var f={};if(o&&"object"==typeof o&&(o=JSON.stringify(o),f["Content-Type"]="application/json"),a.xsrfCookieName)for(var u=document.cookie.split(/ *[;=] */),c=0;c<u.length;c+=2)if(u[c]==a.xsrfCookieName){f[a.xsrfHeaderName]=decodeURIComponent(u[c+1]);break}a.auth&&(f.Authorization=a.auth);var p={config:n};return fetch(t,{method:a.method,body:o,headers:r(a.headers,f,!0)}).then(function(e){var t;for(t in e)"function"!=typeof e[t]&&(p[t]=e[t]);return(a.validateStatus||function(e){return 2==(e/100|0)})(e.status)?("stream"===a.responseType?Promise.resolve(e.body):e[a.responseType||"text"]()).then(function(e){return p.data=e,p}):Promise.reject(e)})}return e=e||{},o.request=o,o.get=t("get",!1),o.delete=t("delete",!1),o.options=t("options",!1),o.post=t("post",!0),o.put=t("put",!0),o.patch=t("patch",!0),o.all=Promise.all,o.spread=function(e){return function(t){return e.apply(this,t)}},o.CancelToken=self.AbortController||Object,o}());
export default(function e(t){function r(e){return function(t,r){return a(t,Object.assign({method:e},r))}}function o(e){return function(t,r,o){return a(t,Object.assign({method:e,data:r},o))}}function n(e,t,r){if(Array.isArray(e))return e.concat(t);if(t&&"object"==typeof t){var o,a={};if(e)for(o in e)a[r?o.toLowerCase():o]=e[o];for(o in t){var i=r?o.toLowerCase():o;"headers"===i&&(r=!0),a[i]=o in a?n(a[i],t[o],r):t[o]}return a}return t}function a(e,r){"string"!=typeof e&&(e=(r=e).url);var o=n(t,r||{}),a=o.data;if(o.transformRequest)for(var i=0;i<o.transformRequest.length;i++){var s=o.transformRequest[i](a,o.headers);void 0!==s&&(a=s)}var u={};if(a&&"object"==typeof a&&(a=JSON.stringify(a),u["Content-Type"]="application/json"),o.xsrfCookieName)for(var f=document.cookie.split(/ *[;=] */),c=0;c<f.length;c+=2)if(f[c]==o.xsrfCookieName){u[o.xsrfHeaderName]=decodeURIComponent(f[c+1]);break}o.auth&&(u.Authorization=o.auth);var p={};return p.config=r,fetch(e,{method:o.method,body:a,headers:n(o.headers,u,!0)}).then(function(e){var t;for(t in e)"function"!=typeof e[t]&&(p[t]=e[t]);return(o.validateStatus?o.validateStatus(e.status):e.ok)?("stream"===o.responseType?Promise.resolve(e.body):e[o.responseType||"text"]()).then(function(e){return p.data=e,p}):Promise.reject(e)})}return t=t||{},a.request=a,a.get=r("get"),a.delete=r("delete"),a.options=r("options"),a.post=o("post"),a.put=o("put"),a.patch=o("patch"),a.all=Promise.all,a.spread=function(e){return function(t){return e.apply(this,t)}},a.CancelToken=self.AbortController||Object,a.create=e,a}());
//# 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){function t(e,t){return function(o,n,i){var a;return t&&(a=n,n=i),r(o,a,n=Object.assign({method:e},n))}}function o(e,t,r){if(Array.isArray(e))return e.concat(t);if(t&&"object"==typeof t){var n,i={};if(e)for(n in e)i[r?n.toLowerCase():n]=e[n];for(n in t){var a=r?n.toLowerCase():n;"headers"===a&&(r=!0),i[a]=n in i?o(i[a],t[n],r):t[n]}return i}return t}function r(t,r,n){var i=n;if("string"!=typeof t?t=(i=t).url:void 0===n&&(i=r,r=void 0),(i=o(e,i)||{}).transformRequest)for(var a=0;a<i.transformRequest.length;a++){var f=i.transformRequest[a](r,i.headers);void 0!==f&&(r=f)}var s={};if(r&&"object"==typeof r&&(r=JSON.stringify(r),s["Content-Type"]="application/json"),i.xsrfCookieName)for(var u=document.cookie.split(/ *[;=] */),c=0;c<u.length;c+=2)if(u[c]==i.xsrfCookieName){s[i.xsrfHeaderName]=decodeURIComponent(u[c+1]);break}i.auth&&(s.Authorization=i.auth);var d={config:n};return fetch(t,{method:i.method,body:r,headers:o(i.headers,s,!0)}).then(function(e){var t;for(t in e)"function"!=typeof e[t]&&(d[t]=e[t]);return(i.validateStatus||function(e){return 2==(e/100|0)})(e.status)?("stream"===i.responseType?Promise.resolve(e.body):e[i.responseType||"text"]()).then(function(e){return d.data=e,d}):Promise.reject(e)})}return e=e||{},r.request=r,r.get=t("get",!1),r.delete=t("delete",!1),r.options=t("options",!1),r.post=t("post",!0),r.put=t("put",!0),r.patch=t("patch",!0),r.all=Promise.all,r.spread=function(e){return function(t){return e.apply(this,t)}},r.CancelToken=self.AbortController||Object,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 r(e){return function(t,r){return a(t,Object.assign({method:e},r))}}function o(e){return function(t,r,o){return a(t,Object.assign({method:e,data:r},o))}}function n(e,t,r){if(Array.isArray(e))return e.concat(t);if(t&&"object"==typeof t){var o,a={};if(e)for(o in e)a[r?o.toLowerCase():o]=e[o];for(o in t){var i=r?o.toLowerCase():o;"headers"===i&&(r=!0),a[i]=o in a?n(a[i],t[o],r):t[o]}return a}return t}function a(e,r){"string"!=typeof e&&(e=(r=e).url);var o=n(t,r||{}),a=o.data;if(o.transformRequest)for(var i=0;i<o.transformRequest.length;i++){var s=o.transformRequest[i](a,o.headers);void 0!==s&&(a=s)}var f={};if(a&&"object"==typeof a&&(a=JSON.stringify(a),f["Content-Type"]="application/json"),o.xsrfCookieName)for(var u=document.cookie.split(/ *[;=] */),c=0;c<u.length;c+=2)if(u[c]==o.xsrfCookieName){f[o.xsrfHeaderName]=decodeURIComponent(u[c+1]);break}o.auth&&(f.Authorization=o.auth);var d={};return d.config=r,fetch(e,{method:o.method,body:a,headers:n(o.headers,f,!0)}).then(function(e){var t;for(t in e)"function"!=typeof e[t]&&(d[t]=e[t]);return(o.validateStatus?o.validateStatus(e.status):e.ok)?("stream"===o.responseType?Promise.resolve(e.body):e[o.responseType||"text"]()).then(function(e){return d.data=e,d}):Promise.reject(e)})}return t=t||{},a.request=a,a.get=r("get"),a.delete=r("delete"),a.options=r("options"),a.post=o("post"),a.put=o("put"),a.patch=o("patch"),a.all=Promise.all,a.spread=function(e){return function(t){return e.apply(this,t)}},a.CancelToken=self.AbortController||Object,a.create=e,a}()});
//# sourceMappingURL=redaxios.umd.js.map
{
"name": "redaxios",
"version": "0.1.0",
"version": "0.2.0",
"description": "The API from Axios, as a tiny abstraction over Fetch.",

@@ -11,3 +11,4 @@ "source": "src/index.js",

"build": "microbundle",
"test": "eslint \"{src,test}/**/*.{mjs,js}\" && karmatic"
"test": "eslint src test && karmatic",
"release": "npm t && git commit -am \"$npm_package_version\" && git tag $npm_package_version && git push && git push --tags && npm publish"
},

@@ -26,3 +27,3 @@ "files": [

],
"author": "Jason Miller <developit@google.com>",
"author": "Jason Miller <jason@developit.ca>",
"license": "Apache-2.0",

@@ -40,2 +41,2 @@ "homepage": "https://github.com/developit/redaxios",

}
}
}
# redaxios
The [axios API](https://github.com/axios/axios) implemented as a thin **800 byte** wrapper around `fetch()`.
[Axios] has a great API that developers love. Redaxios provides that API in **800 bytes**, using native `fetch()`.
For those searching for ways to shave a few kilobytes off of their bundles, that's less than 1/5th of the size. This is made possible by using the browser's native [Fetch API][fetch], which is [supported in all modern browsers](https://caniuse.com/#feat=fetch) and polyfilled by most tools including Next.js, Create React App and Preact CLI.
### Can I just use Axios?
Yes! Axios is an excellent module and you should use it! Redaxios exists so that you can use that same API in cases where it's difficult to justify the dependency. Instead of having to choose between Axios and Fetch, Redaxios provides a middle-ground between the two.
[axios]: https://github.com/axios/axios
[fetch]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
### Usage
```js
import axios from 'redaxios';
// use as you would normally
```
Refer to the [Axios Documentation](https://github.com/axios/axios#axios-api).

@@ -15,2 +15,3 @@ /**

/**
* @public
* @typedef Options

@@ -20,2 +21,3 @@ * @property {string} [url] the URL to request

* @property {Headers} [headers] Request headers
* @property {FormData|string|object} [body] a body, optionally encoded, to send
* @property {'text'|'json'|'stream'|'blob'|'arrayBuffer'|'formData'|'stream'} [responseType="text"] An encoding to use for the response

@@ -30,2 +32,3 @@ * @property {string} [auth] Authorization header value to send with the request

/**
* @public
* @typedef Headers

@@ -36,7 +39,9 @@ * @type {{[name: string]: string}}

/**
* @public
* @typedef Response
* @property {Options} config the resolved request configuration
* @property {FormData|string|object} [body] a body, optionally encoded, to send
* @property {Options} config the request configuration
* @property {any} data the decoded response body
*/
/** */
export default (function create(defaults) {

@@ -47,29 +52,49 @@ defaults = defaults || {};

* Creates a request factory bound to the given HTTP method.
* @private
* @param {string} method
* @param {boolean} allowBody
* @returns {(url: string, config?: Options, body?) => Promise<Response>}
* @returns {(url: string, config?: Options) => Promise<Response>}
*/
function createMethod(method, allowBody) {
return (url, config, alt) => {
let data;
if (allowBody) {
data = config;
config = alt;
}
config = Object.assign({ method }, config);
return axios(url, data, config);
};
function createBodylessMethod(method) {
return (url, config) => redaxios(url, Object.assign({ method }, config));
}
axios.request = axios;
axios.get = createMethod('get', false);
axios.delete = createMethod('delete', false);
axios.options = createMethod('options', false);
axios.post = createMethod('post', true);
axios.put = createMethod('put', true);
axios.patch = createMethod('patch', true);
/**
* Creates a request factory bound to the given HTTP method.
* @private
* @param {string} method
* @returns {(url: string, body?: any, config?: Options) => Promise<Response>}
*/
function createBodyMethod(method) {
return (url, data, config) => redaxios(url, Object.assign({ method, data }, config));
}
// hmmm.
axios.all = Promise.all;
axios.spread = function(fn) {
/**
* @public
* @type {((config?: Options) => Promise<Response>) | ((url: string, config?: Options) => Promise<Response>)}
*/
redaxios.request = redaxios;
/** @public */
redaxios.get = createBodylessMethod('get');
/** @public */
redaxios.delete = createBodylessMethod('delete');
/** @public */
redaxios.options = createBodylessMethod('options');
/** @public */
redaxios.post = createBodyMethod('post');
/** @public */
redaxios.put = createBodyMethod('put');
/** @public */
redaxios.patch = createBodyMethod('patch');
/** @public */
redaxios.all = Promise.all;
/** @public */
redaxios.spread = function(fn) {
return function (results) {

@@ -95,8 +120,3 @@ return fn.apply(this, results);

if (key === 'headers') lowerCase = true;
if (i in out) {
out[key] = deepMerge(out[key], overrides[i], lowerCase);
}
else {
out[key] = overrides[i];
}
out[key] = i in out ? deepMerge(out[key], overrides[i], lowerCase) : overrides[i];
}

@@ -108,24 +128,16 @@ return out;

function isOk(status) {
return (status/100|0) === 2;
}
/**
* Issues a request.
* @param {string} url the URL to fetch
* @param {any} [data] request body to send
* @param {Options} [config] configuration for the request
* @public
* @param {string} [url]
* @param {Options} [config]
* @returns {Promise<Response>}
*/
function axios(url, data, config) {
let options = config;
function redaxios(url, config) {
if (typeof url !== 'string') {
options = url;
url = options.url;
config = url;
url = config.url;
}
else if (config === undefined) {
options = data;
data = undefined;
}
options = deepMerge(defaults, options) || {};
const options = deepMerge(defaults, config || {});
let data = options.data;

@@ -162,5 +174,6 @@ if (options.transformRequest) {

const response = {
config
};
/** @type {Response} */
const response = {};
response.config = config;
return fetch(url, {

@@ -175,3 +188,3 @@ method: options.method,

}
if (!(options.validateStatus || isOk)(res.status)) {
if (!(options.validateStatus ? options.validateStatus(res.status) : res.ok)) {
return Promise.reject(res);

@@ -189,5 +202,7 @@ }

axios.CancelToken = self.AbortController || Object;
redaxios.CancelToken = self.AbortController || Object;
return axios;
redaxios.create = create;
return redaxios;
})();

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