@common.js/formdata-polyfill 4.0.10
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/FormData.js +752 -0
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/esm.min.d.ts +5 -0
- package/esm.min.js +578 -0
- package/formdata-to-blob.js +93 -0
- package/formdata.min.js +507 -0
- package/package.json +38 -0
package/FormData.js
ADDED
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
/* formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */ /* global FormData self Blob File */ /* eslint-disable no-inner-declarations */ "use strict";
|
|
2
|
+
function _arrayLikeToArray(arr, len) {
|
|
3
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
+
return arr2;
|
|
6
|
+
}
|
|
7
|
+
function _arrayWithHoles(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return arr;
|
|
9
|
+
}
|
|
10
|
+
function _classCallCheck(instance, Constructor) {
|
|
11
|
+
if (!(instance instanceof Constructor)) {
|
|
12
|
+
throw new TypeError("Cannot call a class as a function");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _defineProperties(target, props) {
|
|
16
|
+
for(var i = 0; i < props.length; i++){
|
|
17
|
+
var descriptor = props[i];
|
|
18
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
19
|
+
descriptor.configurable = true;
|
|
20
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
21
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
25
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
26
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
27
|
+
return Constructor;
|
|
28
|
+
}
|
|
29
|
+
function _instanceof(left, right) {
|
|
30
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
31
|
+
return !!right[Symbol.hasInstance](left);
|
|
32
|
+
} else {
|
|
33
|
+
return left instanceof right;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function _iterableToArrayLimit(arr, i) {
|
|
37
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
38
|
+
if (_i == null) return;
|
|
39
|
+
var _arr = [];
|
|
40
|
+
var _n = true;
|
|
41
|
+
var _d = false;
|
|
42
|
+
var _s, _e;
|
|
43
|
+
try {
|
|
44
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
45
|
+
_arr.push(_s.value);
|
|
46
|
+
if (i && _arr.length === i) break;
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
_d = true;
|
|
50
|
+
_e = err;
|
|
51
|
+
} finally{
|
|
52
|
+
try {
|
|
53
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
54
|
+
} finally{
|
|
55
|
+
if (_d) throw _e;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return _arr;
|
|
59
|
+
}
|
|
60
|
+
function _nonIterableRest() {
|
|
61
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
62
|
+
}
|
|
63
|
+
function _slicedToArray(arr, i) {
|
|
64
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
65
|
+
}
|
|
66
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
67
|
+
if (!o) return;
|
|
68
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
69
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
70
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
71
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
72
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
73
|
+
}
|
|
74
|
+
var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
75
|
+
var f, y, t, g, _ = {
|
|
76
|
+
label: 0,
|
|
77
|
+
sent: function() {
|
|
78
|
+
if (t[0] & 1) throw t[1];
|
|
79
|
+
return t[1];
|
|
80
|
+
},
|
|
81
|
+
trys: [],
|
|
82
|
+
ops: []
|
|
83
|
+
};
|
|
84
|
+
return g = {
|
|
85
|
+
next: verb(0),
|
|
86
|
+
"throw": verb(1),
|
|
87
|
+
"return": verb(2)
|
|
88
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
89
|
+
return this;
|
|
90
|
+
}), g;
|
|
91
|
+
function verb(n) {
|
|
92
|
+
return function(v) {
|
|
93
|
+
return step([
|
|
94
|
+
n,
|
|
95
|
+
v
|
|
96
|
+
]);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function step(op) {
|
|
100
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
101
|
+
while(_)try {
|
|
102
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
103
|
+
if (y = 0, t) op = [
|
|
104
|
+
op[0] & 2,
|
|
105
|
+
t.value
|
|
106
|
+
];
|
|
107
|
+
switch(op[0]){
|
|
108
|
+
case 0:
|
|
109
|
+
case 1:
|
|
110
|
+
t = op;
|
|
111
|
+
break;
|
|
112
|
+
case 4:
|
|
113
|
+
_.label++;
|
|
114
|
+
return {
|
|
115
|
+
value: op[1],
|
|
116
|
+
done: false
|
|
117
|
+
};
|
|
118
|
+
case 5:
|
|
119
|
+
_.label++;
|
|
120
|
+
y = op[1];
|
|
121
|
+
op = [
|
|
122
|
+
0
|
|
123
|
+
];
|
|
124
|
+
continue;
|
|
125
|
+
case 7:
|
|
126
|
+
op = _.ops.pop();
|
|
127
|
+
_.trys.pop();
|
|
128
|
+
continue;
|
|
129
|
+
default:
|
|
130
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
131
|
+
_ = 0;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
135
|
+
_.label = op[1];
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
139
|
+
_.label = t[1];
|
|
140
|
+
t = op;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (t && _.label < t[2]) {
|
|
144
|
+
_.label = t[2];
|
|
145
|
+
_.ops.push(op);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
if (t[2]) _.ops.pop();
|
|
149
|
+
_.trys.pop();
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
op = body.call(thisArg, _);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
op = [
|
|
155
|
+
6,
|
|
156
|
+
e
|
|
157
|
+
];
|
|
158
|
+
y = 0;
|
|
159
|
+
} finally{
|
|
160
|
+
f = t = 0;
|
|
161
|
+
}
|
|
162
|
+
if (op[0] & 5) throw op[1];
|
|
163
|
+
return {
|
|
164
|
+
value: op[0] ? op[1] : void 0,
|
|
165
|
+
done: true
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
if (typeof Blob !== "undefined" && (typeof FormData === "undefined" || !FormData.prototype.keys)) {
|
|
170
|
+
var ensureArgs = function ensureArgs(args, expected) {
|
|
171
|
+
if (args.length < expected) {
|
|
172
|
+
throw new TypeError("".concat(expected, " argument required, but only ").concat(args.length, " present."));
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var normalizeArgs = /**
|
|
176
|
+
* @param {string} name
|
|
177
|
+
* @param {string | undefined} filename
|
|
178
|
+
* @returns {[string, File|string]}
|
|
179
|
+
*/ function normalizeArgs(name, value, filename) {
|
|
180
|
+
if (_instanceof(value, Blob)) {
|
|
181
|
+
filename = filename !== undefined ? String(filename + "") : typeof value.name === "string" ? value.name : "blob";
|
|
182
|
+
if (value.name !== filename || Object.prototype.toString.call(value) === "[object Blob]") {
|
|
183
|
+
value = new File([
|
|
184
|
+
value
|
|
185
|
+
], filename);
|
|
186
|
+
}
|
|
187
|
+
return [
|
|
188
|
+
String(name),
|
|
189
|
+
value
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
return [
|
|
193
|
+
String(name),
|
|
194
|
+
String(value)
|
|
195
|
+
];
|
|
196
|
+
};
|
|
197
|
+
var normalizeLinefeeds = // normalize line feeds for textarea
|
|
198
|
+
// https://html.spec.whatwg.org/multipage/form-elements.html#textarea-line-break-normalisation-transformation
|
|
199
|
+
function normalizeLinefeeds(value) {
|
|
200
|
+
return value.replace(/\r?\n|\r/g, "\r\n");
|
|
201
|
+
};
|
|
202
|
+
var each = /**
|
|
203
|
+
* @template T
|
|
204
|
+
* @param {ArrayLike<T>} arr
|
|
205
|
+
* @param {{ (elm: T): void; }} cb
|
|
206
|
+
*/ function each(arr, cb) {
|
|
207
|
+
for(var i = 0; i < arr.length; i++){
|
|
208
|
+
cb(arr[i]);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var global = typeof globalThis === "object" ? globalThis : typeof window === "object" ? window : typeof self === "object" ? self : void 0;
|
|
212
|
+
// keep a reference to native implementation
|
|
213
|
+
var _FormData = global.FormData;
|
|
214
|
+
// To be monkey patched
|
|
215
|
+
var _send = global.XMLHttpRequest && global.XMLHttpRequest.prototype.send;
|
|
216
|
+
var _fetch = global.Request && global.fetch;
|
|
217
|
+
var _sendBeacon = global.navigator && global.navigator.sendBeacon;
|
|
218
|
+
// Might be a worker thread...
|
|
219
|
+
var _match = global.Element && global.Element.prototype;
|
|
220
|
+
// Unable to patch Request/Response constructor correctly #109
|
|
221
|
+
// only way is to use ES6 class extend
|
|
222
|
+
// https://github.com/babel/babel/issues/1966
|
|
223
|
+
var stringTag = global.Symbol && Symbol.toStringTag;
|
|
224
|
+
// Add missing stringTags to blob and files
|
|
225
|
+
if (stringTag) {
|
|
226
|
+
if (!Blob.prototype[stringTag]) {
|
|
227
|
+
Blob.prototype[stringTag] = "Blob";
|
|
228
|
+
}
|
|
229
|
+
if ("File" in global && !File.prototype[stringTag]) {
|
|
230
|
+
File.prototype[stringTag] = "File";
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Fix so you can construct your own File
|
|
234
|
+
try {
|
|
235
|
+
new File([], "") // eslint-disable-line
|
|
236
|
+
;
|
|
237
|
+
} catch (a) {
|
|
238
|
+
global.File = function File1(b, d, c) {
|
|
239
|
+
var blob = new Blob(b, c || {});
|
|
240
|
+
var t = c && void 0 !== c.lastModified ? new Date(c.lastModified) : new Date();
|
|
241
|
+
Object.defineProperties(blob, {
|
|
242
|
+
name: {
|
|
243
|
+
value: d
|
|
244
|
+
},
|
|
245
|
+
lastModified: {
|
|
246
|
+
value: +t
|
|
247
|
+
},
|
|
248
|
+
toString: {
|
|
249
|
+
value: function value() {
|
|
250
|
+
return "[object File]";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
if (stringTag) {
|
|
255
|
+
Object.defineProperty(blob, stringTag, {
|
|
256
|
+
value: "File"
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return blob;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
var escape = function(str) {
|
|
263
|
+
return str.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* @implements {Iterable}
|
|
267
|
+
*/ var FormDataPolyfill = /*#__PURE__*/ function() {
|
|
268
|
+
"use strict";
|
|
269
|
+
function FormDataPolyfill(form) {
|
|
270
|
+
_classCallCheck(this, FormDataPolyfill);
|
|
271
|
+
/** @type {[string, string|File][]} */ this._data = [];
|
|
272
|
+
var _$self = this;
|
|
273
|
+
form && each(form.elements, function(/** @type {HTMLInputElement} */ elm) {
|
|
274
|
+
if (!elm.name || elm.disabled || elm.type === "submit" || elm.type === "button" || elm.matches("form fieldset[disabled] *")) return;
|
|
275
|
+
if (elm.type === "file") {
|
|
276
|
+
var files = elm.files && elm.files.length ? elm.files : [
|
|
277
|
+
new File([], "", {
|
|
278
|
+
type: "application/octet-stream"
|
|
279
|
+
})
|
|
280
|
+
] // #78
|
|
281
|
+
;
|
|
282
|
+
each(files, function(file) {
|
|
283
|
+
_$self.append(elm.name, file);
|
|
284
|
+
});
|
|
285
|
+
} else if (elm.type === "select-multiple" || elm.type === "select-one") {
|
|
286
|
+
each(elm.options, function(opt) {
|
|
287
|
+
!opt.disabled && opt.selected && _$self.append(elm.name, opt.value);
|
|
288
|
+
});
|
|
289
|
+
} else if (elm.type === "checkbox" || elm.type === "radio") {
|
|
290
|
+
if (elm.checked) _$self.append(elm.name, elm.value);
|
|
291
|
+
} else {
|
|
292
|
+
var value = elm.type === "textarea" ? normalizeLinefeeds(elm.value) : elm.value;
|
|
293
|
+
_$self.append(elm.name, value);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
_createClass(FormDataPolyfill, [
|
|
298
|
+
{
|
|
299
|
+
/**
|
|
300
|
+
* Append a field
|
|
301
|
+
*
|
|
302
|
+
* @param {string} name field name
|
|
303
|
+
* @param {string|Blob|File} value string / blob / file
|
|
304
|
+
* @param {string=} filename filename to use with blob
|
|
305
|
+
* @return {undefined}
|
|
306
|
+
*/ key: "append",
|
|
307
|
+
value: function append(name, value, filename) {
|
|
308
|
+
ensureArgs(arguments, 2);
|
|
309
|
+
this._data.push(normalizeArgs(name, value, filename));
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
/**
|
|
314
|
+
* Delete all fields values given name
|
|
315
|
+
*
|
|
316
|
+
* @param {string} name Field name
|
|
317
|
+
* @return {undefined}
|
|
318
|
+
*/ key: "delete",
|
|
319
|
+
value: function _delete(name) {
|
|
320
|
+
ensureArgs(arguments, 1);
|
|
321
|
+
var result = [];
|
|
322
|
+
name = String(name);
|
|
323
|
+
each(this._data, function(entry) {
|
|
324
|
+
entry[0] !== name && result.push(entry);
|
|
325
|
+
});
|
|
326
|
+
this._data = result;
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
key: "entries",
|
|
331
|
+
value: /**
|
|
332
|
+
* Iterate over all fields as [name, value]
|
|
333
|
+
*
|
|
334
|
+
* @return {Iterator}
|
|
335
|
+
*/ function entries() {
|
|
336
|
+
var i;
|
|
337
|
+
return __generator(this, function(_state) {
|
|
338
|
+
switch(_state.label){
|
|
339
|
+
case 0:
|
|
340
|
+
i = 0;
|
|
341
|
+
_state.label = 1;
|
|
342
|
+
case 1:
|
|
343
|
+
if (!(i < this._data.length)) return [
|
|
344
|
+
3,
|
|
345
|
+
4
|
|
346
|
+
];
|
|
347
|
+
return [
|
|
348
|
+
4,
|
|
349
|
+
this._data[i]
|
|
350
|
+
];
|
|
351
|
+
case 2:
|
|
352
|
+
_state.sent();
|
|
353
|
+
_state.label = 3;
|
|
354
|
+
case 3:
|
|
355
|
+
i++;
|
|
356
|
+
return [
|
|
357
|
+
3,
|
|
358
|
+
1
|
|
359
|
+
];
|
|
360
|
+
case 4:
|
|
361
|
+
return [
|
|
362
|
+
2
|
|
363
|
+
];
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
/**
|
|
370
|
+
* Iterate over all fields
|
|
371
|
+
*
|
|
372
|
+
* @param {Function} callback Executed for each item with parameters (value, name, thisArg)
|
|
373
|
+
* @param {Object=} thisArg `this` context for callback function
|
|
374
|
+
*/ key: "forEach",
|
|
375
|
+
value: function forEach(callback, thisArg) {
|
|
376
|
+
ensureArgs(arguments, 1);
|
|
377
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
378
|
+
try {
|
|
379
|
+
for(var _iterator = this[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
380
|
+
var _value = _slicedToArray(_step.value, 2), name = _value[0], value = _value[1];
|
|
381
|
+
callback.call(thisArg, value, name, this);
|
|
382
|
+
}
|
|
383
|
+
} catch (err) {
|
|
384
|
+
_didIteratorError = true;
|
|
385
|
+
_iteratorError = err;
|
|
386
|
+
} finally{
|
|
387
|
+
try {
|
|
388
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
389
|
+
_iterator.return();
|
|
390
|
+
}
|
|
391
|
+
} finally{
|
|
392
|
+
if (_didIteratorError) {
|
|
393
|
+
throw _iteratorError;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
/**
|
|
401
|
+
* Return first field value given name
|
|
402
|
+
* or null if non existent
|
|
403
|
+
*
|
|
404
|
+
* @param {string} name Field name
|
|
405
|
+
* @return {string|File|null} value Fields value
|
|
406
|
+
*/ key: "get",
|
|
407
|
+
value: function get(name) {
|
|
408
|
+
ensureArgs(arguments, 1);
|
|
409
|
+
var entries = this._data;
|
|
410
|
+
name = String(name);
|
|
411
|
+
for(var i = 0; i < entries.length; i++){
|
|
412
|
+
if (entries[i][0] === name) {
|
|
413
|
+
return entries[i][1];
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
/**
|
|
421
|
+
* Return all fields values given name
|
|
422
|
+
*
|
|
423
|
+
* @param {string} name Fields name
|
|
424
|
+
* @return {Array} [{String|File}]
|
|
425
|
+
*/ key: "getAll",
|
|
426
|
+
value: function getAll(name) {
|
|
427
|
+
ensureArgs(arguments, 1);
|
|
428
|
+
var result = [];
|
|
429
|
+
name = String(name);
|
|
430
|
+
each(this._data, function(data) {
|
|
431
|
+
data[0] === name && result.push(data[1]);
|
|
432
|
+
});
|
|
433
|
+
return result;
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
/**
|
|
438
|
+
* Check for field name existence
|
|
439
|
+
*
|
|
440
|
+
* @param {string} name Field name
|
|
441
|
+
* @return {boolean}
|
|
442
|
+
*/ key: "has",
|
|
443
|
+
value: function has(name) {
|
|
444
|
+
ensureArgs(arguments, 1);
|
|
445
|
+
name = String(name);
|
|
446
|
+
for(var i = 0; i < this._data.length; i++){
|
|
447
|
+
if (this._data[i][0] === name) {
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
key: "keys",
|
|
456
|
+
value: /**
|
|
457
|
+
* Iterate over all fields name
|
|
458
|
+
*
|
|
459
|
+
* @return {Iterator}
|
|
460
|
+
*/ function keys() {
|
|
461
|
+
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, name, err;
|
|
462
|
+
return __generator(this, function(_state) {
|
|
463
|
+
switch(_state.label){
|
|
464
|
+
case 0:
|
|
465
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
466
|
+
_state.label = 1;
|
|
467
|
+
case 1:
|
|
468
|
+
_state.trys.push([
|
|
469
|
+
1,
|
|
470
|
+
6,
|
|
471
|
+
7,
|
|
472
|
+
8
|
|
473
|
+
]);
|
|
474
|
+
_iterator = this[Symbol.iterator]();
|
|
475
|
+
_state.label = 2;
|
|
476
|
+
case 2:
|
|
477
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
478
|
+
3,
|
|
479
|
+
5
|
|
480
|
+
];
|
|
481
|
+
_value = _slicedToArray(_step.value, 1), name = _value[0];
|
|
482
|
+
return [
|
|
483
|
+
4,
|
|
484
|
+
name
|
|
485
|
+
];
|
|
486
|
+
case 3:
|
|
487
|
+
_state.sent();
|
|
488
|
+
_state.label = 4;
|
|
489
|
+
case 4:
|
|
490
|
+
_iteratorNormalCompletion = true;
|
|
491
|
+
return [
|
|
492
|
+
3,
|
|
493
|
+
2
|
|
494
|
+
];
|
|
495
|
+
case 5:
|
|
496
|
+
return [
|
|
497
|
+
3,
|
|
498
|
+
8
|
|
499
|
+
];
|
|
500
|
+
case 6:
|
|
501
|
+
err = _state.sent();
|
|
502
|
+
_didIteratorError = true;
|
|
503
|
+
_iteratorError = err;
|
|
504
|
+
return [
|
|
505
|
+
3,
|
|
506
|
+
8
|
|
507
|
+
];
|
|
508
|
+
case 7:
|
|
509
|
+
try {
|
|
510
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
511
|
+
_iterator.return();
|
|
512
|
+
}
|
|
513
|
+
} finally{
|
|
514
|
+
if (_didIteratorError) {
|
|
515
|
+
throw _iteratorError;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return [
|
|
519
|
+
7
|
|
520
|
+
];
|
|
521
|
+
case 8:
|
|
522
|
+
return [
|
|
523
|
+
2
|
|
524
|
+
];
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
/**
|
|
531
|
+
* Overwrite all values given name
|
|
532
|
+
*
|
|
533
|
+
* @param {string} name Filed name
|
|
534
|
+
* @param {string} value Field value
|
|
535
|
+
* @param {string=} filename Filename (optional)
|
|
536
|
+
*/ key: "set",
|
|
537
|
+
value: function set(name, value, filename) {
|
|
538
|
+
ensureArgs(arguments, 2);
|
|
539
|
+
name = String(name);
|
|
540
|
+
/** @type {[string, string|File][]} */ var result = [];
|
|
541
|
+
var args = normalizeArgs(name, value, filename);
|
|
542
|
+
var replace = true;
|
|
543
|
+
// - replace the first occurrence with same name
|
|
544
|
+
// - discards the remaining with same name
|
|
545
|
+
// - while keeping the same order items where added
|
|
546
|
+
each(this._data, function(data) {
|
|
547
|
+
data[0] === name ? replace && (replace = !result.push(args)) : result.push(data);
|
|
548
|
+
});
|
|
549
|
+
replace && result.push(args);
|
|
550
|
+
this._data = result;
|
|
551
|
+
}
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
key: "values",
|
|
555
|
+
value: /**
|
|
556
|
+
* Iterate over all fields
|
|
557
|
+
*
|
|
558
|
+
* @return {Iterator}
|
|
559
|
+
*/ function values() {
|
|
560
|
+
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, value, err;
|
|
561
|
+
return __generator(this, function(_state) {
|
|
562
|
+
switch(_state.label){
|
|
563
|
+
case 0:
|
|
564
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
565
|
+
_state.label = 1;
|
|
566
|
+
case 1:
|
|
567
|
+
_state.trys.push([
|
|
568
|
+
1,
|
|
569
|
+
6,
|
|
570
|
+
7,
|
|
571
|
+
8
|
|
572
|
+
]);
|
|
573
|
+
_iterator = this[Symbol.iterator]();
|
|
574
|
+
_state.label = 2;
|
|
575
|
+
case 2:
|
|
576
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
577
|
+
3,
|
|
578
|
+
5
|
|
579
|
+
];
|
|
580
|
+
_value = _slicedToArray(_step.value, 2), value = _value[1];
|
|
581
|
+
return [
|
|
582
|
+
4,
|
|
583
|
+
value
|
|
584
|
+
];
|
|
585
|
+
case 3:
|
|
586
|
+
_state.sent();
|
|
587
|
+
_state.label = 4;
|
|
588
|
+
case 4:
|
|
589
|
+
_iteratorNormalCompletion = true;
|
|
590
|
+
return [
|
|
591
|
+
3,
|
|
592
|
+
2
|
|
593
|
+
];
|
|
594
|
+
case 5:
|
|
595
|
+
return [
|
|
596
|
+
3,
|
|
597
|
+
8
|
|
598
|
+
];
|
|
599
|
+
case 6:
|
|
600
|
+
err = _state.sent();
|
|
601
|
+
_didIteratorError = true;
|
|
602
|
+
_iteratorError = err;
|
|
603
|
+
return [
|
|
604
|
+
3,
|
|
605
|
+
8
|
|
606
|
+
];
|
|
607
|
+
case 7:
|
|
608
|
+
try {
|
|
609
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
610
|
+
_iterator.return();
|
|
611
|
+
}
|
|
612
|
+
} finally{
|
|
613
|
+
if (_didIteratorError) {
|
|
614
|
+
throw _iteratorError;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return [
|
|
618
|
+
7
|
|
619
|
+
];
|
|
620
|
+
case 8:
|
|
621
|
+
return [
|
|
622
|
+
2
|
|
623
|
+
];
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
/**
|
|
630
|
+
* Return a native (perhaps degraded) FormData with only a `append` method
|
|
631
|
+
* Can throw if it's not supported
|
|
632
|
+
*
|
|
633
|
+
* @return {FormData}
|
|
634
|
+
*/ key: "_asNative",
|
|
635
|
+
value: function value() {
|
|
636
|
+
var fd = new _FormData();
|
|
637
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
638
|
+
try {
|
|
639
|
+
for(var _iterator = this[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
640
|
+
var _value = _slicedToArray(_step.value, 2), name = _value[0], value1 = _value[1];
|
|
641
|
+
fd.append(name, value1);
|
|
642
|
+
}
|
|
643
|
+
} catch (err) {
|
|
644
|
+
_didIteratorError = true;
|
|
645
|
+
_iteratorError = err;
|
|
646
|
+
} finally{
|
|
647
|
+
try {
|
|
648
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
649
|
+
_iterator.return();
|
|
650
|
+
}
|
|
651
|
+
} finally{
|
|
652
|
+
if (_didIteratorError) {
|
|
653
|
+
throw _iteratorError;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return fd;
|
|
658
|
+
}
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
/**
|
|
662
|
+
* [_blob description]
|
|
663
|
+
*
|
|
664
|
+
* @return {Blob} [description]
|
|
665
|
+
*/ key: "_blob",
|
|
666
|
+
value: function value() {
|
|
667
|
+
var boundary = "----formdata-polyfill-" + Math.random(), chunks = [], p = "--".concat(boundary, '\r\nContent-Disposition: form-data; name="');
|
|
668
|
+
this.forEach(function(value, name) {
|
|
669
|
+
return typeof value == "string" ? chunks.push(p + escape(normalizeLinefeeds(name)) + '"\r\n\r\n'.concat(normalizeLinefeeds(value), "\r\n")) : chunks.push(p + escape(normalizeLinefeeds(name)) + '"; filename="'.concat(escape(value.name), '"\r\nContent-Type: ').concat(value.type || "application/octet-stream", "\r\n\r\n"), value, "\r\n");
|
|
670
|
+
});
|
|
671
|
+
chunks.push("--".concat(boundary, "--"));
|
|
672
|
+
return new Blob(chunks, {
|
|
673
|
+
type: "multipart/form-data; boundary=" + boundary
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
/**
|
|
679
|
+
* The class itself is iterable
|
|
680
|
+
* alias for formdata.entries()
|
|
681
|
+
*
|
|
682
|
+
* @return {Iterator}
|
|
683
|
+
*/ key: Symbol.iterator,
|
|
684
|
+
value: function value() {
|
|
685
|
+
return this.entries();
|
|
686
|
+
}
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
/**
|
|
690
|
+
* Create the default string description.
|
|
691
|
+
*
|
|
692
|
+
* @return {string} [object FormData]
|
|
693
|
+
*/ key: "toString",
|
|
694
|
+
value: function toString() {
|
|
695
|
+
return "[object FormData]";
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
]);
|
|
699
|
+
return FormDataPolyfill;
|
|
700
|
+
}();
|
|
701
|
+
if (_match && !_match.matches) {
|
|
702
|
+
_match.matches = _match.matchesSelector || _match.mozMatchesSelector || _match.msMatchesSelector || _match.oMatchesSelector || _match.webkitMatchesSelector || function(s) {
|
|
703
|
+
var matches = (this.document || this.ownerDocument).querySelectorAll(s);
|
|
704
|
+
var i = matches.length;
|
|
705
|
+
while(--i >= 0 && matches.item(i) !== this){}
|
|
706
|
+
return i > -1;
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
if (stringTag) {
|
|
710
|
+
/**
|
|
711
|
+
* Create the default string description.
|
|
712
|
+
* It is accessed internally by the Object.prototype.toString().
|
|
713
|
+
*/ FormDataPolyfill.prototype[stringTag] = "FormData";
|
|
714
|
+
}
|
|
715
|
+
// Patch xhr's send method to call _blob transparently
|
|
716
|
+
if (_send) {
|
|
717
|
+
var setRequestHeader = global.XMLHttpRequest.prototype.setRequestHeader;
|
|
718
|
+
global.XMLHttpRequest.prototype.setRequestHeader = function(name, value) {
|
|
719
|
+
setRequestHeader.call(this, name, value);
|
|
720
|
+
if (name.toLowerCase() === "content-type") this._hasContentType = true;
|
|
721
|
+
};
|
|
722
|
+
global.XMLHttpRequest.prototype.send = function(data) {
|
|
723
|
+
// need to patch send b/c old IE don't send blob's type (#44)
|
|
724
|
+
if (_instanceof(data, FormDataPolyfill)) {
|
|
725
|
+
var blob = data["_blob"]();
|
|
726
|
+
if (!this._hasContentType) this.setRequestHeader("Content-Type", blob.type);
|
|
727
|
+
_send.call(this, blob);
|
|
728
|
+
} else {
|
|
729
|
+
_send.call(this, data);
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
// Patch fetch's function to call _blob transparently
|
|
734
|
+
if (_fetch) {
|
|
735
|
+
global.fetch = function(input, init) {
|
|
736
|
+
if (init && init.body && _instanceof(init.body, FormDataPolyfill)) {
|
|
737
|
+
init.body = init.body["_blob"]();
|
|
738
|
+
}
|
|
739
|
+
return _fetch.call(this, input, init);
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
// Patch navigator.sendBeacon to use native FormData
|
|
743
|
+
if (_sendBeacon) {
|
|
744
|
+
global.navigator.sendBeacon = function(url, data) {
|
|
745
|
+
if (_instanceof(data, FormDataPolyfill)) {
|
|
746
|
+
data = data["_asNative"]();
|
|
747
|
+
}
|
|
748
|
+
return _sendBeacon.call(this, url, data);
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
global["FormData"] = FormDataPolyfill;
|
|
752
|
+
}
|