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

chainfetch

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chainfetch - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

2

package.json
{
"name": "chainfetch",
"version": "1.0.5",
"version": "1.1.0",
"description": "A simple, chainable wrapper around node-fetch!",

@@ -5,0 +5,0 @@ "main": "src/index",

@@ -41,3 +41,3 @@ <div>

const res = await fetch.get('https://example.com').toBuffer();
const res = await fetch.get('https://example.com').toText();
```

@@ -50,3 +50,15 @@

const res = await fetch.post('https://example.com').query({ isSimple: true }).query('isAmazing', true).send({ string: 'chainfetch is simple and amazing!' }).toJSON();
const res = await fetch.post('https://example.com').query({ isSimple: true }).query('isAmazing', true).send({ string: 'chainfetch is simple and amazing!' });
```
## Meaning of `toJSON`, `toText` and `toBuffer`
In chainfetch, there are 4 functions which can determine how the response should be parsed. You can access the body by using `res.body`.
By default, we try to JSON.parse the body if the response provides the `Content-Type` header, and it includes `application/json`.
| Function | What it Returns |
|:-------------------:|:-------------------------------------------------------------------------------------------------:|
| toBuffer | Does no processing on the body, and returns it as a buffer |
| toJSON | Attempts to parse the response body as a JSON object, otherwise it returns the stringified Buffer |
| toText and toString | Both of these functions take the response body and turn it into a string |

@@ -201,3 +201,3 @@ const { METHODS } = require('http');

const type = returnRes.headers.get('content-type');
if ((/application\/json/.test(type) && typeof finalBody !== 'object') || this.customHandler === 'json') {
if (/application\/json/.test(type) || this.customHandler === 'json') {
try {

@@ -204,0 +204,0 @@ finalBody = JSON.parse(String(finalBody));

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