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
35
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.2 to 0.0.3

84

dist/index.js

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

var SOURCE = 'library';
var VERSION = '0.0.2';
var VERSION = '0.0.3';

@@ -106,45 +106,47 @@ function WonderfulFetch(url, options) {

res.text()
.then(function (text) {
if (res.ok) {
if (options.raw) {
return _resolve(res);
} else if (options.json) {
JSON5 = JSON5 || require('json5');
try {
return _resolve(JSON5.parse(text));
} catch (e) {
throw new Error(new Error('Response is not JSON: ' + e))
if (options.ok && options.download) {
jetpack = jetpack || require('fs-jetpack');
if (!jetpack.exists(options.download)) {
path = path || require('path');
var name = path.parse(options.download).name;
var ext = path.parse(options.download).ext;
var dir = options.download.replace(name + ext, '');
jetpack.dir(dir)
}
fileStream = jetpack.createWriteStream(options.download);
res.body.pipe(fileStream);
res.body.on('error', function (e) {
throw new Error(new Error('Failed to download: ' + e))
});
fileStream.on('finish', function() {
return _resolve({
path: options.download
});
});
} else {
res.text()
.then(function (text) {
if (res.ok) {
if (options.raw) {
return _resolve(res);
} else if (options.json) {
JSON5 = JSON5 || require('json5');
try {
return _resolve(JSON5.parse(text));
} catch (e) {
throw new Error(new Error('Response is not JSON: ' + e))
}
} else {
return _resolve(text);
}
} else if (options.download) {
jetpack = jetpack || require('fs-jetpack');
if (!jetpack.exists(options.download)) {
path = path || require('path');
var name = path.parse(options.download).name;
var ext = path.parse(options.download).ext;
var dir = options.download.replace(name + ext, '');
jetpack.dir(dir)
}
fileStream = jetpack.createWriteStream(options.download);
res.body.pipe(fileStream);
res.body.on('error', function (e) {
throw new Error(new Error('Failed to download: ' + e))
});
fileStream.on('finish', function() {
return _resolve({
path: options.download
});
});
} else {
return _resolve(text);
var error = new Error(text || res.statusText || 'Unknown error');
Object.assign(error, { status: res.status })
throw error;
}
} else {
var error = new Error(text || res.statusText || 'Unknown error');
Object.assign(error, { status: res.status })
throw error;
}
})
.catch(e => {
return _reject(e);
})
})
.catch(e => {
return _reject(e);
})
}
})

@@ -151,0 +153,0 @@ .catch(function (e) {

{
"name": "wonderful-fetch",
"version": "0.0.2",
"version": "0.0.3",
"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