Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@whatwg-node/node-fetch

Package Overview
Dependencies
Maintainers
1
Versions
509
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@whatwg-node/node-fetch - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

1

Blob.d.ts

@@ -8,2 +8,3 @@ /// <reference types="node" />

constructor(blobParts: BlobPart[], options?: BlobOptions);
buffer(): Promise<Buffer>;
arrayBuffer(): Promise<ArrayBuffer>;

@@ -10,0 +11,0 @@ text(): Promise<string>;

@@ -33,2 +33,3 @@ /// <reference types="node" />

arrayBuffer(): Promise<ArrayBuffer>;
_collectChunksFromReadable(): Promise<Uint8Array[]>;
blob(): Promise<PonyfillBlob>;

@@ -35,0 +36,0 @@ formData(opts?: {

73

index.js

@@ -212,3 +212,3 @@ 'use strict';

}
function uint8ArrayToBuffer(uint8array) {
function uint8ArrayToArrayBuffer(uint8array) {
return uint8array.buffer.slice(uint8array.byteOffset, uint8array.byteOffset + uint8array.byteLength);

@@ -245,3 +245,3 @@ }

}
async arrayBuffer() {
async buffer() {
const bufferChunks = [];

@@ -259,4 +259,8 @@ for (const blobPart of this.blobParts) {

}
return uint8ArrayToBuffer(Buffer.concat(bufferChunks));
return Buffer.concat(bufferChunks);
}
async arrayBuffer() {
const buffer = await this.buffer();
return uint8ArrayToArrayBuffer(buffer);
}
async text() {

@@ -561,7 +565,26 @@ let text = '';

const typedBodyInit = this.bodyInit;
return uint8ArrayToBuffer(typedBodyInit);
return uint8ArrayToArrayBuffer(typedBodyInit);
}
if (this.bodyType === BodyInitType.String) {
const buffer = Buffer.from(this.bodyInit);
return uint8ArrayToArrayBuffer(buffer);
}
if (this.bodyType === BodyInitType.Blob) {
const blob = this.bodyInit;
const arrayBuffer = await blob.arrayBuffer();
return arrayBuffer;
}
const blob = await this.blob();
return blob.arrayBuffer();
}
async _collectChunksFromReadable() {
const chunks = [];
const _body = this.generateBody();
if (_body) {
for await (const chunk of _body.readable) {
chunks.push(chunk);
}
}
return chunks;
}
async blob() {

@@ -586,9 +609,3 @@ if (this.bodyType === BodyInitType.Blob) {

}
const chunks = [];
const _body = this.generateBody();
if (_body) {
for await (const chunk of _body.readable) {
chunks.push(chunk);
}
}
const chunks = await this._collectChunksFromReadable();
return new PonyfillBlob(chunks, {

@@ -666,2 +683,5 @@ type: this.contentType || '',

}
if (this.bodyType === BodyInitType.String) {
return Buffer.from(this.bodyInit);
}
if (this.bodyType === BodyInitType.Uint8Array || this.bodyType === BodyInitType.ArrayBuffer) {

@@ -672,5 +692,12 @@ const bodyInitTyped = this.bodyInit;

}
const blob = await this.blob();
const arrayBuffer = await blob.arrayBuffer();
return Buffer.from(arrayBuffer, undefined, arrayBuffer.byteLength);
if (this.bodyType === BodyInitType.Blob) {
if (this.bodyInit instanceof PonyfillBlob) {
return this.bodyInit.buffer();
}
const bodyInitTyped = this.bodyInit;
const buffer = Buffer.from(await bodyInitTyped.arrayBuffer(), undefined, bodyInitTyped.size);
return buffer;
}
const chunks = await this._collectChunksFromReadable();
return Buffer.concat(chunks);
}

@@ -685,12 +712,4 @@ async json() {

}
if (this.bodyType === BodyInitType.Buffer) {
return this.bodyInit.toString('utf-8');
}
if (this.bodyType === BodyInitType.ArrayBuffer || this.bodyType === BodyInitType.Uint8Array) {
const bodyInitTyped = this.bodyInit;
const buffer = Buffer.from(bodyInitTyped, 'byteOffset' in bodyInitTyped ? bodyInitTyped.byteOffset : undefined, bodyInitTyped.byteLength);
return buffer.toString('utf-8');
}
const blob = await this.blob();
return blob.text();
const buffer = await this.buffer();
return buffer.toString('utf-8');
}

@@ -1168,3 +1187,3 @@ }

*entries() {
for (const key in this.keys()) {
for (const key of this.keys()) {
const value = this.params[key];

@@ -1176,3 +1195,5 @@ if (Array.isArray(value)) {

}
yield [key, value];
else {
yield [key, value];
}
}

@@ -1179,0 +1200,0 @@ }

{
"name": "@whatwg-node/node-fetch",
"version": "0.2.0",
"version": "0.3.0",
"description": "Fetch API implementation for Node",

@@ -5,0 +5,0 @@ "sideEffects": false,

export declare function getHeadersObj(headers: Headers): Record<string, string>;
export declare function uint8ArrayToBuffer(uint8array: Uint8Array): ArrayBuffer;
export declare function uint8ArrayToArrayBuffer(uint8array: Uint8Array): ArrayBuffer;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc