mphttpx 1.2.0-beta.1 → 1.2.0-beta.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.
Files changed (58) hide show
  1. package/dist/cjs/AbortControllerP.js +31 -0
  2. package/dist/cjs/AbortSignalP.js +126 -0
  3. package/dist/cjs/BlobP.js +131 -0
  4. package/dist/cjs/BodyImpl.js +142 -0
  5. package/dist/cjs/CloseEventP.js +38 -0
  6. package/dist/cjs/CustomEventP.js +35 -0
  7. package/dist/cjs/EventP.js +173 -0
  8. package/dist/cjs/EventTargetP.js +176 -0
  9. package/dist/cjs/FileP.js +36 -0
  10. package/dist/cjs/FileReaderP.js +151 -0
  11. package/dist/cjs/FormDataP.js +250 -0
  12. package/dist/cjs/HeadersP.js +176 -0
  13. package/dist/cjs/MessageEventP.js +64 -0
  14. package/dist/cjs/ProgressEventP.js +69 -0
  15. package/dist/cjs/RequestP.js +158 -0
  16. package/dist/cjs/ResponseP.js +102 -0
  17. package/dist/cjs/TextDecoderP.js +186 -0
  18. package/dist/cjs/TextEncoderP.js +122 -0
  19. package/dist/cjs/URLSearchParamsP.js +230 -0
  20. package/dist/cjs/WebSocketP.js +238 -0
  21. package/dist/cjs/XMLHttpRequestP.js +567 -0
  22. package/dist/cjs/convertor.js +83 -0
  23. package/dist/cjs/fetchP.js +115 -0
  24. package/dist/cjs/index.js +80 -0
  25. package/dist/cjs/isPolyfill.js +56 -0
  26. package/dist/cjs/platform.js +33 -0
  27. package/dist/esm/AbortControllerP.js +28 -0
  28. package/dist/esm/AbortSignalP.js +121 -0
  29. package/dist/esm/BlobP.js +124 -0
  30. package/dist/esm/BodyImpl.js +137 -0
  31. package/dist/esm/CloseEventP.js +35 -0
  32. package/dist/esm/CustomEventP.js +32 -0
  33. package/dist/esm/EventP.js +165 -0
  34. package/dist/esm/EventTargetP.js +168 -0
  35. package/dist/esm/FileP.js +33 -0
  36. package/dist/esm/FileReaderP.js +148 -0
  37. package/dist/esm/FormDataP.js +245 -0
  38. package/dist/esm/HeadersP.js +170 -0
  39. package/dist/esm/MessageEventP.js +61 -0
  40. package/dist/esm/ProgressEventP.js +65 -0
  41. package/dist/esm/RequestP.js +153 -0
  42. package/dist/esm/ResponseP.js +98 -0
  43. package/dist/esm/TextDecoderP.js +183 -0
  44. package/dist/esm/TextEncoderP.js +119 -0
  45. package/dist/esm/URLSearchParamsP.js +227 -0
  46. package/dist/esm/WebSocketP.js +234 -0
  47. package/dist/esm/XMLHttpRequestP.js +563 -0
  48. package/dist/esm/convertor.js +80 -0
  49. package/dist/esm/fetchP.js +111 -0
  50. package/dist/esm/index.js +25 -0
  51. package/dist/esm/isPolyfill.js +48 -0
  52. package/dist/esm/platform.js +31 -0
  53. package/dist/index.d.ts +1 -5
  54. package/package.json +7 -10
  55. package/dist/index.cjs.js +0 -3252
  56. package/dist/index.cjs.min.js +0 -1
  57. package/dist/index.esm.js +0 -3212
  58. package/dist/index.esm.min.js +0 -1
