@whatwg-node/node-fetch 0.5.14 → 0.5.15
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/cjs/Blob.js +42 -5
- package/esm/Blob.js +41 -5
- package/package.json +1 -1
- package/typings/Blob.d.cts +2 -0
- package/typings/Blob.d.ts +2 -0
package/cjs/Blob.js
CHANGED
@@ -8,6 +8,7 @@ exports.hasTextMethod = hasTextMethod;
|
|
8
8
|
exports.hasSizeProperty = hasSizeProperty;
|
9
9
|
exports.hasStreamMethod = hasStreamMethod;
|
10
10
|
exports.hasBlobSignature = hasBlobSignature;
|
11
|
+
exports.isArrayBuffer = isArrayBuffer;
|
11
12
|
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
|
12
13
|
const ReadableStream_js_1 = require("./ReadableStream.js");
|
13
14
|
const utils_js_1 = require("./utils.js");
|
@@ -26,26 +27,29 @@ function getBlobPartAsBuffer(blobPart) {
|
|
26
27
|
}
|
27
28
|
}
|
28
29
|
function hasBufferMethod(obj) {
|
29
|
-
return obj != null && obj.buffer != null;
|
30
|
+
return obj != null && obj.buffer != null && typeof obj.buffer === 'function';
|
30
31
|
}
|
31
32
|
function hasArrayBufferMethod(obj) {
|
32
|
-
return obj != null && obj.arrayBuffer != null;
|
33
|
+
return obj != null && obj.arrayBuffer != null && typeof obj.arrayBuffer === 'function';
|
33
34
|
}
|
34
35
|
function hasBytesMethod(obj) {
|
35
|
-
return obj != null && obj.bytes != null;
|
36
|
+
return obj != null && obj.bytes != null && typeof obj.bytes === 'function';
|
36
37
|
}
|
37
38
|
function hasTextMethod(obj) {
|
38
|
-
return obj != null && obj.text != null;
|
39
|
+
return obj != null && obj.text != null && typeof obj.text === 'function';
|
39
40
|
}
|
40
41
|
function hasSizeProperty(obj) {
|
41
42
|
return obj != null && typeof obj.size === 'number';
|
42
43
|
}
|
43
44
|
function hasStreamMethod(obj) {
|
44
|
-
return obj != null && obj.stream != null;
|
45
|
+
return obj != null && obj.stream != null && typeof obj.stream === 'function';
|
45
46
|
}
|
46
47
|
function hasBlobSignature(obj) {
|
47
48
|
return obj != null && obj[Symbol.toStringTag] === 'Blob';
|
48
49
|
}
|
50
|
+
function isArrayBuffer(obj) {
|
51
|
+
return obj != null && obj.byteLength != null && obj.slice != null;
|
52
|
+
}
|
49
53
|
// Will be removed after v14 reaches EOL
|
50
54
|
// Needed because v14 doesn't have .stream() implemented
|
51
55
|
class PonyfillBlob {
|
@@ -118,6 +122,39 @@ class PonyfillBlob {
|
|
118
122
|
return (0, utils_js_1.fakePromise)(Buffer.concat(bufferChunks, this._size || undefined));
|
119
123
|
}
|
120
124
|
arrayBuffer() {
|
125
|
+
if (this._buffer) {
|
126
|
+
return (0, utils_js_1.fakePromise)(this._buffer);
|
127
|
+
}
|
128
|
+
if (this.blobParts.length === 1) {
|
129
|
+
if (isArrayBuffer(this.blobParts[0])) {
|
130
|
+
return (0, utils_js_1.fakePromise)(this.blobParts[0]);
|
131
|
+
}
|
132
|
+
if (hasArrayBufferMethod(this.blobParts[0])) {
|
133
|
+
return this.blobParts[0].arrayBuffer();
|
134
|
+
}
|
135
|
+
}
|
136
|
+
return this.buffer();
|
137
|
+
}
|
138
|
+
bytes() {
|
139
|
+
if (this._buffer) {
|
140
|
+
return (0, utils_js_1.fakePromise)(this._buffer);
|
141
|
+
}
|
142
|
+
if (this.blobParts.length === 1) {
|
143
|
+
if (Buffer.isBuffer(this.blobParts[0])) {
|
144
|
+
this._buffer = this.blobParts[0];
|
145
|
+
return (0, utils_js_1.fakePromise)(this.blobParts[0]);
|
146
|
+
}
|
147
|
+
if (this.blobParts[0] instanceof Uint8Array) {
|
148
|
+
this._buffer = Buffer.from(this.blobParts[0]);
|
149
|
+
return (0, utils_js_1.fakePromise)(this.blobParts[0]);
|
150
|
+
}
|
151
|
+
if (hasBytesMethod(this.blobParts[0])) {
|
152
|
+
return this.blobParts[0].bytes();
|
153
|
+
}
|
154
|
+
if (hasBufferMethod(this.blobParts[0])) {
|
155
|
+
return this.blobParts[0].buffer();
|
156
|
+
}
|
157
|
+
}
|
121
158
|
return this.buffer();
|
122
159
|
}
|
123
160
|
text() {
|
package/esm/Blob.js
CHANGED
@@ -16,26 +16,29 @@ function getBlobPartAsBuffer(blobPart) {
|
|
16
16
|
}
|
17
17
|
}
|
18
18
|
export function hasBufferMethod(obj) {
|
19
|
-
return obj != null && obj.buffer != null;
|
19
|
+
return obj != null && obj.buffer != null && typeof obj.buffer === 'function';
|
20
20
|
}
|
21
21
|
export function hasArrayBufferMethod(obj) {
|
22
|
-
return obj != null && obj.arrayBuffer != null;
|
22
|
+
return obj != null && obj.arrayBuffer != null && typeof obj.arrayBuffer === 'function';
|
23
23
|
}
|
24
24
|
export function hasBytesMethod(obj) {
|
25
|
-
return obj != null && obj.bytes != null;
|
25
|
+
return obj != null && obj.bytes != null && typeof obj.bytes === 'function';
|
26
26
|
}
|
27
27
|
export function hasTextMethod(obj) {
|
28
|
-
return obj != null && obj.text != null;
|
28
|
+
return obj != null && obj.text != null && typeof obj.text === 'function';
|
29
29
|
}
|
30
30
|
export function hasSizeProperty(obj) {
|
31
31
|
return obj != null && typeof obj.size === 'number';
|
32
32
|
}
|
33
33
|
export function hasStreamMethod(obj) {
|
34
|
-
return obj != null && obj.stream != null;
|
34
|
+
return obj != null && obj.stream != null && typeof obj.stream === 'function';
|
35
35
|
}
|
36
36
|
export function hasBlobSignature(obj) {
|
37
37
|
return obj != null && obj[Symbol.toStringTag] === 'Blob';
|
38
38
|
}
|
39
|
+
export function isArrayBuffer(obj) {
|
40
|
+
return obj != null && obj.byteLength != null && obj.slice != null;
|
41
|
+
}
|
39
42
|
// Will be removed after v14 reaches EOL
|
40
43
|
// Needed because v14 doesn't have .stream() implemented
|
41
44
|
export class PonyfillBlob {
|
@@ -108,6 +111,39 @@ export class PonyfillBlob {
|
|
108
111
|
return fakePromise(Buffer.concat(bufferChunks, this._size || undefined));
|
109
112
|
}
|
110
113
|
arrayBuffer() {
|
114
|
+
if (this._buffer) {
|
115
|
+
return fakePromise(this._buffer);
|
116
|
+
}
|
117
|
+
if (this.blobParts.length === 1) {
|
118
|
+
if (isArrayBuffer(this.blobParts[0])) {
|
119
|
+
return fakePromise(this.blobParts[0]);
|
120
|
+
}
|
121
|
+
if (hasArrayBufferMethod(this.blobParts[0])) {
|
122
|
+
return this.blobParts[0].arrayBuffer();
|
123
|
+
}
|
124
|
+
}
|
125
|
+
return this.buffer();
|
126
|
+
}
|
127
|
+
bytes() {
|
128
|
+
if (this._buffer) {
|
129
|
+
return fakePromise(this._buffer);
|
130
|
+
}
|
131
|
+
if (this.blobParts.length === 1) {
|
132
|
+
if (Buffer.isBuffer(this.blobParts[0])) {
|
133
|
+
this._buffer = this.blobParts[0];
|
134
|
+
return fakePromise(this.blobParts[0]);
|
135
|
+
}
|
136
|
+
if (this.blobParts[0] instanceof Uint8Array) {
|
137
|
+
this._buffer = Buffer.from(this.blobParts[0]);
|
138
|
+
return fakePromise(this.blobParts[0]);
|
139
|
+
}
|
140
|
+
if (hasBytesMethod(this.blobParts[0])) {
|
141
|
+
return this.blobParts[0].bytes();
|
142
|
+
}
|
143
|
+
if (hasBufferMethod(this.blobParts[0])) {
|
144
|
+
return this.blobParts[0].buffer();
|
145
|
+
}
|
146
|
+
}
|
111
147
|
return this.buffer();
|
112
148
|
}
|
113
149
|
text() {
|
package/package.json
CHANGED
package/typings/Blob.d.cts
CHANGED
@@ -33,6 +33,7 @@ export declare function hasStreamMethod(obj: any): obj is {
|
|
33
33
|
stream(): any;
|
34
34
|
};
|
35
35
|
export declare function hasBlobSignature(obj: any): obj is Blob;
|
36
|
+
export declare function isArrayBuffer(obj: any): obj is ArrayBuffer;
|
36
37
|
export declare class PonyfillBlob implements Blob {
|
37
38
|
private blobParts;
|
38
39
|
type: string;
|
@@ -42,6 +43,7 @@ export declare class PonyfillBlob implements Blob {
|
|
42
43
|
_buffer: Buffer | null;
|
43
44
|
buffer(): Promise<Buffer>;
|
44
45
|
arrayBuffer(): Promise<ArrayBuffer>;
|
46
|
+
bytes(): Promise<Uint8Array>;
|
45
47
|
_text: string | null;
|
46
48
|
text(): Promise<string>;
|
47
49
|
get size(): number;
|
package/typings/Blob.d.ts
CHANGED
@@ -33,6 +33,7 @@ export declare function hasStreamMethod(obj: any): obj is {
|
|
33
33
|
stream(): any;
|
34
34
|
};
|
35
35
|
export declare function hasBlobSignature(obj: any): obj is Blob;
|
36
|
+
export declare function isArrayBuffer(obj: any): obj is ArrayBuffer;
|
36
37
|
export declare class PonyfillBlob implements Blob {
|
37
38
|
private blobParts;
|
38
39
|
type: string;
|
@@ -42,6 +43,7 @@ export declare class PonyfillBlob implements Blob {
|
|
42
43
|
_buffer: Buffer | null;
|
43
44
|
buffer(): Promise<Buffer>;
|
44
45
|
arrayBuffer(): Promise<ArrayBuffer>;
|
46
|
+
bytes(): Promise<Uint8Array>;
|
45
47
|
_text: string | null;
|
46
48
|
text(): Promise<string>;
|
47
49
|
get size(): number;
|