@whatwg-node/node-fetch 0.0.2-alpha-20230202192735-c9da64f → 0.0.2
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/index.js +14 -7
- package/index.mjs +14 -7
- package/package.json +1 -1
package/index.js
CHANGED
@@ -251,7 +251,9 @@ class PonyfillFormData {
|
|
251
251
|
values = [];
|
252
252
|
this.map.set(name, values);
|
253
253
|
}
|
254
|
-
const entry =
|
254
|
+
const entry = isBlob(value)
|
255
|
+
? getNormalizedFile(name, value, fileName)
|
256
|
+
: value;
|
255
257
|
values.push(entry);
|
256
258
|
}
|
257
259
|
delete(name) {
|
@@ -268,7 +270,9 @@ class PonyfillFormData {
|
|
268
270
|
return this.map.has(name);
|
269
271
|
}
|
270
272
|
set(name, value, fileName) {
|
271
|
-
const entry =
|
273
|
+
const entry = isBlob(value)
|
274
|
+
? getNormalizedFile(name, value, fileName)
|
275
|
+
: value;
|
272
276
|
this.map.set(name, [entry]);
|
273
277
|
}
|
274
278
|
*[Symbol.iterator]() {
|
@@ -296,11 +300,7 @@ class PonyfillFormData {
|
|
296
300
|
const entry = entries.shift();
|
297
301
|
if (entry) {
|
298
302
|
const [key, value] = entry;
|
299
|
-
if (
|
300
|
-
controller.enqueue(Buffer.from(`Content-Disposition: form-data; name="${key}"\r\n\r\n`));
|
301
|
-
controller.enqueue(Buffer.from(value));
|
302
|
-
}
|
303
|
-
else {
|
303
|
+
if (value instanceof PonyfillFile) {
|
304
304
|
let filenamePart = '';
|
305
305
|
if (value.name) {
|
306
306
|
filenamePart = `; filename="${value.name}"`;
|
@@ -309,6 +309,10 @@ class PonyfillFormData {
|
|
309
309
|
controller.enqueue(Buffer.from(`Content-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`));
|
310
310
|
controller.enqueue(Buffer.from(await value.arrayBuffer()));
|
311
311
|
}
|
312
|
+
else {
|
313
|
+
controller.enqueue(Buffer.from(`Content-Disposition: form-data; name="${key}"\r\n\r\n`));
|
314
|
+
controller.enqueue(Buffer.from(value));
|
315
|
+
}
|
312
316
|
if (entries.length === 0) {
|
313
317
|
controller.enqueue(Buffer.from(`\r\n--${boundary}--\r\n`));
|
314
318
|
controller.close();
|
@@ -337,6 +341,9 @@ function getNormalizedFile(name, blob, fileName) {
|
|
337
341
|
}
|
338
342
|
return new PonyfillFile([blob], fileName || name, { type: blob.type });
|
339
343
|
}
|
344
|
+
function isBlob(value) {
|
345
|
+
return value != null && typeof value === 'object' && typeof value.arrayBuffer === 'function';
|
346
|
+
}
|
340
347
|
|
341
348
|
var BodyInitType;
|
342
349
|
(function (BodyInitType) {
|
package/index.mjs
CHANGED
@@ -245,7 +245,9 @@ class PonyfillFormData {
|
|
245
245
|
values = [];
|
246
246
|
this.map.set(name, values);
|
247
247
|
}
|
248
|
-
const entry =
|
248
|
+
const entry = isBlob(value)
|
249
|
+
? getNormalizedFile(name, value, fileName)
|
250
|
+
: value;
|
249
251
|
values.push(entry);
|
250
252
|
}
|
251
253
|
delete(name) {
|
@@ -262,7 +264,9 @@ class PonyfillFormData {
|
|
262
264
|
return this.map.has(name);
|
263
265
|
}
|
264
266
|
set(name, value, fileName) {
|
265
|
-
const entry =
|
267
|
+
const entry = isBlob(value)
|
268
|
+
? getNormalizedFile(name, value, fileName)
|
269
|
+
: value;
|
266
270
|
this.map.set(name, [entry]);
|
267
271
|
}
|
268
272
|
*[Symbol.iterator]() {
|
@@ -290,11 +294,7 @@ class PonyfillFormData {
|
|
290
294
|
const entry = entries.shift();
|
291
295
|
if (entry) {
|
292
296
|
const [key, value] = entry;
|
293
|
-
if (
|
294
|
-
controller.enqueue(Buffer.from(`Content-Disposition: form-data; name="${key}"\r\n\r\n`));
|
295
|
-
controller.enqueue(Buffer.from(value));
|
296
|
-
}
|
297
|
-
else {
|
297
|
+
if (value instanceof PonyfillFile) {
|
298
298
|
let filenamePart = '';
|
299
299
|
if (value.name) {
|
300
300
|
filenamePart = `; filename="${value.name}"`;
|
@@ -303,6 +303,10 @@ class PonyfillFormData {
|
|
303
303
|
controller.enqueue(Buffer.from(`Content-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`));
|
304
304
|
controller.enqueue(Buffer.from(await value.arrayBuffer()));
|
305
305
|
}
|
306
|
+
else {
|
307
|
+
controller.enqueue(Buffer.from(`Content-Disposition: form-data; name="${key}"\r\n\r\n`));
|
308
|
+
controller.enqueue(Buffer.from(value));
|
309
|
+
}
|
306
310
|
if (entries.length === 0) {
|
307
311
|
controller.enqueue(Buffer.from(`\r\n--${boundary}--\r\n`));
|
308
312
|
controller.close();
|
@@ -331,6 +335,9 @@ function getNormalizedFile(name, blob, fileName) {
|
|
331
335
|
}
|
332
336
|
return new PonyfillFile([blob], fileName || name, { type: blob.type });
|
333
337
|
}
|
338
|
+
function isBlob(value) {
|
339
|
+
return value != null && typeof value === 'object' && typeof value.arrayBuffer === 'function';
|
340
|
+
}
|
334
341
|
|
335
342
|
var BodyInitType;
|
336
343
|
(function (BodyInitType) {
|