-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathformdata.js
56 lines (46 loc) · 1.11 KB
/
formdata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class FormData {
constructor() {
this._entries = [];
}
append(name, value) {
if (typeof name !== 'string') {
throw new TypeError('FormData name must be a string');
}
if (typeof value !== 'string') {
if (typeof value !== 'object' || typeof value.uri !== 'string') {
throw new TypeError('FormData value must be a string or { uri: tempFilePath }')
}
}
this._entries.push([name, value]);
}
set(name, value) {
const entry = this.get(name);
if (entry) {
entry[1] = value;
} else {
this.append(name, value);
}
}
delete(name) {
this._entries = this._entries.filter(entry => entry[0] !== name);
}
entries() {
return this._entries;
}
get(name) {
return this._entries.find(entry => entry[0] === name);
}
getAll(name) {
return this._entries.filter(entry => entry[0] === name);
}
has(name) {
return this._entries.some(entry => entry[0] === name);
}
keys() {
return this._entries.map(entry => entry[0]);
}
values() {
return this._entries.map(entry => entry[1]);
}
}
module.exports = FormData;