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

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.5 to 0.1.6

16

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

@@ -10,6 +10,5 @@ const { version } = require('./package');

if (!options.url) throw new Error('The "url" option is required.');
this.url = options.url;
this.url = new URL(options.url);
this.method = options.method ? options.method.toUpperCase() : 'GET';
if (!METHODS.includes(this.method)) throw new Error(`The method "${this.method}" is not supported.`);
this.queryParams = options.query || {};
this.headers = options.headers || {};

@@ -21,4 +20,3 @@ this.body = options.body || null;

async _request() {
const queryParams = querystring.stringify(this.queryParams);
const response = await fetch(`${this.url}${queryParams ? `?${queryParams}` : ''}`, {
const response = await fetch(this.url.toString(), {
method: this.method,

@@ -78,6 +76,6 @@ headers: this.headers,

query(queryOrName, value) {
if (typeof queryOrName === 'object' && !value) {
for (const [param, val] of Object.entries(queryOrName)) this.queryParams[param] = val;
if (typeof queryOrName === 'object') {
for (const [param, val] of Object.entries(queryOrName)) this.url.searchParams.append(param, val);
} else if (typeof queryOrName === 'string' && value) {
this.queryParams[queryOrName] = value;
this.url.searchParams.append(queryOrName, value);
} else {

@@ -90,3 +88,3 @@ throw new TypeError('The "query" parameter must be either an object or a query field.');

set(headersOrName, value) {
if (typeof headersOrName === 'object' && !value) {
if (typeof headersOrName === 'object') {
for (const [header, val] of Object.entries(headersOrName)) this.headers[header] = val;

@@ -93,0 +91,0 @@ } else if (typeof headersOrName === 'string' && value) {

{
"name": "node-superfetch",
"version": "0.1.5",
"version": "0.1.6",
"description": "A wrapper for node-fetch that makes it appear like superagent.",

@@ -5,0 +5,0 @@ "main": "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