@whatwg-node/node-fetch 0.0.3-alpha-20230205160723-6e9b185 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Blob.d.ts +3 -1
- package/index.js +8 -4
- package/index.mjs +8 -4
- package/package.json +1 -1
package/Blob.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { Blob as NodeBlob } from 'buffer';
|
3
|
-
|
3
|
+
declare const PonyfillBlob_base: typeof NodeBlob;
|
4
|
+
export declare class PonyfillBlob extends PonyfillBlob_base implements Blob {
|
4
5
|
stream(): any;
|
5
6
|
slice(...args: any[]): any;
|
6
7
|
}
|
@@ -8,3 +9,4 @@ export interface PonyfillBlob {
|
|
8
9
|
prototype: Blob;
|
9
10
|
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
10
11
|
}
|
12
|
+
export {};
|
package/index.js
CHANGED
@@ -172,9 +172,14 @@ class PonyfillReadableStream {
|
|
172
172
|
}
|
173
173
|
}
|
174
174
|
|
175
|
+
class DummyBlob {
|
176
|
+
constructor() {
|
177
|
+
throw new Error('Blob is not supported in this environment, if you are using an older version of Node v14, please upgrade to v14.17.0 or higher');
|
178
|
+
}
|
179
|
+
}
|
175
180
|
// Will be removed after v14 reaches EOL
|
176
181
|
// Needed because v14 doesn't have .stream() implemented
|
177
|
-
class PonyfillBlob extends buffer.Blob {
|
182
|
+
class PonyfillBlob extends (buffer.Blob || DummyBlob) {
|
178
183
|
stream() {
|
179
184
|
return new PonyfillReadableStream({
|
180
185
|
start: async (controller) => {
|
@@ -554,10 +559,9 @@ function processBodyInit(bodyInit) {
|
|
554
559
|
return {
|
555
560
|
bodyType: BodyInitType.String,
|
556
561
|
contentType: 'text/plain;charset=UTF-8',
|
557
|
-
contentLength: bodyInit
|
562
|
+
contentLength: Buffer.byteLength(bodyInit),
|
558
563
|
bodyFactory() {
|
559
|
-
const
|
560
|
-
const readable = stream.Readable.from(buffer);
|
564
|
+
const readable = stream.Readable.from(bodyInit);
|
561
565
|
return new PonyfillReadableStream(readable);
|
562
566
|
},
|
563
567
|
};
|
package/index.mjs
CHANGED
@@ -166,9 +166,14 @@ class PonyfillReadableStream {
|
|
166
166
|
}
|
167
167
|
}
|
168
168
|
|
169
|
+
class DummyBlob {
|
170
|
+
constructor() {
|
171
|
+
throw new Error('Blob is not supported in this environment, if you are using an older version of Node v14, please upgrade to v14.17.0 or higher');
|
172
|
+
}
|
173
|
+
}
|
169
174
|
// Will be removed after v14 reaches EOL
|
170
175
|
// Needed because v14 doesn't have .stream() implemented
|
171
|
-
class PonyfillBlob extends Blob {
|
176
|
+
class PonyfillBlob extends (Blob || DummyBlob) {
|
172
177
|
stream() {
|
173
178
|
return new PonyfillReadableStream({
|
174
179
|
start: async (controller) => {
|
@@ -548,10 +553,9 @@ function processBodyInit(bodyInit) {
|
|
548
553
|
return {
|
549
554
|
bodyType: BodyInitType.String,
|
550
555
|
contentType: 'text/plain;charset=UTF-8',
|
551
|
-
contentLength: bodyInit
|
556
|
+
contentLength: Buffer.byteLength(bodyInit),
|
552
557
|
bodyFactory() {
|
553
|
-
const
|
554
|
-
const readable = Readable.from(buffer);
|
558
|
+
const readable = Readable.from(bodyInit);
|
555
559
|
return new PonyfillReadableStream(readable);
|
556
560
|
},
|
557
561
|
};
|