Comparing version 1.3.5 to 2.0.0-beta1
@@ -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); |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
6
0
6973
3
8
133
2
+ Addednode-fetch@^1.6.3
+ Addedobject-inspect@1.13.2(transitive)
- Removedobject-inspect@1.13.3(transitive)