@@ -0,0 +1,176 @@
1
+ 'use strict';
2
+
3
+ var EventP = require('./EventP.js');
4
+ var isPolyfill = require('./isPolyfill.js');
5
+
6
+ var _a;
7
+ const passive = 0;
8
+ const dispatched = 1;
9
+ const preventDefaultCalled = 2;
10
+ const stopImmediatePropagationCalled = 3;
11
+ /** @internal */ const state = Symbol( /* "EventTargetState" */);
12
+ class EventTargetP {
13
+ constructor() {
14
+ this[state] = new EventTargetState(this);
15
+ this[state].name = new.target.name;
16
+ }
17
+ addEventListener(...args) {
18
+ const [type, callback, options] = args;
19
+ isPolyfill.checkArgsLength(args, 2, this[state].name, "addEventListener");
20
+ if (typeof callback !== "function" && typeof callback !== "object" && typeof callback !== "undefined") {
21
+ throw new TypeError(`Failed to execute 'addEventListener' on '${this[state].name}': parameter 2 is not of type 'Object'.`);
22
+ }
23
+ const s = this[state];
24
+ const executor = new Executor(type, callback);
25
+ executor.options.capture = typeof options === "boolean" ? options : !!(options === null || options === void 0 ? void 0 : options.capture);
26
+ if (!s[_executors].some(x => x.equals(executor))) {
27
+ if (options && typeof options === "object") {
28
+ const { once, passive, signal } = options;
29
+ executor.options.once = !!once;
30
+ executor.options.passive = !!passive;
31
+ if (signal && isPolyfill.isPolyfillType("EventTarget", signal)) {
32
+ executor.options.signal = signal;
33
+ reply(this, signal, executor);
34
+ }
35
+ }
36
+ s[_executors].push(executor);
37
+ const f = (v) => !!v.options.capture ? 0 : 1;
38
+ s[_executors] = s[_executors].sort((a, b) => f(a) - f(b));
39
+ }
40
+ }
41
+ dispatchEvent(...args) {
42
+ const [event] = args;
43
+ isPolyfill.checkArgsLength(args, 1, this[state].name, "dispatchEvent");
44
+ if (!(event instanceof EventP.EventP)) {
45
+ throw new TypeError(`Failed to execute 'dispatchEvent' on '${this[state].name}': parameter 1 is not of type 'Event'.`);
46
+ }
47
+ EventP.Event_setTrusted(event, false);
48
+ event[EventP.eventState].target = this;
49
+ return EventTarget_fire(this, event);
50
+ }
51
+ removeEventListener(...args) {
52
+ const [type, callback, options] = args;
53
+ isPolyfill.checkArgsLength(args, 2, this[state].name, "removeEventListener");
54
+ if (typeof callback !== "function" && typeof callback !== "object" && typeof callback !== "undefined") {
55
+ throw new TypeError(`Failed to execute 'removeEventListener' on '${this[state].name}': parameter 2 is not of type 'Object'.`);
56
+ }
57
+ const s = this[state];
58
+ const executor = new Executor(type, callback);
59
+ executor.options.capture = typeof options === "boolean" ? options : !!(options === null || options === void 0 ? void 0 : options.capture);
60
+ if (s[_executors].some(x => x.equals(executor))) {
61
+ s[_executors] = s[_executors].filter(x => !x.equals(executor));
62
+ }
63
+ }
64
+ /** @internal */ toString() { return "[object EventTarget]"; }
65
+ /** @internal */ get [Symbol.toStringTag]() { return "EventTarget"; }
66
+ /** @internal */ get isPolyfill() { return { symbol: isPolyfill.polyfill, hierarchy: ["EventTarget"] }; }
67
+ }
68
+ /** @internal */
69
+ const _executors = Symbol();
70
+ /** @internal */
71
+ class EventTargetState {
72
+ constructor(target) {
73
+ this.name = "EventTarget";
74
+ this[_a] = [];
75
+ this.target = target;
76
+ }
77
+ }
78
+ _a = _executors;
79
+ /** @internal */
80
+ function EventTarget_fire(target, event) {
81
+ const s = target[state];
82
+ const evs = event[EventP.eventState];
83
+ if (!event.target)
84
+ evs.target = target;
85
+ evs.currentTarget = target;
86
+ evs.eventPhase = 2 /* AT_TARGET */;
87
+ EventP.Event_setEtField(event, dispatched, true);
88
+ let onceIndexes = [];
89
+ for (let i = 0; i < s[_executors].length; ++i) {
90
+ if (EventP.Event_getEtField(event, stopImmediatePropagationCalled))
91
+ break;
92
+ let executor = s[_executors][i];
93
+ if (executor.type !== event.type)
94
+ continue;
95
+ if (executor.options.once)
96
+ onceIndexes.push(i);
97
+ EventP.Event_setEtField(event, passive, !!executor.options.passive);
98
+ try {
99
+ let cb = executor.callback;
100
+ if (typeof cb === "function")
101
+ cb.call(target, event);
102
+ }
103
+ catch (e) {
104
+ console.error(e);
105
+ }
106
+ EventP.Event_setEtField(event, passive, false);
107
+ }
108
+ if (onceIndexes.length > 0) {
109
+ s[_executors] = s[_executors].reduce((acc, cur, index) => {
110
+ if (onceIndexes.indexOf(index) === -1)
111
+ acc.push(cur);
112
+ return acc;
113
+ }, []);
114
+ }
115
+ evs.currentTarget = null;
116
+ evs.eventPhase = 0 /* NONE */;
117
+ EventP.Event_setEtField(event, dispatched, false);
118
+ return !(event.cancelable && EventP.Event_getEtField(event, preventDefaultCalled));
119
+ }
120
+ function reply(target, signal, executor) {
121
+ const s = target[state];
122
+ const onAbort = () => {
123
+ s[_executors] = s[_executors].filter(x => !x.equals(executor));
124
+ signal.removeEventListener("abort", onAbort);
125
+ };
126
+ signal.addEventListener("abort", onAbort);
127
+ }
128
+ /** @internal */
129
+ class Executor {
130
+ constructor(type, callback) {
131
+ this.options = {};
132
+ this.type = "" + type;
133
+ this.callback = extract(callback);
134
+ }
135
+ equals(executor) {
136
+ return Object.is(this.type, executor.type) && Object.is(this.callback, executor.callback)
137
+ && Object.is(this.options.capture, executor.options.capture);
138
+ }
139
+ }
140
+ function extract(cb) {
141
+ if (typeof cb === "function") {
142
+ return cb;
143
+ }
144
+ else if (isEventListenerObject(cb)) {
145
+ return cb.handleEvent;
146
+ }
147
+ else {
148
+ return cb;
149
+ }
150
+ }
151
+ function isEventListenerObject(cb) {
152
+ return !!cb && typeof cb === "object" && "handleEvent" in cb && typeof cb.handleEvent === "function";
153
+ }
154
+ /** @internal */
155
+ function attachFn(target, type, cb, listener) {
156
+ if (typeof cb === "function") {
157
+ target.addEventListener(type, listener);
158
+ }
159
+ else {
160
+ target.removeEventListener(type, listener);
161
+ }
162
+ }
163
+ /** @internal */
164
+ function executeFn(target, cb, ev) {
165
+ if (typeof cb === "function")
166
+ cb.call(target, ev);
167
+ }
168
+ const EventTargetE = isPolyfill.g["EventTarget"] || EventTargetP;
169
+
170
+ exports.EventTarget = EventTargetE;
171
+ exports.EventTargetP = EventTargetP;
172
+ exports.EventTargetState = EventTargetState;
173
+ exports.EventTarget_fire = EventTarget_fire;
174
+ exports.attachFn = attachFn;
175
+ exports.eventTargetState = state;
176
+ exports.executeFn = executeFn;
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ var BlobP = require('./BlobP.js');
4
+ var isPolyfill = require('./isPolyfill.js');
5
+ require('./TextEncoderP.js');
6
+ require('./TextDecoderP.js');
7
+
8
+ /** @internal */
9
+ const state = Symbol( /* "FileState" */);
10
+ class FileP extends BlobP.BlobP {
11
+ constructor(...args) {
12
+ const [fileBits, fileName, options] = args;
13
+ isPolyfill.checkArgsLength(args, 2, "File");
14
+ super(fileBits, options);
15
+ this[state] = new FileState();
16
+ this[state].lastModified = +((options === null || options === void 0 ? void 0 : options.lastModified) ? new Date(options.lastModified) : new Date()) || 0;
17
+ this[state].name = "" + fileName;
18
+ }
19
+ get lastModified() { return this[state].lastModified; }
20
+ get name() { return this[state].name; }
21
+ get webkitRelativePath() { return ""; }
22
+ /** @internal */ toString() { return "[object File]"; }
23
+ /** @internal */ get [Symbol.toStringTag]() { return "File"; }
24
+ /** @internal */ get isPolyfill() { return { symbol: isPolyfill.polyfill, hierarchy: ["File", "Blob"] }; }
25
+ }
26
+ /** @internal */
27
+ class FileState {
28
+ constructor() {
29
+ this.lastModified = 0;
30
+ this.name = "";
31
+ }
32
+ }
33
+ const FileE = isPolyfill.g["Blob"] ? isPolyfill.g["File"] : FileP;
34
+
35
+ exports.File = FileE;
36
+ exports.FileP = FileP;
@@ -0,0 +1,151 @@
1
+ 'use strict';
2
+
3
+ var EventTargetP = require('./EventTargetP.js');
4
+ var ProgressEventP = require('./ProgressEventP.js');
5
+ var BlobP = require('./BlobP.js');
6
+ var isPolyfill = require('./isPolyfill.js');
7
+ require('./EventP.js');
8
+ require('./TextEncoderP.js');
9
+ require('./TextDecoderP.js');
10
+
11
+ var _a;
12
+ /** @internal */
13
+ const state = Symbol( /* "FileReaderState" */);
14
+ class FileReaderP extends EventTargetP.EventTargetP {
15
+ static get EMPTY() { return 0; }
16
+ static get LOADING() { return 1; }
17
+ static get DONE() { return 2; }
18
+ constructor() {
19
+ super();
20
+ this[state] = new FileReaderState(this);
21
+ }
22
+ get readyState() { return this[state].readyState; }
23
+ get result() { return this[state].result; }
24
+ get EMPTY() { return 0; }
25
+ get LOADING() { return 1; }
26
+ get DONE() { return 2; }
27
+ get error() { return this[state].error; }
28
+ abort() {
29
+ if (this.readyState === 1 /* LOADING */) {
30
+ const s = this[state];
31
+ s.readyState = 2 /* DONE */;
32
+ s.result = null;
33
+ s.error = new isPolyfill.MPException("An ongoing operation was aborted, typically with a call to abort().", "AbortError");
34
+ ProgressEventP.emitProcessEvent(this, "abort");
35
+ }
36
+ }
37
+ readAsArrayBuffer(...args) {
38
+ read(this, "readAsArrayBuffer", args, blob => {
39
+ this[state].result = BlobP.Blob_toUint8Array(blob).buffer.slice(0);
40
+ });
41
+ }
42
+ readAsBinaryString(...args) {
43
+ read(this, "readAsBinaryString", args, blob => {
44
+ let str = [];
45
+ let buf = BlobP.Blob_toUint8Array(blob);
46
+ for (let i = 0; i < buf.length; ++i) {
47
+ let char = buf[i];
48
+ str.push(String.fromCharCode(char));
49
+ }
50
+ this[state].result = str.join("");
51
+ });
52
+ }
53
+ readAsDataURL(...args) {
54
+ read(this, "readAsDataURL", args, blob => {
55
+ this[state].result = "data:" + (blob.type || "application/octet-stream") + ";base64," + BlobP.Uint8Array_toBase64(BlobP.Blob_toUint8Array(blob));
56
+ });
57
+ }
58
+ readAsText(...args) {
59
+ const encoding = args.length > 1 ? args[1] : undefined;
60
+ read(this, "readAsText", args, blob => {
61
+ if (encoding !== undefined) {
62
+ let _encoding = "" + encoding;
63
+ if (["utf-8", "utf8", "unicode-1-1-utf-8"].indexOf(_encoding.toLowerCase()) === -1) {
64
+ console.error(`TypeError: Failed to execute 'readAsText' on 'FileReader': encoding ('${_encoding}') not implemented.`);
65
+ }
66
+ }
67
+ this[state].result = BlobP.decode(BlobP.Blob_toUint8Array(blob));
68
+ });
69
+ }
70
+ get onabort() { return this[state].onabort; }
71
+ set onabort(value) { this[state].onabort = value; attach(this, "abort"); }
72
+ get onerror() { return this[state].onerror; }
73
+ set onerror(value) { this[state].onerror = value; attach(this, "error"); }
74
+ get onload() { return this[state].onload; }
75
+ set onload(value) { this[state].onload = value; attach(this, "load"); }
76
+ get onloadend() { return this[state].onloadend; }
77
+ set onloadend(value) { this[state].onloadend = value; attach(this, "loadend"); }
78
+ get onloadstart() { return this[state].onloadstart; }
79
+ set onloadstart(value) { this[state].onloadstart = value; attach(this, "loadstart"); }
80
+ get onprogress() { return this[state].onprogress; }
81
+ set onprogress(value) { this[state].onprogress = value; attach(this, "progress"); }
82
+ /** @internal */ toString() { return "[object FileReader]"; }
83
+ /** @internal */ get [Symbol.toStringTag]() { return "FileReader"; }
84
+ /** @internal */ get isPolyfill() { return { symbol: isPolyfill.polyfill, hierarchy: ["FileReader", "EventTarget"] }; }
85
+ }
86
+ /** @internal */
87
+ const _handlers = Symbol();
88
+ /** @internal */
89
+ class FileReaderState {
90
+ constructor(target) {
91
+ this.readyState = 0 /* EMPTY */;
92
+ this.result = null;
93
+ this.error = null;
94
+ this[_a] = getHandlers(this);
95
+ this.onabort = null;
96
+ this.onerror = null;
97
+ this.onload = null;
98
+ this.onloadend = null;
99
+ this.onloadstart = null;
100
+ this.onprogress = null;
101
+ this.target = target;
102
+ }
103
+ }
104
+ _a = _handlers;
105
+ function read(reader, kind, args, setResult) {
106
+ const [blob] = args;
107
+ isPolyfill.checkArgsLength(args, 1, "FileReader", kind);
108
+ if (!isPolyfill.isPolyfillType("Blob", blob)) {
109
+ throw new TypeError("Failed to execute '" + kind + "' on 'FileReader': parameter 1 is not of type 'Blob'.");
110
+ }
111
+ const s = reader[state];
112
+ s.error = null;
113
+ s.readyState = 1 /* LOADING */;
114
+ ProgressEventP.emitProcessEvent(s.target, "loadstart", 0, blob.size);
115
+ setTimeout(() => {
116
+ if (s.readyState === 1 /* LOADING */) {
117
+ s.readyState = 2 /* DONE */;
118
+ try {
119
+ setResult(blob);
120
+ ProgressEventP.emitProcessEvent(s.target, "load", blob.size, blob.size);
121
+ }
122
+ catch (e) {
123
+ s.result = null;
124
+ s.error = e;
125
+ ProgressEventP.emitProcessEvent(s.target, "error", 0, blob.size);
126
+ }
127
+ }
128
+ ProgressEventP.emitProcessEvent(s.target, "loadend", !!s.result ? blob.size : 0, blob.size);
129
+ });
130
+ }
131
+ function attach(reader, type) {
132
+ const s = reader[state];
133
+ const fnName = ("on" + type);
134
+ const cb = s[fnName];
135
+ const listener = s[_handlers][fnName];
136
+ EventTargetP.attachFn(reader, type, cb, listener);
137
+ }
138
+ function getHandlers(s) {
139
+ return {
140
+ onabort: (ev) => { EventTargetP.executeFn(s.target, s.onabort, ev); },
141
+ onerror: (ev) => { EventTargetP.executeFn(s.target, s.onerror, ev); },
142
+ onload: (ev) => { EventTargetP.executeFn(s.target, s.onload, ev); },
143
+ onloadend: (ev) => { EventTargetP.executeFn(s.target, s.onloadend, ev); },
144
+ onloadstart: (ev) => { EventTargetP.executeFn(s.target, s.onloadstart, ev); },
145
+ onprogress: (ev) => { EventTargetP.executeFn(s.target, s.onprogress, ev); },
146
+ };
147
+ }
148
+ const FileReaderE = isPolyfill.g["Blob"] ? isPolyfill.g["FileReader"] : FileReaderP;
149
+
150
+ exports.FileReader = FileReaderE;
151
+ exports.FileReaderP = FileReaderP;
@@ -0,0 +1,250 @@
1
+ 'use strict';
2
+
3
+ var BlobP = require('./BlobP.js');
4
+ var FileP = require('./FileP.js');
5
+ var isPolyfill = require('./isPolyfill.js');
6
+ require('./TextEncoderP.js');
7
+ require('./TextDecoderP.js');
8
+
9
+ var _a;
10
+ /** @internal */ const state = Symbol( /* "FormDataState" */);
11
+ const checkArgsFn = (args, required, funcName) => { isPolyfill.checkArgsLength(args, required, "FormData", funcName); };
12
+ class FormDataP {
13
+ constructor(form, submitter) {
14
+ if (submitter === undefined) {
15
+ if (form !== undefined) {
16
+ console.error("TypeError: Failed to construct 'FormData': parameter 1 not implemented.");
17
+ }
18
+ }
19
+ else {
20
+ if (submitter !== null) {
21
+ console.error("TypeError: Failed to construct 'FormData': parameter 1 and parameter 2 not implemented.");
22
+ }
23
+ }
24
+ this[state] = new FormDataState();
25
+ }
26
+ append(...args) {
27
+ const [name, value, filename] = args;
28
+ checkArgsFn(args, 2, "append");
29
+ this[state][_formData].push(normalizeArgs(name, value, filename));
30
+ }
31
+ delete(...args) {
32
+ const [name] = args;
33
+ checkArgsFn(args, 1, "delete");
34
+ let _name = "" + name;
35
+ let index = -1;
36
+ let array = this[state][_formData];
37
+ let result = [];
38
+ for (let i = 0; i < array.length; ++i) {
39
+ let item = array[i];
40
+ if (item[0] === _name) {
41
+ index = i;
42
+ continue;
43
+ }
44
+ result.push(item);
45
+ }
46
+ if (index > -1) {
47
+ this[state][_formData] = result;
48
+ }
49
+ }
50
+ get(...args) {
51
+ const [name] = args;
52
+ checkArgsFn(args, 1, "get");
53
+ let _name = "" + name;
54
+ let array = this[state][_formData];
55
+ for (let i = 0; i < array.length; ++i) {
56
+ let item = array[i];
57
+ if (item[0] === _name) {
58
+ return item[1];
59
+ }
60
+ }
61
+ return null;
62
+ }
63
+ getAll(...args) {
64
+ const [name] = args;
65
+ checkArgsFn(args, 1, "getAll");
66
+ let _name = "" + name;
67
+ let array = this[state][_formData];
68
+ let result = [];
69
+ for (let i = 0; i < array.length; ++i) {
70
+ let item = array[i];
71
+ if (item[0] === _name) {
72
+ result.push(item[1]);
73
+ }
74
+ }
75
+ return result;
76
+ }
77
+ has(...args) {
78
+ const [name] = args;
79
+ checkArgsFn(args, 1, "has");
80
+ let _name = "" + name;
81
+ let array = this[state][_formData];
82
+ for (let i = 0; i < array.length; ++i) {
83
+ let item = array[i];
84
+ if (item[0] === _name) {
85
+ return true;
86
+ }
87
+ }
88
+ return false;
89
+ }
90
+ set(...args) {
91
+ const [name, value, filename] = args;
92
+ checkArgsFn(args, 2, "set");
93
+ let _name = "" + name;
94
+ let _args = normalizeArgs(name, value, filename);
95
+ let index = -1;
96
+ let array = this[state][_formData];
97
+ let result = [];
98
+ for (let i = 0; i < array.length; ++i) {
99
+ let item = array[i];
100
+ if (item[0] === _name) {
101
+ if (index === -1) {
102
+ index = i;
103
+ result.push(_args);
104
+ }
105
+ continue;
106
+ }
107
+ result.push(item);
108
+ }
109
+ if (index === -1) {
110
+ result.push(_args);
111
+ }
112
+ this[state][_formData] = result;
113
+ }
114
+ forEach(...args) {
115
+ const [callbackfn, thisArg] = args;
116
+ checkArgsFn(args, 1, "forEach");
117
+ if (typeof callbackfn !== "function") {
118
+ throw new TypeError("Failed to execute 'forEach' on 'FormData': parameter 1 is not of type 'Function'.");
119
+ }
120
+ let array = this[state][_formData];
121
+ for (let i = 0; i < array.length; ++i) {
122
+ let item = array[i];
123
+ callbackfn.call(thisArg, item[1], item[0], thisArg);
124
+ }
125
+ }
126
+ entries() {
127
+ return this[state][_formData].map(x => [x[0], x[1]]).values();
128
+ }
129
+ keys() {
130
+ return this[state][_formData].map(x => x[0]).values();
131
+ }
132
+ values() {
133
+ return this[state][_formData].map(x => x[1]).values();
134
+ }
135
+ [Symbol.iterator]() {
136
+ return this.entries();
137
+ }
138
+ /** @internal */ toString() { return "[object FormData]"; }
139
+ /** @internal */ get [Symbol.toStringTag]() { return "FormData"; }
140
+ /** @internal */ get isPolyfill() { return { symbol: isPolyfill.polyfill, hierarchy: ["FormData"] }; }
141
+ }
142
+ /** @internal */
143
+ const _formData = Symbol();
144
+ /** @internal */
145
+ class FormDataState {
146
+ constructor() {
147
+ this[_a] = [];
148
+ }
149
+ }
150
+ _a = _formData;
151
+ /** @internal */
152
+ function FormData_toBlob(formData) {
153
+ const boundary = "----formdata-mphttpx-" + Math.random();
154
+ const p = `--${boundary}\r\nContent-Disposition: form-data; name="`;
155
+ let chunks = [];
156
+ for (let i = 0; i < formData[state][_formData].length; ++i) {
157
+ let pair = formData[state][_formData][i];
158
+ let name = pair[0];
159
+ let value = pair[1];
160
+ if (typeof value === "string") {
161
+ chunks.push(p + escape(normalizeLinefeeds(name)) + `"\r\n\r\n${normalizeLinefeeds(value)}\r\n`);
162
+ }
163
+ else {
164
+ chunks.push(p + escape(normalizeLinefeeds(name)) + `"; filename="${escape(value.name)}"\r\nContent-Type: ${value.type || "application/octet-stream"}\r\n\r\n`, value, `\r\n`);
165
+ }
166
+ }
167
+ chunks.push(`--${boundary}--`);
168
+ return new BlobP.BlobP(chunks, { type: "multipart/form-data; boundary=" + boundary });
169
+ }
170
+ function normalizeArgs(name, value, filename) {
171
+ if (isPolyfill.isPolyfillType("Blob", value)) {
172
+ filename = filename !== undefined
173
+ ? ("" + filename)
174
+ : typeof value.name === "string"
175
+ ? value.name
176
+ : "blob";
177
+ if (value.name !== filename || isPolyfill.isObjectType("Blob", value) || isPolyfill.isPolyfillType("Blob", value, true)) {
178
+ value = new FileP.FileP([value], filename);
179
+ }
180
+ return ["" + name, value];
181
+ }
182
+ return ["" + name, "" + value];
183
+ }
184
+ // normalize line feeds for textarea
185
+ // https://html.spec.whatwg.org/multipage/form-elements.html#textarea-line-break-normalisation-transformation
186
+ function normalizeLinefeeds(value) {
187
+ return value.replace(/\r?\n|\r/g, "\r\n");
188
+ }
189
+ function escape(str) {
190
+ return str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22');
191
+ }
192
+ /** @internal */
193
+ function createFormDataFromBinaryText(text, boundary) {
194
+ const throwParseError = () => {
195
+ throw new TypeError("Could not parse content as FormData.");
196
+ };
197
+ if (typeof text !== "string" || text.trim() === "") {
198
+ throwParseError();
199
+ }
200
+ let firstLineEnd = text.indexOf("\r\n");
201
+ if (firstLineEnd === -1) {
202
+ throwParseError();
203
+ }
204
+ let _boundary = text.substring(2, firstLineEnd).trim();
205
+ if (!_boundary) {
206
+ throwParseError();
207
+ }
208
+ if (boundary !== undefined && boundary !== _boundary) {
209
+ throwParseError();
210
+ }
211
+ let parts = text.split(`--${_boundary}`).filter(part => {
212
+ let trimmed = part.trim();
213
+ return trimmed !== "" && trimmed !== "--";
214
+ });
215
+ if (parts.length === 0) {
216
+ throwParseError();
217
+ }
218
+ let formData = new FormDataP();
219
+ parts.forEach(part => {
220
+ let separatorIndex = part.indexOf("\r\n\r\n");
221
+ if (separatorIndex === -1) {
222
+ throwParseError();
223
+ }
224
+ let headerRaw = part.substring(0, separatorIndex).trim();
225
+ let nameMatch = headerRaw.match(/name="([^"]*)"/);
226
+ if (!nameMatch || nameMatch.length < 2) {
227
+ throwParseError();
228
+ }
229
+ let fieldName = nameMatch[1];
230
+ let filenameMatch = headerRaw.match(/filename="([^"]*)"/);
231
+ let contentRaw = part.substring(separatorIndex + 4);
232
+ if (!filenameMatch) {
233
+ formData.append(fieldName, contentRaw.replace(/^[\r\n]+|[\r\n]+$/g, ""));
234
+ }
235
+ else {
236
+ let filename = filenameMatch[1] || "";
237
+ let contentTypeMatch = headerRaw.match(/Content-Type: ([^\r\n]+)/);
238
+ let mimeType = contentTypeMatch ? (contentTypeMatch[1] || "").trim() : "text/plain";
239
+ let content = contentRaw.replace(/\r\n/g, "");
240
+ formData.append(fieldName, new FileP.FileP([content], filename, { type: mimeType }));
241
+ }
242
+ });
243
+ return formData;
244
+ }
245
+ const FormDataE = isPolyfill.g["FormData"] || FormDataP;
246
+
247
+ exports.FormData = FormDataE;
248
+ exports.FormDataP = FormDataP;
249
+ exports.FormData_toBlob = FormData_toBlob;
250
+ exports.createFormDataFromBinaryText = createFormDataFromBinaryText;