New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@idearium/fetch

Package Overview
Dependencies
Maintainers
4
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@idearium/fetch - npm Package Compare versions

Comparing version 2.0.3 to 2.0.4-beta.3

16

index.js

@@ -23,7 +23,17 @@ 'use strict';

const fetchApi = async (url, { headers, ...options } = {}) => {
const opts = { ...options };
const fetchApi = async (url, opts = {}) => {
const headers = {};
opts.headers = { 'content-type': 'application/json', ...headers };
if (opts?.headers) {
Object.keys(opts.headers)
.map((key) => key.toLowerCase())
.forEach((key) => (headers[key] = opts.headers[key]));
}
if (!headers['content-type']) {
headers['content-type'] = 'application/json';
}
opts.headers = headers;
return parseResponse(await fetch(url, opts));

@@ -30,0 +40,0 @@ };

2

package.json
{
"name": "@idearium/fetch",
"version": "2.0.3",
"version": "2.0.4-beta.3",
"description": "A package to make fetching trivial.",

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

@@ -8,3 +8,3 @@ 'use strict';

const testUrl = 'http://www.idearium.io/';
const testUrl = 'https://www.idearium.io/';
const headers = { 'content-type': 'application/json' };

@@ -29,3 +29,3 @@

result: { pass: true },
status: 200
status: 200,
});

@@ -40,3 +40,3 @@ });

headers,
status: 400
status: 400,
});

@@ -47,3 +47,3 @@

result: { pass: false },
status: 400
status: 400,
});

@@ -71,6 +71,4 @@ });

const headers = { 'content-type': 'application/json' };
fetchMock.mock(testUrl, [], {
headers
headers,
});

@@ -81,3 +79,3 @@

await expect(fetchMock).toHaveBeenCalledWith(testUrl, {
headers
headers,
});

@@ -91,3 +89,3 @@ });

headers,
method: 'POST'
method: 'POST',
});

@@ -99,3 +97,3 @@

headers,
method: 'POST'
method: 'POST',
});

@@ -111,3 +109,3 @@ });

credentials,
headers
headers,
});

@@ -119,3 +117,3 @@

credentials,
headers
headers,
});

@@ -132,3 +130,3 @@ });

credentials,
headers
headers,
};

@@ -151,4 +149,24 @@

result: {},
status: 400
status: 400,
});
});
it('does not duplicate the content type header', async () => {
expect.assertions(2);
fetchMock.mock(testUrl, [], {
headers,
});
await fetchApi(testUrl, {
headers: { 'Content-Type': 'application/json' },
});
await expect(fetchMock).toHaveBeenCalledWith(testUrl, {
headers: { 'content-type': 'application/json' },
});
await expect(fetchMock).not.toHaveBeenCalledWith(testUrl, {
headers: { 'Content-Type': 'application/json' },
});
});
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