chainfetch
Advanced tools
Comparing version 1.0.5 to 1.1.0
{ | ||
"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)); |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
76604
63
4