Comparing version 1.0.10 to 1.0.11
{ | ||
"name": "autofetch", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "fetch for node", | ||
@@ -5,0 +5,0 @@ "main": "src/index.node.js", |
const realFetch = require('isomorphic-fetch/fetch-npm-browserify.js'); | ||
const { responseMiddleware, parseUrl } = require('./utils'); | ||
const { responseMiddleware, parseUrl, toFormData } = require('./utils'); | ||
@@ -10,2 +10,12 @@ let globalCallback = response => response; | ||
if(!options.method || options.method === 'GET'){ | ||
options.body = options.body || options.data; | ||
} | ||
options.headers = options.headers || {}; | ||
if(options.headers['Content-Type'] !== 'application/json' && !(options.body instanceof 'FormData') { | ||
// convert to FormData | ||
options.body = toFormData(body); | ||
} | ||
return realFetch.call(this, parseUrl(url, options, baseHost), options, ...extras).then(responseMiddleware).then(globalCallback); | ||
@@ -12,0 +22,0 @@ }; |
@@ -12,2 +12,12 @@ "use strict"; | ||
if(!options.method || options.method === 'GET'){ | ||
options.body = options.body || options.data; | ||
} | ||
options.headers = options.headers || {}; | ||
if(options.headers['Content-Type'] !== 'application/json' && !(options.body instanceof 'FormData') { | ||
// convert to FormData | ||
options.body = toFormData(body); | ||
} | ||
return realFetch.call(this, parseUrl(url, options,baseHost), options, ...extras).then(responseMiddleware).then(globalCallback); | ||
@@ -14,0 +24,0 @@ }; |
@@ -23,5 +23,15 @@ const responseMiddleware = (response) => { | ||
const toFormData = (obj) => { | ||
const form = new FormData(); | ||
Object.keys(obj).forEach((key)=> { | ||
form.append(key, obj[key]); | ||
}); | ||
return form; | ||
} | ||
module.exports = { | ||
parseUrl, | ||
responseMiddleware | ||
responseMiddleware, | ||
toFormData | ||
}; |
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
87
6012
6