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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
| module.exports = {
| type(ob) {
| return Object.prototype.toString.call(ob).slice(8, -1).toLowerCase()
| },
| isObject(ob, real) {
| if (real) {
| return this.type(ob) === "object"
| } else {
| return ob && typeof ob === 'object'
| }
| },
| isFormData(val) {
| return (typeof FormData !== 'undefined') && (val instanceof FormData);
| },
| trim(str) {
| return str.replace(/(^\s*)|(\s*$)/g, '');
| },
| encode(val) {
| return encodeURIComponent(val)
| .replace(/%40/gi, '@')
| .replace(/%3A/gi, ':')
| .replace(/%24/g, '$')
| .replace(/%2C/gi, ',')
| .replace(/%20/g, '+')
| .replace(/%5B/gi, '[')
| .replace(/%5D/gi, ']');
| },
| formatParams(data) {
| let str = "";
| let first = true;
| let that = this;
| if (!this.isObject(data)) {
| return data;
| }
|
| function _encode(sub, path) {
| let encode = that.encode;
| let type = that.type(sub);
| if (type == "array") {
| sub.forEach(function (e, i) {
| if (!that.isObject(e)) i = "";
| _encode(e, path + `%5B${i}%5D`);
| });
|
| } else if (type == "object") {
| for (let key in sub) {
| if (path) {
| _encode(sub[key], path + "%5B" + encode(key) + "%5D");
| } else {
| _encode(sub[key], encode(key));
| }
| }
| } else {
| if (!first) {
| str += "&";
| }
| first = false;
| str += path + "=" + encode(sub);
| }
| }
|
| _encode(data, "");
| return str;
| },
| // Do not overwrite existing attributes
| merge(a, b) {
| for (let key in b) {
| if (!a.hasOwnProperty(key)) {
| a[key] = b[key];
| } else if (this.isObject(b[key], 1) && this.isObject(a[key], 1)) {
| this.merge(a[key], b[key])
| }
| }
| return a;
| }
|
| }
|
|