@whatwg-node/node-fetch
Advanced tools
Comparing version 0.5.14 to 0.5.15
@@ -11,2 +11,3 @@ "use strict"; | ||
exports.hasBlobSignature = hasBlobSignature; | ||
exports.isArrayBuffer = isArrayBuffer; | ||
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ | ||
@@ -30,12 +31,12 @@ const ReadableStream_js_1 = require("./ReadableStream.js"); | ||
function hasBufferMethod(obj) { | ||
return obj != null && obj.buffer != null; | ||
return obj != null && obj.buffer != null && typeof obj.buffer === 'function'; | ||
} | ||
function hasArrayBufferMethod(obj) { | ||
return obj != null && obj.arrayBuffer != null; | ||
return obj != null && obj.arrayBuffer != null && typeof obj.arrayBuffer === 'function'; | ||
} | ||
function hasBytesMethod(obj) { | ||
return obj != null && obj.bytes != null; | ||
return obj != null && obj.bytes != null && typeof obj.bytes === 'function'; | ||
} | ||
function hasTextMethod(obj) { | ||
return obj != null && obj.text != null; | ||
return obj != null && obj.text != null && typeof obj.text === 'function'; | ||
} | ||
@@ -46,3 +47,3 @@ function hasSizeProperty(obj) { | ||
function hasStreamMethod(obj) { | ||
return obj != null && obj.stream != null; | ||
return obj != null && obj.stream != null && typeof obj.stream === 'function'; | ||
} | ||
@@ -52,2 +53,5 @@ function hasBlobSignature(obj) { | ||
} | ||
function isArrayBuffer(obj) { | ||
return obj != null && obj.byteLength != null && obj.slice != null; | ||
} | ||
// Will be removed after v14 reaches EOL | ||
@@ -125,4 +129,37 @@ // Needed because v14 doesn't have .stream() implemented | ||
arrayBuffer() { | ||
if (this._buffer) { | ||
return (0, utils_js_1.fakePromise)(this._buffer); | ||
} | ||
if (this.blobParts.length === 1) { | ||
if (isArrayBuffer(this.blobParts[0])) { | ||
return (0, utils_js_1.fakePromise)(this.blobParts[0]); | ||
} | ||
if (hasArrayBufferMethod(this.blobParts[0])) { | ||
return this.blobParts[0].arrayBuffer(); | ||
} | ||
} | ||
return this.buffer(); | ||
} | ||
bytes() { | ||
if (this._buffer) { | ||
return (0, utils_js_1.fakePromise)(this._buffer); | ||
} | ||
if (this.blobParts.length === 1) { | ||
if (Buffer.isBuffer(this.blobParts[0])) { | ||
this._buffer = this.blobParts[0]; | ||
return (0, utils_js_1.fakePromise)(this.blobParts[0]); | ||
} | ||
if (this.blobParts[0] instanceof Uint8Array) { | ||
this._buffer = Buffer.from(this.blobParts[0]); | ||
return (0, utils_js_1.fakePromise)(this.blobParts[0]); | ||
} | ||
if (hasBytesMethod(this.blobParts[0])) { | ||
return this.blobParts[0].bytes(); | ||
} | ||
if (hasBufferMethod(this.blobParts[0])) { | ||
return this.blobParts[0].buffer(); | ||
} | ||
} | ||
return this.buffer(); | ||
} | ||
text() { | ||
@@ -129,0 +166,0 @@ if (this._text) { |
@@ -19,12 +19,12 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ | ||
export function hasBufferMethod(obj) { | ||
return obj != null && obj.buffer != null; | ||
return obj != null && obj.buffer != null && typeof obj.buffer === 'function'; | ||
} | ||
export function hasArrayBufferMethod(obj) { | ||
return obj != null && obj.arrayBuffer != null; | ||
return obj != null && obj.arrayBuffer != null && typeof obj.arrayBuffer === 'function'; | ||
} | ||
export function hasBytesMethod(obj) { | ||
return obj != null && obj.bytes != null; | ||
return obj != null && obj.bytes != null && typeof obj.bytes === 'function'; | ||
} | ||
export function hasTextMethod(obj) { | ||
return obj != null && obj.text != null; | ||
return obj != null && obj.text != null && typeof obj.text === 'function'; | ||
} | ||
@@ -35,3 +35,3 @@ export function hasSizeProperty(obj) { | ||
export function hasStreamMethod(obj) { | ||
return obj != null && obj.stream != null; | ||
return obj != null && obj.stream != null && typeof obj.stream === 'function'; | ||
} | ||
@@ -41,2 +41,5 @@ export function hasBlobSignature(obj) { | ||
} | ||
export function isArrayBuffer(obj) { | ||
return obj != null && obj.byteLength != null && obj.slice != null; | ||
} | ||
// Will be removed after v14 reaches EOL | ||
@@ -114,4 +117,37 @@ // Needed because v14 doesn't have .stream() implemented | ||
arrayBuffer() { | ||
if (this._buffer) { | ||
return fakePromise(this._buffer); | ||
} | ||
if (this.blobParts.length === 1) { | ||
if (isArrayBuffer(this.blobParts[0])) { | ||
return fakePromise(this.blobParts[0]); | ||
} | ||
if (hasArrayBufferMethod(this.blobParts[0])) { | ||
return this.blobParts[0].arrayBuffer(); | ||
} | ||
} | ||
return this.buffer(); | ||
} | ||
bytes() { | ||
if (this._buffer) { | ||
return fakePromise(this._buffer); | ||
} | ||
if (this.blobParts.length === 1) { | ||
if (Buffer.isBuffer(this.blobParts[0])) { | ||
this._buffer = this.blobParts[0]; | ||
return fakePromise(this.blobParts[0]); | ||
} | ||
if (this.blobParts[0] instanceof Uint8Array) { | ||
this._buffer = Buffer.from(this.blobParts[0]); | ||
return fakePromise(this.blobParts[0]); | ||
} | ||
if (hasBytesMethod(this.blobParts[0])) { | ||
return this.blobParts[0].bytes(); | ||
} | ||
if (hasBufferMethod(this.blobParts[0])) { | ||
return this.blobParts[0].buffer(); | ||
} | ||
} | ||
return this.buffer(); | ||
} | ||
text() { | ||
@@ -118,0 +154,0 @@ if (this._text) { |
{ | ||
"name": "@whatwg-node/node-fetch", | ||
"version": "0.5.14", | ||
"version": "0.5.15", | ||
"description": "Fetch API implementation for Node", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -36,2 +36,3 @@ interface BlobOptions { | ||
export declare function hasBlobSignature(obj: any): obj is Blob; | ||
export declare function isArrayBuffer(obj: any): obj is ArrayBuffer; | ||
export declare class PonyfillBlob implements Blob { | ||
@@ -46,2 +47,3 @@ private blobParts; | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
bytes(): Promise<Uint8Array>; | ||
_text: string | null; | ||
@@ -48,0 +50,0 @@ text(): Promise<string>; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
169820
4338