Socket
Socket
Sign inDemoInstall

node-superfetch

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-superfetch - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

35

index.js
const fetch = require('node-fetch');
const FormData = require('form-data');
const querystring = require('querystring');
const { METHODS } = require('http');
const { version } = require('./package');

@@ -73,5 +75,9 @@ class Request {

query(queryOrName, value) {
if (typeof queryOrName === 'object' && !value) this.queryParams = { ...this.queryParams, ...queryOrName };
else if (typeof queryOrName === 'string' && value) this.queryParams[queryOrName] = value;
else throw new TypeError('The "query" parameter must be either an object or a query field.');
if (typeof queryOrName === 'object' && !value) {
for (const [param, val] of Object.entries(queryOrName)) this.queryParams[param] = val;
} else if (typeof queryOrName === 'string' && value) {
this.queryParams[queryOrName] = value;
} else {
throw new TypeError('The "query" parameter must be either an object or a query field.');
}
return this;

@@ -81,9 +87,24 @@ }

set(headersOrName, value) {
if (typeof headersOrName === 'object' && !value) this.headers = { ...this.headers, ...headersOrName };
else if (typeof headersOrName === 'string' && value) this.headers[headersOrName] = value;
else throw new TypeError('The "headers" parameter must be either an object or a header field.');
if (typeof headersOrName === 'object' && !value) {
for (const [header, val] of Object.entries(headersOrName)) this.headers[header] = val;
} else if (typeof headersOrName === 'string' && value) {
this.headers[headersOrName] = value;
} else {
throw new TypeError('The "headers" parameter must be either an object or a header field.');
}
return this;
}
attach(...args) {
if (!this.body || !(this.body instanceof FormData)) this.body = new FormData();
if (typeof args[0] === 'object') {
for (const [key, val] of Object.entries(args[0])) this.attach(key, val);
} else {
this.body.append(...args);
}
return this;
}
send(body, raw = false) {
if (body instanceof FormData) raw = true;
if (!raw && body !== null && typeof body === 'object') {

@@ -114,2 +135,4 @@ const header = this.headers['content-type'];

Request.version = version;
module.exports = Request;

3

package.json
{
"name": "node-superfetch",
"version": "0.1.1",
"version": "0.1.2",
"description": "A wrapper for node-fetch that makes it appear like superagent.",

@@ -33,2 +33,3 @@ "main": "index.js",

"dependencies": {
"form-data": "^2.3.2",
"node-fetch": "^2.1.2"

@@ -35,0 +36,0 @@ },

@@ -26,6 +26,5 @@ # node-superfetch

methods, as well as functions like `query` (sets query parameters), `set` (sets
headers), `send` (for adding POST data and such), and `redirects` (for setting
the allowed number of redirects). `end` is also supported for callbacks. It
_does not_ implement anything related to formdata (but you can probably attach
it like you would with node-fetch).
headers), `send` (for adding POST data and such), `attach` (for sending
FormData), and `redirects` (for setting the allowed number of redirects). `end`
is also supported for callbacks.

@@ -32,0 +31,0 @@ ## Disclaimer for Contributors

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