rekwest 2.1.0 → 2.2.0
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/README.md +3 -1
- package/dist/formdata.js +17 -1
- package/package.json +1 -1
- package/src/formdata.mjs +24 -1
package/README.md
CHANGED
|
@@ -84,7 +84,9 @@ const blob = new Blob(['bits']);
|
|
|
84
84
|
const file = new File(['bits'], 'file.dab');
|
|
85
85
|
const readable = Readable.from('bits');
|
|
86
86
|
|
|
87
|
-
const fd = new FormData(
|
|
87
|
+
const fd = new FormData({
|
|
88
|
+
aux: Date.now(), // or [[key, value]]
|
|
89
|
+
});
|
|
88
90
|
|
|
89
91
|
fd.append('celestial', 'payload');
|
|
90
92
|
fd.append('blob', blob, 'blob.dab');
|
package/dist/formdata.js
CHANGED
|
@@ -65,7 +65,7 @@ class FormData {
|
|
|
65
65
|
if (_file.File.alike(value)) {
|
|
66
66
|
value = new _file.File([value], filename, value);
|
|
67
67
|
} else if (this.#ensureInstance(value)) {
|
|
68
|
-
value.name = filename;
|
|
68
|
+
value.name = filename || value.name;
|
|
69
69
|
} else {
|
|
70
70
|
value = (0, _util.toUSVString)(value);
|
|
71
71
|
}
|
|
@@ -86,6 +86,22 @@ class FormData {
|
|
|
86
86
|
return this.constructor.name;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
constructor(input) {
|
|
90
|
+
if (input !== undefined && ![Array, Object].includes(input?.constructor)) {
|
|
91
|
+
throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': parameter 1 is not of type 'Array' or 'Object'.`);
|
|
92
|
+
} else {
|
|
93
|
+
if (Array.isArray(input) && !input.every(it => Array.isArray(it) && it.length === 2)) {
|
|
94
|
+
throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': The provided value cannot be converted to a sequence.`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (input.constructor === Object) {
|
|
98
|
+
input = Object.entries(input);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
input.forEach(([key, value]) => this.append(key, value));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
89
105
|
#ensureArgs(args, expected, method) {
|
|
90
106
|
if (args.length < expected) {
|
|
91
107
|
throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': ${expected} arguments required, but only ${args.length} present.`);
|
package/package.json
CHANGED
package/src/formdata.mjs
CHANGED
|
@@ -62,7 +62,7 @@ export class FormData {
|
|
|
62
62
|
if (File.alike(value)) {
|
|
63
63
|
value = new File([value], filename, value);
|
|
64
64
|
} else if (this.#ensureInstance(value)) {
|
|
65
|
-
value.name = filename;
|
|
65
|
+
value.name = filename || value.name;
|
|
66
66
|
} else {
|
|
67
67
|
value = toUSVString(value);
|
|
68
68
|
}
|
|
@@ -83,6 +83,29 @@ export class FormData {
|
|
|
83
83
|
return this.constructor.name;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
constructor(input) {
|
|
87
|
+
if (input !== undefined && ![
|
|
88
|
+
Array,
|
|
89
|
+
Object,
|
|
90
|
+
].includes(input?.constructor)) {
|
|
91
|
+
throw new TypeError(`Failed to construct '${
|
|
92
|
+
this[Symbol.toStringTag]
|
|
93
|
+
}': parameter 1 is not of type 'Array' or 'Object'.`);
|
|
94
|
+
} else {
|
|
95
|
+
if (Array.isArray(input) && !input.every((it) => Array.isArray(it) && it.length === 2)) {
|
|
96
|
+
throw new TypeError(`Failed to construct '${
|
|
97
|
+
this[Symbol.toStringTag]
|
|
98
|
+
}': The provided value cannot be converted to a sequence.`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (input.constructor === Object) {
|
|
102
|
+
input = Object.entries(input);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
input.forEach(([key, value]) => this.append(key, value));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
86
109
|
#ensureArgs(args, expected, method) {
|
|
87
110
|
if (args.length < expected) {
|
|
88
111
|
throw new TypeError(`Failed to execute '${ method }' on '${
|