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

autofetch

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autofetch - npm Package Compare versions

Comparing version 1.3.5 to 2.0.0-beta1

58

libs/utils.js

@@ -15,7 +15,7 @@ const qs = require('qs');

return headers instanceof Headers ? (() => {
return Array.from(headers.keys()).reduce((previous, currentKey) => {
previous[currentKey] = headers.get(currentKey);
return previous;
}, {})
})() : headers;
return Array.from(headers.keys()).reduce((previous, currentKey) => {
previous[currentKey] = headers.get(currentKey);
return previous;
}, {})
})() : headers;
};

@@ -42,26 +42,21 @@

const parseRequest = (url, { method = 'GET', query = {}, data = {}, body = {}, headers = {}, json = false, ...extras } = {}) => {
const isGet = method === 'GET' || method === 'HEAD';
const parseRequest = (url, options = { method: 'GET' }) => {
const isGet = options.method === 'GET' || options.method === 'HEAD';
const bodyIsFormData = typeof window !== 'undefined' && typeof FormData !== 'undefined' ? body instanceof FormData : false;
if (isGet && !options.query && options.data) {
options.query = options.data;
}
if (!isGet && !options.body && options.data) {
options.body = options.data;
}
isGet ? (query = typeof query === 'object' ?
{ ...query, ...data, ...body } :
(Object.keys(query).length === 0 ? data : query)) :
(body = typeof body === 'object' && !bodyIsFormData ?
{ ...data, ...body } :
(Object.keys(body).length === 0 && !bodyIsFormData ? data : body));
const headers = new Headers(Object.assign({}, headersToObject(options.headers), headersToObject(globalHeader)));
headers = new Headers({
...headersToObject(headers),
...headersToObject(globalHeader)
});
// handle Content-Type when not GET
!isGet ? headers.set('Content-Type', headers.get('Content-Type') || mime(body)) : '';
!isGet ? headers.set('Content-Type', headers.get('Content-Type') || mime(options.body)) : '';
if (typeof body === 'object') {
if (typeof options.body === 'object') {
switch (headers.get('Content-Type')) {
case mimetypes.form: {
body = qs.stringify(body);
options.body = qs.stringify(options.body);
break;

@@ -71,6 +66,6 @@ }

const form = new FormData();
Object.keys(body).forEach((key) => {
form.set(key, body[key]);
Object.keys(options.body).forEach((key) => {
form.set(key, options.body[key]);
});
body = form;
options.body = form;
break;

@@ -84,13 +79,4 @@ }

const options = {
method,
query,
headers,
...extras
};
options.headers = headers;
if (!isGet) {
options.body = body;
}
return [

@@ -116,2 +102,4 @@ parseUrl(url, options, baseHost),

baseHost = host;
delete fetchRequest.baseHost;
};

@@ -118,0 +106,0 @@

{
"name": "autofetch",
"version": "1.3.5",
"version": "2.0.0-beta1",
"description": "fetch for node",

@@ -8,3 +8,3 @@ "main": "src/index.node.js",

"scripts": {
"build": "webpack --config=webpack.config.js",
"build": "webpack --config=scripts/webpack.config.js",
"prepublish": "npm run build",

@@ -51,4 +51,5 @@ "publish": "rm -rf dist/",

"isomorphic-fetch": "^2.2.1",
"node-fetch": "^1.6.3",
"qs": "^6.3.0"
}
}
const realFetch = require('isomorphic-fetch/fetch-npm-browserify.js');
require('../libs/polyfill')(window);
const { fetchDecorator } = require('./../libs/utils');

@@ -4,0 +4,0 @@

"use strict";
const realFetch = require('isomorphic-fetch/fetch-npm-node.js');
require('../libs/polyfill')(global);
const { fetchDecorator } = require('./../dist/utils');
const { fetchDecorator } = require('./../libs/utils');

@@ -8,0 +7,0 @@ const fetch = fetchDecorator(realFetch);

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