@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.
@@ -0,0 +1,93 @@
1
+ /*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "formDataToBlob", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return formDataToBlob;
9
+ }
10
+ });
11
+ function _arrayLikeToArray(arr, len) {
12
+ if (len == null || len > arr.length) len = arr.length;
13
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
14
+ return arr2;
15
+ }
16
+ function _arrayWithHoles(arr) {
17
+ if (Array.isArray(arr)) return arr;
18
+ }
19
+ function _iterableToArrayLimit(arr, i) {
20
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
21
+ if (_i == null) return;
22
+ var _arr = [];
23
+ var _n = true;
24
+ var _d = false;
25
+ var _s, _e;
26
+ try {
27
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
28
+ _arr.push(_s.value);
29
+ if (i && _arr.length === i) break;
30
+ }
31
+ } catch (err) {
32
+ _d = true;
33
+ _e = err;
34
+ } finally{
35
+ try {
36
+ if (!_n && _i["return"] != null) _i["return"]();
37
+ } finally{
38
+ if (_d) throw _e;
39
+ }
40
+ }
41
+ return _arr;
42
+ }
43
+ function _nonIterableRest() {
44
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
45
+ }
46
+ function _slicedToArray(arr, i) {
47
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
48
+ }
49
+ function _unsupportedIterableToArray(o, minLen) {
50
+ if (!o) return;
51
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
52
+ var n = Object.prototype.toString.call(o).slice(8, -1);
53
+ if (n === "Object" && o.constructor) n = o.constructor.name;
54
+ if (n === "Map" || n === "Set") return Array.from(n);
55
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
56
+ }
57
+ var escape = function(str, filename) {
58
+ return (filename ? str : str.replace(/\r?\n|\r/g, "\r\n")).replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
59
+ };
60
+ function formDataToBlob(formData) {
61
+ var BlobClass = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Blob;
62
+ var boundary = "----formdata-polyfill-" + Math.random();
63
+ var chunks = [];
64
+ var prefix = "--".concat(boundary, '\r\nContent-Disposition: form-data; name="');
65
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
66
+ try {
67
+ for(var _iterator = formData[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
68
+ var _value = _slicedToArray(_step.value, 2), name = _value[0], value = _value[1];
69
+ if (typeof value === "string") {
70
+ chunks.push(prefix + escape(name) + '"\r\n\r\n'.concat(value.replace(RegExp("\\r(?!\\n)|(?<!\\r)\\n", "g"), "\r\n"), "\r\n"));
71
+ } else {
72
+ chunks.push(prefix + escape(name) + '"; filename="'.concat(escape(value.name, 1), '"\r\n') + "Content-Type: ".concat(value.type || "application/octet-stream", "\r\n\r\n"), value, "\r\n");
73
+ }
74
+ }
75
+ } catch (err) {
76
+ _didIteratorError = true;
77
+ _iteratorError = err;
78
+ } finally{
79
+ try {
80
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
81
+ _iterator.return();
82
+ }
83
+ } finally{
84
+ if (_didIteratorError) {
85
+ throw _iteratorError;
86
+ }
87
+ }
88
+ }
89
+ chunks.push("--".concat(boundary, "--"));
90
+ return new BlobClass(chunks, {
91
+ type: "multipart/form-data; boundary=" + boundary
92
+ });
93
+ }
@@ -0,0 +1,507 @@
1
+ "use strict";
2
+ function _instanceof(left, right) {
3
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
4
+ return !!right[Symbol.hasInstance](left);
5
+ } else {
6
+ return left instanceof right;
7
+ }
8
+ }
9
+ ;
10
+ (function() {
11
+ var l = function l(a) {
12
+ var b = 0;
13
+ return function() {
14
+ return b < a.length ? {
15
+ done: !1,
16
+ value: a[b++]
17
+ } : {
18
+ done: !0
19
+ };
20
+ };
21
+ };
22
+ var n = function n(a) {
23
+ a = [
24
+ "object" == typeof globalThis && globalThis,
25
+ a,
26
+ "object" == typeof window && window,
27
+ "object" == typeof self && self,
28
+ "object" == typeof global && global
29
+ ];
30
+ for(var b = 0; b < a.length; ++b){
31
+ var c = a[b];
32
+ if (c && c.Math == Math) return c;
33
+ }
34
+ throw Error("Cannot find global object");
35
+ };
36
+ var r = function r(a, b) {
37
+ if (b) a: {
38
+ var c = q;
39
+ a = a.split(".");
40
+ for(var d = 0; d < a.length - 1; d++){
41
+ var e = a[d];
42
+ if (!(e in c)) break a;
43
+ c = c[e];
44
+ }
45
+ a = a[a.length - 1];
46
+ d = c[a];
47
+ b = b(d);
48
+ b != d && null != b && m(c, a, {
49
+ configurable: !0,
50
+ writable: !0,
51
+ value: b
52
+ });
53
+ }
54
+ };
55
+ var u = function u(a) {
56
+ a = {
57
+ next: a
58
+ };
59
+ a[Symbol.iterator] = function() {
60
+ return this;
61
+ };
62
+ return a;
63
+ };
64
+ var v = function v(a) {
65
+ var b = "undefined" != typeof Symbol && Symbol.iterator && a[Symbol.iterator];
66
+ return b ? b.call(a) : {
67
+ next: l(a)
68
+ };
69
+ };
70
+ var C = function C() {
71
+ this.m = !1;
72
+ this.j = null;
73
+ this.v = void 0;
74
+ this.h = 1;
75
+ this.u = this.C = 0;
76
+ this.l = null;
77
+ };
78
+ var D = function D(a) {
79
+ if (a.m) throw new TypeError("Generator is already running");
80
+ a.m = !0;
81
+ };
82
+ var E = function E(a, b) {
83
+ a.h = 3;
84
+ return {
85
+ value: b
86
+ };
87
+ };
88
+ var F = function F(a) {
89
+ this.g = new C;
90
+ this.G = a;
91
+ };
92
+ var I = function I(a, b) {
93
+ D(a.g);
94
+ var c = a.g.j;
95
+ if (c) return G(a, "return" in c ? c["return"] : function(d) {
96
+ return {
97
+ value: d,
98
+ done: !0
99
+ };
100
+ }, b, a.g.return);
101
+ a.g.return(b);
102
+ return H(a);
103
+ };
104
+ var G = function G(a, b, c, d) {
105
+ try {
106
+ var e = b.call(a.g.j, c);
107
+ if (!_instanceof(e, Object)) throw new TypeError("Iterator result " + e + " is not an object");
108
+ if (!e.done) return a.g.m = !1, e;
109
+ var f = e.value;
110
+ } catch (g) {
111
+ return a.g.j = null, a.g.s(g), H(a);
112
+ }
113
+ a.g.j = null;
114
+ d.call(a.g, f);
115
+ return H(a);
116
+ };
117
+ var H = function H(a) {
118
+ for(; a.g.h;)try {
119
+ var b = a.G(a.g);
120
+ if (b) return a.g.m = !1, {
121
+ value: b.value,
122
+ done: !1
123
+ };
124
+ } catch (c) {
125
+ a.g.v = void 0, a.g.s(c);
126
+ }
127
+ a.g.m = !1;
128
+ if (a.g.l) {
129
+ b = a.g.l;
130
+ a.g.l = null;
131
+ if (b.F) throw b.D;
132
+ return {
133
+ value: b.return,
134
+ done: !0
135
+ };
136
+ }
137
+ return {
138
+ value: void 0,
139
+ done: !0
140
+ };
141
+ };
142
+ var J = function J(a) {
143
+ this.next = function(b) {
144
+ return a.o(b);
145
+ };
146
+ this.throw = function(b) {
147
+ return a.s(b);
148
+ };
149
+ this.return = function(b) {
150
+ return I(a, b);
151
+ };
152
+ this[Symbol.iterator] = function() {
153
+ return this;
154
+ };
155
+ };
156
+ var K = function K(a, b) {
157
+ b = new J(new F(b));
158
+ B && a.prototype && B(b, a.prototype);
159
+ return b;
160
+ };
161
+ var L = function L(a, b) {
162
+ _instanceof(a, String) && (a += "");
163
+ var c = 0, d = !1, e = {
164
+ next: function next() {
165
+ if (!d && c < a.length) {
166
+ var f = c++;
167
+ return {
168
+ value: b(f, a[f]),
169
+ done: !1
170
+ };
171
+ }
172
+ d = !0;
173
+ return {
174
+ done: !0,
175
+ value: void 0
176
+ };
177
+ }
178
+ };
179
+ e[Symbol.iterator] = function() {
180
+ return e;
181
+ };
182
+ return e;
183
+ };
184
+ var h;
185
+ var m = "function" == typeof Object.defineProperties ? Object.defineProperty : function m(a, b, c) {
186
+ if (a == Array.prototype || a == Object.prototype) return a;
187
+ a[b] = c.value;
188
+ return a;
189
+ };
190
+ var q = n(this);
191
+ r("Symbol", function(a) {
192
+ var c = function c(f, g) {
193
+ this.A = f;
194
+ m(this, "description", {
195
+ configurable: !0,
196
+ writable: !0,
197
+ value: g
198
+ });
199
+ };
200
+ function b(f) {
201
+ if (_instanceof(this, b)) throw new TypeError("Symbol is not a constructor");
202
+ return new c(d + (f || "") + "_" + e++, f);
203
+ }
204
+ if (a) return a;
205
+ c.prototype.toString = function() {
206
+ return this.A;
207
+ };
208
+ var d = "jscomp_symbol_" + (1E9 * Math.random() >>> 0) + "_", e = 0;
209
+ return b;
210
+ });
211
+ r("Symbol.iterator", function(a) {
212
+ if (a) return a;
213
+ a = Symbol("Symbol.iterator");
214
+ for(var b = "Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "), c = 0; c < b.length; c++){
215
+ var d = q[b[c]];
216
+ "function" === typeof d && "function" != typeof d.prototype[a] && m(d.prototype, a, {
217
+ configurable: !0,
218
+ writable: !0,
219
+ value: function value() {
220
+ return u(l(this));
221
+ }
222
+ });
223
+ }
224
+ return a;
225
+ });
226
+ var w;
227
+ if ("function" == typeof Object.setPrototypeOf) w = Object.setPrototypeOf;
228
+ else {
229
+ var y;
230
+ a: {
231
+ var z = {
232
+ a: !0
233
+ }, A = {};
234
+ try {
235
+ A.__proto__ = z;
236
+ y = A.a;
237
+ break a;
238
+ } catch (a) {}
239
+ y = !1;
240
+ }
241
+ w = y ? function w(a, b) {
242
+ a.__proto__ = b;
243
+ if (a.__proto__ !== b) throw new TypeError(a + " is not extensible");
244
+ return a;
245
+ } : null;
246
+ }
247
+ var B = w;
248
+ C.prototype.o = function(a) {
249
+ this.v = a;
250
+ };
251
+ C.prototype.s = function(a) {
252
+ this.l = {
253
+ D: a,
254
+ F: !0
255
+ };
256
+ this.h = this.C || this.u;
257
+ };
258
+ C.prototype.return = function(a) {
259
+ this.l = {
260
+ return: a
261
+ };
262
+ this.h = this.u;
263
+ };
264
+ F.prototype.o = function(a) {
265
+ D(this.g);
266
+ if (this.g.j) return G(this, this.g.j.next, a, this.g.o);
267
+ this.g.o(a);
268
+ return H(this);
269
+ };
270
+ F.prototype.s = function(a) {
271
+ D(this.g);
272
+ if (this.g.j) return G(this, this.g.j["throw"], a, this.g.o);
273
+ this.g.s(a);
274
+ return H(this);
275
+ };
276
+ r("Array.prototype.entries", function(a) {
277
+ return a ? a : function() {
278
+ return L(this, function(b, c) {
279
+ return [
280
+ b,
281
+ c
282
+ ];
283
+ });
284
+ };
285
+ });
286
+ if ("undefined" !== typeof Blob && ("undefined" === typeof FormData || !FormData.prototype.keys)) {
287
+ var M = function M(a, b) {
288
+ for(var c = 0; c < a.length; c++)b(a[c]);
289
+ }, N = function N(a) {
290
+ return a.replace(/\r?\n|\r/g, "\r\n");
291
+ }, O = function O(a, b, c) {
292
+ if (_instanceof(b, Blob)) {
293
+ c = void 0 !== c ? String(c + "") : "string" === typeof b.name ? b.name : "blob";
294
+ if (b.name !== c || "[object Blob]" === Object.prototype.toString.call(b)) b = new File([
295
+ b
296
+ ], c);
297
+ return [
298
+ String(a),
299
+ b
300
+ ];
301
+ }
302
+ return [
303
+ String(a),
304
+ String(b)
305
+ ];
306
+ }, P = function P(a, b) {
307
+ if (a.length < b) throw new TypeError(b + " argument required, but only " + a.length + " present.");
308
+ }, Q = "object" === typeof globalThis ? globalThis : "object" === typeof window ? window : "object" === typeof self ? self : this, R = Q.FormData, S = Q.XMLHttpRequest && Q.XMLHttpRequest.prototype.send, T = Q.Request && Q.fetch, U = Q.navigator && Q.navigator.sendBeacon, V = Q.Element && Q.Element.prototype, W = Q.Symbol && Symbol.toStringTag;
309
+ W && (Blob.prototype[W] || (Blob.prototype[W] = "Blob"), "File" in Q && !File.prototype[W] && (File.prototype[W] = "File"));
310
+ try {
311
+ new File([], "");
312
+ } catch (a1) {
313
+ Q.File = function(b, c, d) {
314
+ b = new Blob(b, d || {});
315
+ Object.defineProperties(b, {
316
+ name: {
317
+ value: c
318
+ },
319
+ lastModified: {
320
+ value: +(d && void 0 !== d.lastModified ? new Date(d.lastModified) : new Date)
321
+ },
322
+ toString: {
323
+ value: function value() {
324
+ return "[object File]";
325
+ }
326
+ }
327
+ });
328
+ W && Object.defineProperty(b, W, {
329
+ value: "File"
330
+ });
331
+ return b;
332
+ };
333
+ }
334
+ var escape = function escape(a) {
335
+ return a.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
336
+ }, X = function X(a) {
337
+ this.i = [];
338
+ var b = this;
339
+ a && M(a.elements, function(c) {
340
+ if (c.name && !c.disabled && "submit" !== c.type && "button" !== c.type && !c.matches("form fieldset[disabled] *")) if ("file" === c.type) {
341
+ var d = c.files && c.files.length ? c.files : [
342
+ new File([], "", {
343
+ type: "application/octet-stream"
344
+ })
345
+ ];
346
+ M(d, function(e) {
347
+ b.append(c.name, e);
348
+ });
349
+ } else "select-multiple" === c.type || "select-one" === c.type ? M(c.options, function(e) {
350
+ !e.disabled && e.selected && b.append(c.name, e.value);
351
+ }) : "checkbox" === c.type || "radio" === c.type ? c.checked && b.append(c.name, c.value) : (d = "textarea" === c.type ? N(c.value) : c.value, b.append(c.name, d));
352
+ });
353
+ };
354
+ h = X.prototype;
355
+ h.append = function(a, b, c) {
356
+ P(arguments, 2);
357
+ this.i.push(O(a, b, c));
358
+ };
359
+ h.delete = function(a) {
360
+ P(arguments, 1);
361
+ var b = [];
362
+ a = String(a);
363
+ M(this.i, function(c) {
364
+ c[0] !== a && b.push(c);
365
+ });
366
+ this.i = b;
367
+ };
368
+ h.entries = function b() {
369
+ var c, d = this;
370
+ return K(b, function(e) {
371
+ 1 == e.h && (c = 0);
372
+ if (3 != e.h) return c < d.i.length ? e = E(e, d.i[c]) : (e.h = 0, e = void 0), e;
373
+ c++;
374
+ e.h = 2;
375
+ });
376
+ };
377
+ h.forEach = function(b, c) {
378
+ P(arguments, 1);
379
+ for(var d = v(this), e = d.next(); !e.done; e = d.next()){
380
+ var f = v(e.value);
381
+ e = f.next().value;
382
+ f = f.next().value;
383
+ b.call(c, f, e, this);
384
+ }
385
+ };
386
+ h.get = function(b) {
387
+ P(arguments, 1);
388
+ var c = this.i;
389
+ b = String(b);
390
+ for(var d = 0; d < c.length; d++)if (c[d][0] === b) return c[d][1];
391
+ return null;
392
+ };
393
+ h.getAll = function(b) {
394
+ P(arguments, 1);
395
+ var c = [];
396
+ b = String(b);
397
+ M(this.i, function(d) {
398
+ d[0] === b && c.push(d[1]);
399
+ });
400
+ return c;
401
+ };
402
+ h.has = function(b) {
403
+ P(arguments, 1);
404
+ b = String(b);
405
+ for(var c = 0; c < this.i.length; c++)if (this.i[c][0] === b) return !0;
406
+ return !1;
407
+ };
408
+ h.keys = function c() {
409
+ var d = this, e, f, g, k, p;
410
+ return K(c, function(t) {
411
+ 1 == t.h && (e = v(d), f = e.next());
412
+ if (3 != t.h) {
413
+ if (f.done) {
414
+ t.h = 0;
415
+ return;
416
+ }
417
+ g = f.value;
418
+ k = v(g);
419
+ p = k.next().value;
420
+ return E(t, p);
421
+ }
422
+ f = e.next();
423
+ t.h = 2;
424
+ });
425
+ };
426
+ h.set = function(c, d, e) {
427
+ P(arguments, 2);
428
+ c = String(c);
429
+ var f = [], g = O(c, d, e), k = !0;
430
+ M(this.i, function(p) {
431
+ p[0] === c ? k && (k = !f.push(g)) : f.push(p);
432
+ });
433
+ k && f.push(g);
434
+ this.i = f;
435
+ };
436
+ h.values = function d() {
437
+ var e = this, f, g, k, p, t;
438
+ return K(d, function(x) {
439
+ 1 == x.h && (f = v(e), g = f.next());
440
+ if (3 != x.h) {
441
+ if (g.done) {
442
+ x.h = 0;
443
+ return;
444
+ }
445
+ k = g.value;
446
+ p = v(k);
447
+ p.next();
448
+ t = p.next().value;
449
+ return E(x, t);
450
+ }
451
+ g = f.next();
452
+ x.h = 2;
453
+ });
454
+ };
455
+ X.prototype._asNative = function() {
456
+ for(var d = new R, e = v(this), f = e.next(); !f.done; f = e.next()){
457
+ var g = v(f.value);
458
+ f = g.next().value;
459
+ g = g.next().value;
460
+ d.append(f, g);
461
+ }
462
+ return d;
463
+ };
464
+ X.prototype._blob = function() {
465
+ var d = "----formdata-polyfill-" + Math.random(), e = [], f = "--" + d + '\r\nContent-Disposition: form-data; name="';
466
+ this.forEach(function(g, k) {
467
+ return "string" == typeof g ? e.push(f + escape(N(k)) + ('"\r\n\r\n' + N(g) + "\r\n")) : e.push(f + escape(N(k)) + ('"; filename="' + escape(g.name) + '"\r\nContent-Type: ' + (g.type || "application/octet-stream") + "\r\n\r\n"), g, "\r\n");
468
+ });
469
+ e.push("--" + d + "--");
470
+ return new Blob(e, {
471
+ type: "multipart/form-data; boundary=" + d
472
+ });
473
+ };
474
+ X.prototype[Symbol.iterator] = function() {
475
+ return this.entries();
476
+ };
477
+ X.prototype.toString = function() {
478
+ return "[object FormData]";
479
+ };
480
+ V && !V.matches && (V.matches = V.matchesSelector || V.mozMatchesSelector || V.msMatchesSelector || V.oMatchesSelector || V.webkitMatchesSelector || function(d) {
481
+ d = (this.document || this.ownerDocument).querySelectorAll(d);
482
+ for(var e = d.length; 0 <= --e && d.item(e) !== this;);
483
+ return -1 < e;
484
+ });
485
+ W && (X.prototype[W] = "FormData");
486
+ if (S) {
487
+ var Y = Q.XMLHttpRequest.prototype.setRequestHeader;
488
+ Q.XMLHttpRequest.prototype.setRequestHeader = function(d, e) {
489
+ Y.call(this, d, e);
490
+ "content-type" === d.toLowerCase() && (this.B = !0);
491
+ };
492
+ Q.XMLHttpRequest.prototype.send = function(d) {
493
+ _instanceof(d, X) ? (d = d._blob(), this.B || this.setRequestHeader("Content-Type", d.type), S.call(this, d)) : S.call(this, d);
494
+ };
495
+ }
496
+ T && (Q.fetch = function(d, e) {
497
+ e && e.body && _instanceof(e.body, X) && (e.body = e.body._blob());
498
+ return T.call(this, d, e);
499
+ });
500
+ U && (Q.navigator.sendBeacon = function(d, e) {
501
+ _instanceof(e, X) && (e = e._asNative());
502
+ return U.call(this, d, e);
503
+ });
504
+ Q.FormData = X;
505
+ }
506
+ ;
507
+ })();
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@common.js/formdata-polyfill",
3
+ "version": "4.0.10",
4
+ "description": "formdata-polyfill package exported as CommonJS modules",
5
+ "type": "commonjs",
6
+ "main": "formdata.min.js",
7
+ "scripts": {
8
+ "build": "node build.js",
9
+ "test": "node test/test-esm.js",
10
+ "test-wpt": "node --experimental-loader ./test/http-loader.js ./test/test-wpt-in-node.js",
11
+ "test-polyfill": "php -S localhost:4445 & open http://localhost:4445/test/test-polyfill.html"
12
+ },
13
+ "repository": "etienne-martin/common.js",
14
+ "files": [
15
+ "esm.min.js",
16
+ "esm.min.d.ts",
17
+ "FormData.js",
18
+ "formdata-to-blob.js",
19
+ "formdata.min.js",
20
+ "README.md"
21
+ ],
22
+ "engines": {
23
+ "node": ">=12.20.0"
24
+ },
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/jimmywarting/FormData/issues"
28
+ },
29
+ "homepage": "https://github.com/etienne-martin/common.js#readme",
30
+ "dependencies": {
31
+ "@common.js/fetch-blob": "^3.1.2"
32
+ },
33
+ "devDependencies": {
34
+ "@types/google-closure-compiler": "^0.0.19",
35
+ "@types/node": "^16.7.10",
36
+ "google-closure-compiler": "^20210808.0.0"
37
+ }
38
+ }