@whatwg-node/node-fetch 0.4.13-alpha-20230821122741-21a9569 → 0.4.13-alpha-20230821124424-6f3a2b1

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 CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PonyfillBlob = void 0;
4
4
  /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
5
5
  const ReadableStream_js_1 = require("./ReadableStream.js");
6
+ const utils_js_1 = require("./utils.js");
6
7
  function getBlobPartAsBuffer(blobPart) {
7
8
  if (typeof blobPart === 'string') {
8
9
  return Buffer.from(blobPart);
@@ -10,10 +11,7 @@ function getBlobPartAsBuffer(blobPart) {
10
11
  else if (Buffer.isBuffer(blobPart)) {
11
12
  return blobPart;
12
13
  }
13
- else if (blobPart instanceof Uint8Array) {
14
- return Buffer.from(blobPart);
15
- }
16
- else if ('buffer' in blobPart) {
14
+ else if ((0, utils_js_1.isArrayBufferView)(blobPart)) {
17
15
  return Buffer.from(blobPart.buffer, blobPart.byteOffset, blobPart.byteLength);
18
16
  }
19
17
  else {
@@ -21,7 +19,7 @@ function getBlobPartAsBuffer(blobPart) {
21
19
  }
22
20
  }
23
21
  function isBlob(obj) {
24
- return obj != null && typeof obj === 'object' && obj.arrayBuffer != null;
22
+ return obj != null && obj.arrayBuffer != null;
25
23
  }
26
24
  // Will be removed after v14 reaches EOL
27
25
  // Needed because v14 doesn't have .stream() implemented
@@ -55,7 +53,7 @@ class PonyfillBlob {
55
53
  if (typeof blobPart === 'string') {
56
54
  text += blobPart;
57
55
  }
58
- else if ('text' in blobPart) {
56
+ else if (isBlob(blobPart)) {
59
57
  text += await blobPart.text();
60
58
  }
61
59
  else {
@@ -74,10 +72,7 @@ class PonyfillBlob {
74
72
  else if (isBlob(blobPart)) {
75
73
  size += blobPart.size;
76
74
  }
77
- else if ('length' in blobPart) {
78
- size += blobPart.length;
79
- }
80
- else if ('byteLength' in blobPart) {
75
+ else if ((0, utils_js_1.isArrayBufferView)(blobPart)) {
81
76
  size += blobPart.byteLength;
82
77
  }
83
78
  }
package/cjs/Body.js CHANGED
@@ -187,14 +187,6 @@ class PonyfillBody {
187
187
  if (this._buffer) {
188
188
  return (0, utils_js_1.fakePromise)(Buffer.from(this._buffer.buffer, this._buffer.byteOffset, this._buffer.byteLength));
189
189
  }
190
- if (this.bodyType === BodyInitType.String) {
191
- return (0, utils_js_1.fakePromise)(Buffer.from(this.bodyInit));
192
- }
193
- if (this.bodyType === BodyInitType.Uint8Array || this.bodyType === BodyInitType.ArrayBuffer) {
194
- const bodyInitTyped = this.bodyInit;
195
- const buffer = Buffer.from(bodyInitTyped, 'byteOffset' in bodyInitTyped ? bodyInitTyped.byteOffset : undefined, bodyInitTyped.byteLength);
196
- return (0, utils_js_1.fakePromise)(buffer);
197
- }
198
190
  if (this.bodyType === BodyInitType.Blob) {
199
191
  if (this.bodyInit instanceof Blob_js_1.PonyfillBlob) {
200
192
  return this.bodyInit.buffer();
@@ -271,27 +263,15 @@ function processBodyInit(bodyInit) {
271
263
  },
272
264
  };
273
265
  }
274
- if (bodyInit instanceof Uint8Array) {
266
+ if ((0, utils_js_1.isArrayBufferView)(bodyInit)) {
275
267
  const contentLength = bodyInit.byteLength;
268
+ const buffer = Buffer.from(bodyInit.buffer, bodyInit.byteOffset, bodyInit.byteLength);
276
269
  return {
277
270
  bodyType: BodyInitType.Uint8Array,
278
- contentLength,
279
- contentType: null,
280
- buffer: bodyInit,
281
- bodyFactory() {
282
- const readable = stream_1.Readable.from(bodyInit);
283
- const body = new ReadableStream_js_1.PonyfillReadableStream(readable);
284
- return body;
285
- },
286
- };
287
- }
288
- if ('buffer' in bodyInit) {
289
- const contentLength = bodyInit.byteLength;
290
- return {
271
+ buffer,
291
272
  contentLength,
292
273
  contentType: null,
293
274
  bodyFactory() {
294
- const buffer = Buffer.from(bodyInit.buffer, bodyInit.byteOffset, bodyInit.byteLength);
295
275
  const readable = stream_1.Readable.from(buffer);
296
276
  const body = new ReadableStream_js_1.PonyfillReadableStream(readable);
297
277
  return body;
@@ -324,7 +304,7 @@ function processBodyInit(bodyInit) {
324
304
  },
325
305
  };
326
306
  }
327
- if ('stream' in bodyInit) {
307
+ if (isBlob(bodyInit)) {
328
308
  return {
329
309
  contentType: bodyInit.type,
330
310
  contentLength: bodyInit.size,
@@ -335,7 +315,7 @@ function processBodyInit(bodyInit) {
335
315
  },
336
316
  };
337
317
  }
338
- if ('sort' in bodyInit) {
318
+ if (isURLSearchParams(bodyInit)) {
339
319
  const contentType = 'application/x-www-form-urlencoded;charset=UTF-8';
340
320
  return {
341
321
  bodyType: BodyInitType.String,
@@ -347,7 +327,7 @@ function processBodyInit(bodyInit) {
347
327
  },
348
328
  };
349
329
  }
350
- if ('forEach' in bodyInit) {
330
+ if (isFormData(bodyInit)) {
351
331
  const boundary = Math.random().toString(36).substr(2);
352
332
  const contentType = `multipart/form-data; boundary=${boundary}`;
353
333
  return {
@@ -370,3 +350,12 @@ function processBodyInit(bodyInit) {
370
350
  }
371
351
  throw new Error('Unknown body type');
372
352
  }
353
+ function isFormData(value) {
354
+ return value?.forEach != null;
355
+ }
356
+ function isBlob(value) {
357
+ return value?.stream != null;
358
+ }
359
+ function isURLSearchParams(value) {
360
+ return value?.sort != null;
361
+ }
@@ -43,16 +43,22 @@ function createController(desiredSize, readable) {
43
43
  },
44
44
  };
45
45
  }
46
+ function isNodeReadable(obj) {
47
+ return obj?.read != null;
48
+ }
49
+ function isReadableStream(obj) {
50
+ return obj?.getReader != null;
51
+ }
46
52
  class PonyfillReadableStream {
47
53
  constructor(underlyingSource) {
48
54
  this.locked = false;
49
55
  if (underlyingSource instanceof PonyfillReadableStream) {
50
56
  this.readable = underlyingSource.readable;
51
57
  }
52
- else if (underlyingSource && 'read' in underlyingSource) {
58
+ else if (isNodeReadable(underlyingSource)) {
53
59
  this.readable = underlyingSource;
54
60
  }
55
- else if (underlyingSource && 'getReader' in underlyingSource) {
61
+ else if (isReadableStream(underlyingSource)) {
56
62
  let reader;
57
63
  let started = false;
58
64
  this.readable = new stream_1.Readable({
@@ -162,7 +168,7 @@ class PonyfillReadableStream {
162
168
  return readable;
163
169
  }
164
170
  static [Symbol.hasInstance](instance) {
165
- return instance != null && typeof instance === 'object' && 'getReader' in instance;
171
+ return isReadableStream(instance);
166
172
  }
167
173
  }
168
174
  exports.PonyfillReadableStream = PonyfillReadableStream;
package/cjs/Request.js CHANGED
@@ -6,6 +6,9 @@ const Headers_js_1 = require("./Headers.js");
6
6
  function isRequest(input) {
7
7
  return input[Symbol.toStringTag] === 'Request';
8
8
  }
9
+ function isURL(obj) {
10
+ return obj?.href != null;
11
+ }
9
12
  class PonyfillRequest extends Body_js_1.PonyfillBody {
10
13
  constructor(input, options) {
11
14
  let url;
@@ -14,7 +17,7 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
14
17
  if (typeof input === 'string') {
15
18
  url = input;
16
19
  }
17
- else if ('href' in input) {
20
+ else if (isURL(input)) {
18
21
  url = input.toString();
19
22
  }
20
23
  else if (isRequest(input)) {
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PonyfillURLSearchParams = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fast_querystring_1 = tslib_1.__importDefault(require("fast-querystring"));
6
+ function isURLSearchParams(value) {
7
+ return value?.entries != null;
8
+ }
6
9
  class PonyfillURLSearchParams {
7
10
  constructor(init) {
8
11
  if (init) {
@@ -15,7 +18,7 @@ class PonyfillURLSearchParams {
15
18
  this.params[key] = value;
16
19
  }
17
20
  }
18
- else if ('entries' in init) {
21
+ else if (isURLSearchParams(init)) {
19
22
  this.params = {};
20
23
  for (const [key, value] of init.entries()) {
21
24
  this.params[key] = value;
package/cjs/fetch.js CHANGED
@@ -35,8 +35,11 @@ function getResponseForDataUri(url) {
35
35
  },
36
36
  });
37
37
  }
38
+ function isURL(obj) {
39
+ return obj != null && obj.href != null;
40
+ }
38
41
  function fetchPonyfill(info, init) {
39
- if (typeof info === 'string' || 'href' in info) {
42
+ if (typeof info === 'string' || isURL(info)) {
40
43
  const ponyfillRequest = new Request_js_1.PonyfillRequest(info, init);
41
44
  return fetchPonyfill(ponyfillRequest);
42
45
  }
package/cjs/fetchCurl.js CHANGED
@@ -24,7 +24,7 @@ function fetchCurl(fetchRequest) {
24
24
  }
25
25
  else {
26
26
  const nodeReadable = (fetchRequest.body != null
27
- ? 'pipe' in fetchRequest.body
27
+ ? (0, utils_js_1.isNodeReadable)(fetchRequest.body)
28
28
  ? fetchRequest.body
29
29
  : node_stream_1.Readable.from(fetchRequest.body)
30
30
  : null);
@@ -24,7 +24,7 @@ function fetchNodeHttp(fetchRequest) {
24
24
  try {
25
25
  const requestFn = getRequestFnForProtocol(fetchRequest.url);
26
26
  const nodeReadable = (fetchRequest.body != null
27
- ? 'pipe' in fetchRequest.body
27
+ ? (0, utils_js_1.isNodeReadable)(fetchRequest.body)
28
28
  ? fetchRequest.body
29
29
  : stream_1.Readable.from(fetchRequest.body)
30
30
  : null);
package/cjs/utils.js CHANGED
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fakePromise = exports.defaultHeadersSerializer = exports.getHeadersObj = void 0;
3
+ exports.isNodeReadable = exports.isArrayBufferView = exports.fakePromise = exports.defaultHeadersSerializer = exports.getHeadersObj = void 0;
4
+ function isHeadersInstance(obj) {
5
+ return obj?.forEach != null;
6
+ }
4
7
  function getHeadersObj(headers) {
5
- if (headers == null || !('forEach' in headers)) {
8
+ if (headers == null || !isHeadersInstance(headers)) {
6
9
  return headers;
7
10
  }
8
11
  const obj = {};
@@ -57,3 +60,15 @@ function fakePromise(value) {
57
60
  };
58
61
  }
59
62
  exports.fakePromise = fakePromise;
63
+ function isArrayBufferView(obj) {
64
+ return (obj != null &&
65
+ typeof obj === 'object' &&
66
+ obj.buffer != null &&
67
+ obj.byteLength != null &&
68
+ obj.byteOffset != null);
69
+ }
70
+ exports.isArrayBufferView = isArrayBufferView;
71
+ function isNodeReadable(obj) {
72
+ return obj != null && obj.pipe != null;
73
+ }
74
+ exports.isNodeReadable = isNodeReadable;
package/esm/Blob.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
2
2
  import { PonyfillReadableStream } from './ReadableStream.js';
3
+ import { isArrayBufferView } from './utils.js';
3
4
  function getBlobPartAsBuffer(blobPart) {
4
5
  if (typeof blobPart === 'string') {
5
6
  return Buffer.from(blobPart);
@@ -7,10 +8,7 @@ function getBlobPartAsBuffer(blobPart) {
7
8
  else if (Buffer.isBuffer(blobPart)) {
8
9
  return blobPart;
9
10
  }
10
- else if (blobPart instanceof Uint8Array) {
11
- return Buffer.from(blobPart);
12
- }
13
- else if ('buffer' in blobPart) {
11
+ else if (isArrayBufferView(blobPart)) {
14
12
  return Buffer.from(blobPart.buffer, blobPart.byteOffset, blobPart.byteLength);
15
13
  }
16
14
  else {
@@ -18,7 +16,7 @@ function getBlobPartAsBuffer(blobPart) {
18
16
  }
19
17
  }
20
18
  function isBlob(obj) {
21
- return obj != null && typeof obj === 'object' && obj.arrayBuffer != null;
19
+ return obj != null && obj.arrayBuffer != null;
22
20
  }
23
21
  // Will be removed after v14 reaches EOL
24
22
  // Needed because v14 doesn't have .stream() implemented
@@ -52,7 +50,7 @@ export class PonyfillBlob {
52
50
  if (typeof blobPart === 'string') {
53
51
  text += blobPart;
54
52
  }
55
- else if ('text' in blobPart) {
53
+ else if (isBlob(blobPart)) {
56
54
  text += await blobPart.text();
57
55
  }
58
56
  else {
@@ -71,10 +69,7 @@ export class PonyfillBlob {
71
69
  else if (isBlob(blobPart)) {
72
70
  size += blobPart.size;
73
71
  }
74
- else if ('length' in blobPart) {
75
- size += blobPart.length;
76
- }
77
- else if ('byteLength' in blobPart) {
72
+ else if (isArrayBufferView(blobPart)) {
78
73
  size += blobPart.byteLength;
79
74
  }
80
75
  }
package/esm/Body.js CHANGED
@@ -4,7 +4,7 @@ import { PonyfillBlob } from './Blob.js';
4
4
  import { PonyfillFile } from './File.js';
5
5
  import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
6
6
  import { PonyfillReadableStream } from './ReadableStream.js';
7
- import { fakePromise } from './utils.js';
7
+ import { fakePromise, isArrayBufferView } from './utils.js';
8
8
  var BodyInitType;
9
9
  (function (BodyInitType) {
10
10
  BodyInitType["ReadableStream"] = "ReadableStream";
@@ -183,14 +183,6 @@ export class PonyfillBody {
183
183
  if (this._buffer) {
184
184
  return fakePromise(Buffer.from(this._buffer.buffer, this._buffer.byteOffset, this._buffer.byteLength));
185
185
  }
186
- if (this.bodyType === BodyInitType.String) {
187
- return fakePromise(Buffer.from(this.bodyInit));
188
- }
189
- if (this.bodyType === BodyInitType.Uint8Array || this.bodyType === BodyInitType.ArrayBuffer) {
190
- const bodyInitTyped = this.bodyInit;
191
- const buffer = Buffer.from(bodyInitTyped, 'byteOffset' in bodyInitTyped ? bodyInitTyped.byteOffset : undefined, bodyInitTyped.byteLength);
192
- return fakePromise(buffer);
193
- }
194
186
  if (this.bodyType === BodyInitType.Blob) {
195
187
  if (this.bodyInit instanceof PonyfillBlob) {
196
188
  return this.bodyInit.buffer();
@@ -266,27 +258,15 @@ function processBodyInit(bodyInit) {
266
258
  },
267
259
  };
268
260
  }
269
- if (bodyInit instanceof Uint8Array) {
261
+ if (isArrayBufferView(bodyInit)) {
270
262
  const contentLength = bodyInit.byteLength;
263
+ const buffer = Buffer.from(bodyInit.buffer, bodyInit.byteOffset, bodyInit.byteLength);
271
264
  return {
272
265
  bodyType: BodyInitType.Uint8Array,
273
- contentLength,
274
- contentType: null,
275
- buffer: bodyInit,
276
- bodyFactory() {
277
- const readable = Readable.from(bodyInit);
278
- const body = new PonyfillReadableStream(readable);
279
- return body;
280
- },
281
- };
282
- }
283
- if ('buffer' in bodyInit) {
284
- const contentLength = bodyInit.byteLength;
285
- return {
266
+ buffer,
286
267
  contentLength,
287
268
  contentType: null,
288
269
  bodyFactory() {
289
- const buffer = Buffer.from(bodyInit.buffer, bodyInit.byteOffset, bodyInit.byteLength);
290
270
  const readable = Readable.from(buffer);
291
271
  const body = new PonyfillReadableStream(readable);
292
272
  return body;
@@ -319,7 +299,7 @@ function processBodyInit(bodyInit) {
319
299
  },
320
300
  };
321
301
  }
322
- if ('stream' in bodyInit) {
302
+ if (isBlob(bodyInit)) {
323
303
  return {
324
304
  contentType: bodyInit.type,
325
305
  contentLength: bodyInit.size,
@@ -330,7 +310,7 @@ function processBodyInit(bodyInit) {
330
310
  },
331
311
  };
332
312
  }
333
- if ('sort' in bodyInit) {
313
+ if (isURLSearchParams(bodyInit)) {
334
314
  const contentType = 'application/x-www-form-urlencoded;charset=UTF-8';
335
315
  return {
336
316
  bodyType: BodyInitType.String,
@@ -342,7 +322,7 @@ function processBodyInit(bodyInit) {
342
322
  },
343
323
  };
344
324
  }
345
- if ('forEach' in bodyInit) {
325
+ if (isFormData(bodyInit)) {
346
326
  const boundary = Math.random().toString(36).substr(2);
347
327
  const contentType = `multipart/form-data; boundary=${boundary}`;
348
328
  return {
@@ -365,3 +345,12 @@ function processBodyInit(bodyInit) {
365
345
  }
366
346
  throw new Error('Unknown body type');
367
347
  }
348
+ function isFormData(value) {
349
+ return value?.forEach != null;
350
+ }
351
+ function isBlob(value) {
352
+ return value?.stream != null;
353
+ }
354
+ function isURLSearchParams(value) {
355
+ return value?.sort != null;
356
+ }
@@ -40,16 +40,22 @@ function createController(desiredSize, readable) {
40
40
  },
41
41
  };
42
42
  }
43
+ function isNodeReadable(obj) {
44
+ return obj?.read != null;
45
+ }
46
+ function isReadableStream(obj) {
47
+ return obj?.getReader != null;
48
+ }
43
49
  export class PonyfillReadableStream {
44
50
  constructor(underlyingSource) {
45
51
  this.locked = false;
46
52
  if (underlyingSource instanceof PonyfillReadableStream) {
47
53
  this.readable = underlyingSource.readable;
48
54
  }
49
- else if (underlyingSource && 'read' in underlyingSource) {
55
+ else if (isNodeReadable(underlyingSource)) {
50
56
  this.readable = underlyingSource;
51
57
  }
52
- else if (underlyingSource && 'getReader' in underlyingSource) {
58
+ else if (isReadableStream(underlyingSource)) {
53
59
  let reader;
54
60
  let started = false;
55
61
  this.readable = new Readable({
@@ -159,6 +165,6 @@ export class PonyfillReadableStream {
159
165
  return readable;
160
166
  }
161
167
  static [Symbol.hasInstance](instance) {
162
- return instance != null && typeof instance === 'object' && 'getReader' in instance;
168
+ return isReadableStream(instance);
163
169
  }
164
170
  }
package/esm/Request.js CHANGED
@@ -3,6 +3,9 @@ import { isHeadersLike, PonyfillHeaders } from './Headers.js';
3
3
  function isRequest(input) {
4
4
  return input[Symbol.toStringTag] === 'Request';
5
5
  }
6
+ function isURL(obj) {
7
+ return obj?.href != null;
8
+ }
6
9
  export class PonyfillRequest extends PonyfillBody {
7
10
  constructor(input, options) {
8
11
  let url;
@@ -11,7 +14,7 @@ export class PonyfillRequest extends PonyfillBody {
11
14
  if (typeof input === 'string') {
12
15
  url = input;
13
16
  }
14
- else if ('href' in input) {
17
+ else if (isURL(input)) {
15
18
  url = input.toString();
16
19
  }
17
20
  else if (isRequest(input)) {
@@ -1,4 +1,7 @@
1
1
  import FastQuerystring from 'fast-querystring';
2
+ function isURLSearchParams(value) {
3
+ return value?.entries != null;
4
+ }
2
5
  export class PonyfillURLSearchParams {
3
6
  constructor(init) {
4
7
  if (init) {
@@ -11,7 +14,7 @@ export class PonyfillURLSearchParams {
11
14
  this.params[key] = value;
12
15
  }
13
16
  }
14
- else if ('entries' in init) {
17
+ else if (isURLSearchParams(init)) {
15
18
  this.params = {};
16
19
  for (const [key, value] of init.entries()) {
17
20
  this.params[key] = value;
package/esm/fetch.js CHANGED
@@ -32,8 +32,11 @@ function getResponseForDataUri(url) {
32
32
  },
33
33
  });
34
34
  }
35
+ function isURL(obj) {
36
+ return obj != null && obj.href != null;
37
+ }
35
38
  export function fetchPonyfill(info, init) {
36
- if (typeof info === 'string' || 'href' in info) {
39
+ if (typeof info === 'string' || isURL(info)) {
37
40
  const ponyfillRequest = new PonyfillRequest(info, init);
38
41
  return fetchPonyfill(ponyfillRequest);
39
42
  }
package/esm/fetchCurl.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Readable } from 'node:stream';
2
2
  import { PonyfillAbortError } from './AbortError.js';
3
3
  import { PonyfillResponse } from './Response.js';
4
- import { defaultHeadersSerializer } from './utils.js';
4
+ import { defaultHeadersSerializer, isNodeReadable } from './utils.js';
5
5
  export function fetchCurl(fetchRequest) {
6
6
  const { Curl, CurlCode, CurlFeature, CurlPause, CurlProgressFunc } = globalThis['libcurl'];
7
7
  const curlHandle = new Curl();
@@ -21,7 +21,7 @@ export function fetchCurl(fetchRequest) {
21
21
  }
22
22
  else {
23
23
  const nodeReadable = (fetchRequest.body != null
24
- ? 'pipe' in fetchRequest.body
24
+ ? isNodeReadable(fetchRequest.body)
25
25
  ? fetchRequest.body
26
26
  : Readable.from(fetchRequest.body)
27
27
  : null);
@@ -6,7 +6,7 @@ import { PonyfillAbortError } from './AbortError.js';
6
6
  import { PonyfillRequest } from './Request.js';
7
7
  import { PonyfillResponse } from './Response.js';
8
8
  import { PonyfillURL } from './URL.js';
9
- import { getHeadersObj } from './utils.js';
9
+ import { getHeadersObj, isNodeReadable } from './utils.js';
10
10
  function getRequestFnForProtocol(url) {
11
11
  if (url.startsWith('http:')) {
12
12
  return httpRequest;
@@ -21,7 +21,7 @@ export function fetchNodeHttp(fetchRequest) {
21
21
  try {
22
22
  const requestFn = getRequestFnForProtocol(fetchRequest.url);
23
23
  const nodeReadable = (fetchRequest.body != null
24
- ? 'pipe' in fetchRequest.body
24
+ ? isNodeReadable(fetchRequest.body)
25
25
  ? fetchRequest.body
26
26
  : Readable.from(fetchRequest.body)
27
27
  : null);
package/esm/utils.js CHANGED
@@ -1,5 +1,8 @@
1
+ function isHeadersInstance(obj) {
2
+ return obj?.forEach != null;
3
+ }
1
4
  export function getHeadersObj(headers) {
2
- if (headers == null || !('forEach' in headers)) {
5
+ if (headers == null || !isHeadersInstance(headers)) {
3
6
  return headers;
4
7
  }
5
8
  const obj = {};
@@ -51,3 +54,13 @@ export function fakePromise(value) {
51
54
  [Symbol.toStringTag]: 'Promise',
52
55
  };
53
56
  }
57
+ export function isArrayBufferView(obj) {
58
+ return (obj != null &&
59
+ typeof obj === 'object' &&
60
+ obj.buffer != null &&
61
+ obj.byteLength != null &&
62
+ obj.byteOffset != null);
63
+ }
64
+ export function isNodeReadable(obj) {
65
+ return obj != null && obj.pipe != null;
66
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.4.13-alpha-20230821122741-21a9569",
3
+ "version": "0.4.13-alpha-20230821124424-6f3a2b1",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -1,3 +1,7 @@
1
+ /// <reference types="node" />
2
+ import { Readable } from 'node:stream';
1
3
  export declare function getHeadersObj(headers: Headers): Record<string, string>;
2
4
  export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
3
5
  export declare function fakePromise<T>(value: T): Promise<T>;
6
+ export declare function isArrayBufferView(obj: any): obj is ArrayBufferView;
7
+ export declare function isNodeReadable(obj: any): obj is Readable;
@@ -1,3 +1,7 @@
1
+ /// <reference types="node" />
2
+ import { Readable } from 'node:stream';
1
3
  export declare function getHeadersObj(headers: Headers): Record<string, string>;
2
4
  export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
3
5
  export declare function fakePromise<T>(value: T): Promise<T>;
6
+ export declare function isArrayBufferView(obj: any): obj is ArrayBufferView;
7
+ export declare function isNodeReadable(obj: any): obj is Readable;