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

wonderful-fetch

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wonderful-fetch - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

51

dist/index.js

@@ -23,3 +23,3 @@ (function (root, factory) {

var SOURCE = 'library';
var VERSION = '0.0.6';
var VERSION = '0.0.7';

@@ -35,2 +35,14 @@ function WonderfulFetch(url, options) {

options.cacheBreaker = typeof options.cacheBreaker === 'undefined' ? true : options.cacheBreaker;
options.contentType = typeof options.contentType === 'undefined' ? '' : options.contentType;
options.responseFormat = typeof options.responseFormat === 'undefined' ? 'raw' : options.responseFormat;
// Legacy
if (options.raw) {
options.responseFormat = 'raw'
} else if (options.json) {
options.responseFormat = 'json'
} else if (options.text) {
options.responseFormat = 'text'
}
url = url || options.url;

@@ -42,2 +54,5 @@

var bodyIsFormData = typeof options.body === 'function' && options.body.append;
var bodyIsObject = typeof options.body === 'object';
if (!url) {

@@ -54,8 +69,29 @@ return reject(new Error('No URL provided.'))

if (options.body) {
config.body = typeof options.body !== 'string' ? JSON.stringify(options.body) : options.body;
if (bodyIsFormData) {
config.body = options.body;
} else if (bodyIsObject) {
config.body = JSON.stringify(options.body);
} else {
config.body = options.body;
}
}
if (options.json && options.body && config.method === 'post') {
// if (options.json && options.body && config.method === 'post') {
// config.headers['Content-Type'] = 'application/json';
// }
if (
(bodyIsObject && !bodyIsFormData)
|| (options.contentType === 'json')
) {
config.headers['Content-Type'] = 'application/json';
}
if (config.method === 'get') {
delete config.body;
}
if (options.log) {
console.log('Fetch configuration:', 'bodyIsFormData=' + bodyIsFormData, 'bodyIsObject=' + bodyIsObject, options, config);
}
var timeoutHolder;

@@ -76,3 +112,3 @@

if (options.log) {
console.log('Fetch (' + tries + '/' + options.tries + ', ' + ms + 'ms): ' + url, options);
console.log('Fetch (' + tries + '/' + options.tries + ', ' + ms + 'ms): ', url);
}

@@ -131,3 +167,3 @@

if (res.ok) {
if (options.raw) {
if (options.responseFormat === 'raw') {
return _resolve(res);

@@ -137,3 +173,3 @@ } else {

.then(function (text) {
if (options.json) {
if (options.responseFormat === 'json') {
JSON5 = JSON5 || require('json5');

@@ -149,2 +185,5 @@ try {

})
.catch(e => {
return _reject(e);
})
}

@@ -151,0 +190,0 @@ } else {

2

package.json
{
"name": "wonderful-fetch",
"version": "0.0.6",
"version": "0.0.7",
"description": "A wrapper around fetch.",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

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