tangled
alpha
login
or
join now
kitten.sh
/
fetch-nodeshim
Mirror: A Node.js fetch shim using built-in Request, Response, and Headers (but without native fetch)
0
fork
atom
overview
issues
pulls
pipelines
Compare changes
Choose any two refs to compare.
base:
main
v0.4.5
v0.4.4
v0.4.3
v0.4.2
v0.4.1
v0.4.0
v0.3.0
v0.2.1
v0.2.0
compare:
main
v0.4.5
v0.4.4
v0.4.3
v0.4.2
v0.4.1
v0.4.0
v0.3.0
v0.2.1
v0.2.0
go
+19
-9
3 changed files
expand all
collapse all
unified
split
CHANGELOG.md
package.json
src
body.ts
+7
CHANGELOG.md
···
1
1
# minifetch
2
2
3
3
+
## 0.4.6
4
4
+
5
5
+
### Patch Changes
6
6
+
7
7
+
- Replace undici `Response` with `node:stream/consumers` in body helper
8
8
+
Submitted by [@kitten](https://github.com/kitten) (See [#32](https://github.com/kitten/fetch-nodeshim/pull/32))
9
9
+
3
10
## 0.4.5
4
11
5
12
### Patch Changes
+1
-1
package.json
···
1
1
{
2
2
"name": "fetch-nodeshim",
3
3
-
"version": "0.4.5",
3
3
+
"version": "0.4.6",
4
4
"description": "A Node.js fetch shim using built-in Request, Response, and Headers (but without native fetch)",
5
5
"author": "Phil Pluckthun <phil@kitten.sh>",
6
6
"source": "./src/index.ts",
+11
-8
src/body.ts
···
1
1
import { Readable } from 'node:stream';
2
2
+
import { arrayBuffer, blob, text } from 'node:stream/consumers';
2
3
import { isAnyArrayBuffer } from 'node:util/types';
3
4
import { randomBytes } from 'node:crypto';
4
5
import { Response, Blob, FormData, URLSearchParams } from './webstd';
···
223
224
224
225
async arrayBuffer() {
225
226
const { body } = this[kBodyInternals];
226
226
-
return isAnyArrayBuffer(body)
227
227
-
? body
228
228
-
: new Response(this.body).arrayBuffer();
227
227
+
return body != null && !isAnyArrayBuffer(body) ? arrayBuffer(body) : body;
229
228
}
230
229
231
230
async formData() {
···
237
236
}
238
237
239
238
async blob() {
240
240
-
const { contentType } = this[kBodyInternals];
241
241
-
return new Blob([await this.arrayBuffer()], {
239
239
+
const { body, contentType } = this[kBodyInternals];
240
240
+
const chunks =
241
241
+
body !== null ? [!isAnyArrayBuffer(body) ? await blob(body) : body] : [];
242
242
+
return new Blob(chunks, {
242
243
type: contentType ?? undefined,
243
244
});
244
245
}
245
246
246
247
async json() {
247
247
-
const text = await this.text();
248
248
-
return JSON.parse(text);
248
248
+
return JSON.parse(await this.text());
249
249
}
250
250
251
251
async text() {
252
252
-
return new TextDecoder().decode(await this.arrayBuffer());
252
252
+
const { body } = this[kBodyInternals];
253
253
+
return body == null || isAnyArrayBuffer(body)
254
254
+
? new TextDecoder().decode(await this.arrayBuffer())
255
255
+
: text(body);
253
256
}
254
257
}