@etsoo/shared 1.2.47 → 1.2.48
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/__tests__/Utils.ts +3 -3
- package/lib/cjs/Utils.d.ts +7 -17
- package/lib/cjs/Utils.js +60 -79
- package/lib/mjs/Utils.d.ts +7 -17
- package/lib/mjs/Utils.js +60 -79
- package/package.json +1 -1
- package/src/Utils.ts +72 -94
package/__tests__/Utils.ts
CHANGED
|
@@ -15,7 +15,7 @@ test('Tests for addBlankItem', () => {
|
|
|
15
15
|
|
|
16
16
|
test('Tests for addUrlParam', () => {
|
|
17
17
|
const url = 'https://www.etsoo.com';
|
|
18
|
-
const result =
|
|
18
|
+
const result = url.addUrlParam('a', 'b');
|
|
19
19
|
expect(result).toBe('https://www.etsoo.com/?a=b');
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -30,7 +30,7 @@ describe('Tests for addUrlParams', () => {
|
|
|
30
30
|
f: ['a', 'b'],
|
|
31
31
|
g: null
|
|
32
32
|
};
|
|
33
|
-
const result1 =
|
|
33
|
+
const result1 = url.addUrlParams(data);
|
|
34
34
|
|
|
35
35
|
test('addUrlParams', () => {
|
|
36
36
|
expect(result1).toBe(
|
|
@@ -38,7 +38,7 @@ describe('Tests for addUrlParams', () => {
|
|
|
38
38
|
);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
const result2 =
|
|
41
|
+
const result2 = url.addUrlParams(data, true);
|
|
42
42
|
|
|
43
43
|
test('addUrlParams with array format', () => {
|
|
44
44
|
expect(result2).toBe(
|
package/lib/cjs/Utils.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ declare global {
|
|
|
19
19
|
* @returns New URL
|
|
20
20
|
*/
|
|
21
21
|
addUrlParams(this: string, data: DataTypes.SimpleObject, arrayFormat?: boolean | string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Add parameters to URL
|
|
24
|
+
* @param this URL to add parameters
|
|
25
|
+
* @param params Parameters string
|
|
26
|
+
* @returns New URL
|
|
27
|
+
*/
|
|
28
|
+
addUrlParams(this: string, params: string): string;
|
|
22
29
|
/**
|
|
23
30
|
* Check the input string contains Chinese character or not
|
|
24
31
|
* @param this Input
|
|
@@ -90,23 +97,6 @@ export declare namespace Utils {
|
|
|
90
97
|
* @param blankLabel Blank label, default is ---
|
|
91
98
|
*/
|
|
92
99
|
function addBlankItem<T extends object>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): T[];
|
|
93
|
-
/**
|
|
94
|
-
* Add parameter to URL
|
|
95
|
-
* @param url URL to add parameter
|
|
96
|
-
* @param name Parameter name
|
|
97
|
-
* @param value Parameter value
|
|
98
|
-
* @param arrayFormat Array format to array style or not to multiple fields
|
|
99
|
-
* @returns New URL
|
|
100
|
-
*/
|
|
101
|
-
function addUrlParam(url: string, name: string, value: DataTypes.Simple, arrayFormat?: boolean | string): string;
|
|
102
|
-
/**
|
|
103
|
-
* Add parameters to URL
|
|
104
|
-
* @param url URL to add parameters
|
|
105
|
-
* @param data Parameters
|
|
106
|
-
* @param arrayFormat Array format to array style or not to multiple fields
|
|
107
|
-
* @returns New URL
|
|
108
|
-
*/
|
|
109
|
-
function addUrlParams(url: string, data: DataTypes.SimpleObject, arrayFormat?: boolean | string): string;
|
|
110
100
|
/**
|
|
111
101
|
* Base64 chars to number
|
|
112
102
|
* @param base64Chars Base64 chars
|
package/lib/cjs/Utils.js
CHANGED
|
@@ -8,10 +8,68 @@ const DataTypes_1 = require("./DataTypes");
|
|
|
8
8
|
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
9
9
|
const DateUtils_1 = require("./DateUtils");
|
|
10
10
|
String.prototype.addUrlParam = function (name, value, arrayFormat) {
|
|
11
|
-
return
|
|
11
|
+
return this.addUrlParams({ [name]: value }, arrayFormat);
|
|
12
12
|
};
|
|
13
13
|
String.prototype.addUrlParams = function (data, arrayFormat) {
|
|
14
|
-
|
|
14
|
+
if (typeof data === 'string') {
|
|
15
|
+
let url = this;
|
|
16
|
+
if (url.includes('?')) {
|
|
17
|
+
url += '&';
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
if (!url.endsWith('/'))
|
|
21
|
+
url = url + '/';
|
|
22
|
+
url += '?';
|
|
23
|
+
}
|
|
24
|
+
return url + data;
|
|
25
|
+
}
|
|
26
|
+
if (typeof URL === 'undefined') {
|
|
27
|
+
const params = Object.entries(data)
|
|
28
|
+
.map(([key, value]) => {
|
|
29
|
+
let v;
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
if (arrayFormat == null || arrayFormat === false) {
|
|
32
|
+
return value
|
|
33
|
+
.map((item) => `${key}=${encodeURIComponent(`${item}`)}`)
|
|
34
|
+
.join('&');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
v = value.join(arrayFormat ? ',' : arrayFormat);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (value instanceof Date) {
|
|
41
|
+
v = value.toJSON();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
v = value == null ? '' : `${value}`;
|
|
45
|
+
}
|
|
46
|
+
return `${key}=${encodeURIComponent(v)}`;
|
|
47
|
+
})
|
|
48
|
+
.join('&');
|
|
49
|
+
return this.addUrlParams(params);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const urlObj = new URL(this);
|
|
53
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
54
|
+
if (Array.isArray(value)) {
|
|
55
|
+
if (arrayFormat == null || arrayFormat === false) {
|
|
56
|
+
value.forEach((item) => {
|
|
57
|
+
urlObj.searchParams.append(key, `${item}`);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
urlObj.searchParams.append(key, value.join(arrayFormat ? ',' : arrayFormat));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (value instanceof Date) {
|
|
65
|
+
urlObj.searchParams.append(key, value.toJSON());
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
urlObj.searchParams.append(key, `${value == null ? '' : value}`);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return urlObj.toString();
|
|
72
|
+
}
|
|
15
73
|
};
|
|
16
74
|
String.prototype.containChinese = function () {
|
|
17
75
|
const regExp = /[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f]/g;
|
|
@@ -95,83 +153,6 @@ var Utils;
|
|
|
95
153
|
return options;
|
|
96
154
|
}
|
|
97
155
|
Utils.addBlankItem = addBlankItem;
|
|
98
|
-
/**
|
|
99
|
-
* Add parameter to URL
|
|
100
|
-
* @param url URL to add parameter
|
|
101
|
-
* @param name Parameter name
|
|
102
|
-
* @param value Parameter value
|
|
103
|
-
* @param arrayFormat Array format to array style or not to multiple fields
|
|
104
|
-
* @returns New URL
|
|
105
|
-
*/
|
|
106
|
-
function addUrlParam(url, name, value, arrayFormat) {
|
|
107
|
-
return addUrlParams(url, { [name]: value }, arrayFormat);
|
|
108
|
-
}
|
|
109
|
-
Utils.addUrlParam = addUrlParam;
|
|
110
|
-
/**
|
|
111
|
-
* Add parameters to URL
|
|
112
|
-
* @param url URL to add parameters
|
|
113
|
-
* @param data Parameters
|
|
114
|
-
* @param arrayFormat Array format to array style or not to multiple fields
|
|
115
|
-
* @returns New URL
|
|
116
|
-
*/
|
|
117
|
-
function addUrlParams(url, data, arrayFormat) {
|
|
118
|
-
if (typeof URL === 'undefined') {
|
|
119
|
-
if (url.includes('?')) {
|
|
120
|
-
url += '&';
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
if (!url.endsWith('/'))
|
|
124
|
-
url = url + '/';
|
|
125
|
-
url += '?';
|
|
126
|
-
}
|
|
127
|
-
url += Object.entries(data)
|
|
128
|
-
.map(([key, value]) => {
|
|
129
|
-
let v;
|
|
130
|
-
if (Array.isArray(value)) {
|
|
131
|
-
if (arrayFormat == null || arrayFormat === false) {
|
|
132
|
-
return value
|
|
133
|
-
.map((item) => `${key}=${encodeURIComponent(`${item}`)}`)
|
|
134
|
-
.join('&');
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
v = value.join(arrayFormat ? ',' : arrayFormat);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
else if (value instanceof Date) {
|
|
141
|
-
v = value.toJSON();
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
v = value == null ? '' : `${value}`;
|
|
145
|
-
}
|
|
146
|
-
return `${key}=${encodeURIComponent(v)}`;
|
|
147
|
-
})
|
|
148
|
-
.join('&');
|
|
149
|
-
return url;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
const urlObj = new URL(url);
|
|
153
|
-
Object.entries(data).forEach(([key, value]) => {
|
|
154
|
-
if (Array.isArray(value)) {
|
|
155
|
-
if (arrayFormat == null || arrayFormat === false) {
|
|
156
|
-
value.forEach((item) => {
|
|
157
|
-
urlObj.searchParams.append(key, `${item}`);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
urlObj.searchParams.append(key, value.join(arrayFormat ? ',' : arrayFormat));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else if (value instanceof Date) {
|
|
165
|
-
urlObj.searchParams.append(key, value.toJSON());
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
urlObj.searchParams.append(key, `${value == null ? '' : value}`);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
return urlObj.toString();
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
Utils.addUrlParams = addUrlParams;
|
|
175
156
|
/**
|
|
176
157
|
* Base64 chars to number
|
|
177
158
|
* @param base64Chars Base64 chars
|
package/lib/mjs/Utils.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ declare global {
|
|
|
19
19
|
* @returns New URL
|
|
20
20
|
*/
|
|
21
21
|
addUrlParams(this: string, data: DataTypes.SimpleObject, arrayFormat?: boolean | string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Add parameters to URL
|
|
24
|
+
* @param this URL to add parameters
|
|
25
|
+
* @param params Parameters string
|
|
26
|
+
* @returns New URL
|
|
27
|
+
*/
|
|
28
|
+
addUrlParams(this: string, params: string): string;
|
|
22
29
|
/**
|
|
23
30
|
* Check the input string contains Chinese character or not
|
|
24
31
|
* @param this Input
|
|
@@ -90,23 +97,6 @@ export declare namespace Utils {
|
|
|
90
97
|
* @param blankLabel Blank label, default is ---
|
|
91
98
|
*/
|
|
92
99
|
function addBlankItem<T extends object>(options: T[], idField?: string | keyof T, labelField?: unknown, blankLabel?: string): T[];
|
|
93
|
-
/**
|
|
94
|
-
* Add parameter to URL
|
|
95
|
-
* @param url URL to add parameter
|
|
96
|
-
* @param name Parameter name
|
|
97
|
-
* @param value Parameter value
|
|
98
|
-
* @param arrayFormat Array format to array style or not to multiple fields
|
|
99
|
-
* @returns New URL
|
|
100
|
-
*/
|
|
101
|
-
function addUrlParam(url: string, name: string, value: DataTypes.Simple, arrayFormat?: boolean | string): string;
|
|
102
|
-
/**
|
|
103
|
-
* Add parameters to URL
|
|
104
|
-
* @param url URL to add parameters
|
|
105
|
-
* @param data Parameters
|
|
106
|
-
* @param arrayFormat Array format to array style or not to multiple fields
|
|
107
|
-
* @returns New URL
|
|
108
|
-
*/
|
|
109
|
-
function addUrlParams(url: string, data: DataTypes.SimpleObject, arrayFormat?: boolean | string): string;
|
|
110
100
|
/**
|
|
111
101
|
* Base64 chars to number
|
|
112
102
|
* @param base64Chars Base64 chars
|
package/lib/mjs/Utils.js
CHANGED
|
@@ -2,10 +2,68 @@ import { DataTypes } from './DataTypes';
|
|
|
2
2
|
import isEqual from 'lodash.isequal';
|
|
3
3
|
import { DateUtils } from './DateUtils';
|
|
4
4
|
String.prototype.addUrlParam = function (name, value, arrayFormat) {
|
|
5
|
-
return
|
|
5
|
+
return this.addUrlParams({ [name]: value }, arrayFormat);
|
|
6
6
|
};
|
|
7
7
|
String.prototype.addUrlParams = function (data, arrayFormat) {
|
|
8
|
-
|
|
8
|
+
if (typeof data === 'string') {
|
|
9
|
+
let url = this;
|
|
10
|
+
if (url.includes('?')) {
|
|
11
|
+
url += '&';
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
if (!url.endsWith('/'))
|
|
15
|
+
url = url + '/';
|
|
16
|
+
url += '?';
|
|
17
|
+
}
|
|
18
|
+
return url + data;
|
|
19
|
+
}
|
|
20
|
+
if (typeof URL === 'undefined') {
|
|
21
|
+
const params = Object.entries(data)
|
|
22
|
+
.map(([key, value]) => {
|
|
23
|
+
let v;
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
if (arrayFormat == null || arrayFormat === false) {
|
|
26
|
+
return value
|
|
27
|
+
.map((item) => `${key}=${encodeURIComponent(`${item}`)}`)
|
|
28
|
+
.join('&');
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
v = value.join(arrayFormat ? ',' : arrayFormat);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (value instanceof Date) {
|
|
35
|
+
v = value.toJSON();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
v = value == null ? '' : `${value}`;
|
|
39
|
+
}
|
|
40
|
+
return `${key}=${encodeURIComponent(v)}`;
|
|
41
|
+
})
|
|
42
|
+
.join('&');
|
|
43
|
+
return this.addUrlParams(params);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const urlObj = new URL(this);
|
|
47
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
if (arrayFormat == null || arrayFormat === false) {
|
|
50
|
+
value.forEach((item) => {
|
|
51
|
+
urlObj.searchParams.append(key, `${item}`);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
urlObj.searchParams.append(key, value.join(arrayFormat ? ',' : arrayFormat));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (value instanceof Date) {
|
|
59
|
+
urlObj.searchParams.append(key, value.toJSON());
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
urlObj.searchParams.append(key, `${value == null ? '' : value}`);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return urlObj.toString();
|
|
66
|
+
}
|
|
9
67
|
};
|
|
10
68
|
String.prototype.containChinese = function () {
|
|
11
69
|
const regExp = /[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f]/g;
|
|
@@ -89,83 +147,6 @@ export var Utils;
|
|
|
89
147
|
return options;
|
|
90
148
|
}
|
|
91
149
|
Utils.addBlankItem = addBlankItem;
|
|
92
|
-
/**
|
|
93
|
-
* Add parameter to URL
|
|
94
|
-
* @param url URL to add parameter
|
|
95
|
-
* @param name Parameter name
|
|
96
|
-
* @param value Parameter value
|
|
97
|
-
* @param arrayFormat Array format to array style or not to multiple fields
|
|
98
|
-
* @returns New URL
|
|
99
|
-
*/
|
|
100
|
-
function addUrlParam(url, name, value, arrayFormat) {
|
|
101
|
-
return addUrlParams(url, { [name]: value }, arrayFormat);
|
|
102
|
-
}
|
|
103
|
-
Utils.addUrlParam = addUrlParam;
|
|
104
|
-
/**
|
|
105
|
-
* Add parameters to URL
|
|
106
|
-
* @param url URL to add parameters
|
|
107
|
-
* @param data Parameters
|
|
108
|
-
* @param arrayFormat Array format to array style or not to multiple fields
|
|
109
|
-
* @returns New URL
|
|
110
|
-
*/
|
|
111
|
-
function addUrlParams(url, data, arrayFormat) {
|
|
112
|
-
if (typeof URL === 'undefined') {
|
|
113
|
-
if (url.includes('?')) {
|
|
114
|
-
url += '&';
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
if (!url.endsWith('/'))
|
|
118
|
-
url = url + '/';
|
|
119
|
-
url += '?';
|
|
120
|
-
}
|
|
121
|
-
url += Object.entries(data)
|
|
122
|
-
.map(([key, value]) => {
|
|
123
|
-
let v;
|
|
124
|
-
if (Array.isArray(value)) {
|
|
125
|
-
if (arrayFormat == null || arrayFormat === false) {
|
|
126
|
-
return value
|
|
127
|
-
.map((item) => `${key}=${encodeURIComponent(`${item}`)}`)
|
|
128
|
-
.join('&');
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
v = value.join(arrayFormat ? ',' : arrayFormat);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
else if (value instanceof Date) {
|
|
135
|
-
v = value.toJSON();
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
v = value == null ? '' : `${value}`;
|
|
139
|
-
}
|
|
140
|
-
return `${key}=${encodeURIComponent(v)}`;
|
|
141
|
-
})
|
|
142
|
-
.join('&');
|
|
143
|
-
return url;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
const urlObj = new URL(url);
|
|
147
|
-
Object.entries(data).forEach(([key, value]) => {
|
|
148
|
-
if (Array.isArray(value)) {
|
|
149
|
-
if (arrayFormat == null || arrayFormat === false) {
|
|
150
|
-
value.forEach((item) => {
|
|
151
|
-
urlObj.searchParams.append(key, `${item}`);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
urlObj.searchParams.append(key, value.join(arrayFormat ? ',' : arrayFormat));
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else if (value instanceof Date) {
|
|
159
|
-
urlObj.searchParams.append(key, value.toJSON());
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
urlObj.searchParams.append(key, `${value == null ? '' : value}`);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
return urlObj.toString();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
Utils.addUrlParams = addUrlParams;
|
|
169
150
|
/**
|
|
170
151
|
* Base64 chars to number
|
|
171
152
|
* @param base64Chars Base64 chars
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -33,6 +33,14 @@ declare global {
|
|
|
33
33
|
arrayFormat?: boolean | string
|
|
34
34
|
): string;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Add parameters to URL
|
|
38
|
+
* @param this URL to add parameters
|
|
39
|
+
* @param params Parameters string
|
|
40
|
+
* @returns New URL
|
|
41
|
+
*/
|
|
42
|
+
addUrlParams(this: string, params: string): string;
|
|
43
|
+
|
|
36
44
|
/**
|
|
37
45
|
* Check the input string contains Chinese character or not
|
|
38
46
|
* @param this Input
|
|
@@ -108,15 +116,76 @@ String.prototype.addUrlParam = function (
|
|
|
108
116
|
value: DataTypes.Simple,
|
|
109
117
|
arrayFormat?: boolean | string
|
|
110
118
|
) {
|
|
111
|
-
return
|
|
119
|
+
return this.addUrlParams({ [name]: value }, arrayFormat);
|
|
112
120
|
};
|
|
113
121
|
|
|
114
122
|
String.prototype.addUrlParams = function (
|
|
115
123
|
this: string,
|
|
116
|
-
data: DataTypes.SimpleObject,
|
|
124
|
+
data: DataTypes.SimpleObject | string,
|
|
117
125
|
arrayFormat?: boolean | string
|
|
118
126
|
) {
|
|
119
|
-
|
|
127
|
+
if (typeof data === 'string') {
|
|
128
|
+
let url = this;
|
|
129
|
+
if (url.includes('?')) {
|
|
130
|
+
url += '&';
|
|
131
|
+
} else {
|
|
132
|
+
if (!url.endsWith('/')) url = url + '/';
|
|
133
|
+
url += '?';
|
|
134
|
+
}
|
|
135
|
+
return url + data;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (typeof URL === 'undefined') {
|
|
139
|
+
const params = Object.entries(data)
|
|
140
|
+
.map(([key, value]) => {
|
|
141
|
+
let v: string;
|
|
142
|
+
if (Array.isArray(value)) {
|
|
143
|
+
if (arrayFormat == null || arrayFormat === false) {
|
|
144
|
+
return value
|
|
145
|
+
.map(
|
|
146
|
+
(item) =>
|
|
147
|
+
`${key}=${encodeURIComponent(`${item}`)}`
|
|
148
|
+
)
|
|
149
|
+
.join('&');
|
|
150
|
+
} else {
|
|
151
|
+
v = value.join(arrayFormat ? ',' : arrayFormat);
|
|
152
|
+
}
|
|
153
|
+
} else if (value instanceof Date) {
|
|
154
|
+
v = value.toJSON();
|
|
155
|
+
} else {
|
|
156
|
+
v = value == null ? '' : `${value}`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return `${key}=${encodeURIComponent(v)}`;
|
|
160
|
+
})
|
|
161
|
+
.join('&');
|
|
162
|
+
|
|
163
|
+
return this.addUrlParams(params);
|
|
164
|
+
} else {
|
|
165
|
+
const urlObj = new URL(this);
|
|
166
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
167
|
+
if (Array.isArray(value)) {
|
|
168
|
+
if (arrayFormat == null || arrayFormat === false) {
|
|
169
|
+
value.forEach((item) => {
|
|
170
|
+
urlObj.searchParams.append(key, `${item}`);
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
urlObj.searchParams.append(
|
|
174
|
+
key,
|
|
175
|
+
value.join(arrayFormat ? ',' : arrayFormat)
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
} else if (value instanceof Date) {
|
|
179
|
+
urlObj.searchParams.append(key, value.toJSON());
|
|
180
|
+
} else {
|
|
181
|
+
urlObj.searchParams.append(
|
|
182
|
+
key,
|
|
183
|
+
`${value == null ? '' : value}`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
return urlObj.toString();
|
|
188
|
+
}
|
|
120
189
|
};
|
|
121
190
|
|
|
122
191
|
String.prototype.containChinese = function (this: string): boolean {
|
|
@@ -225,97 +294,6 @@ export namespace Utils {
|
|
|
225
294
|
return options;
|
|
226
295
|
}
|
|
227
296
|
|
|
228
|
-
/**
|
|
229
|
-
* Add parameter to URL
|
|
230
|
-
* @param url URL to add parameter
|
|
231
|
-
* @param name Parameter name
|
|
232
|
-
* @param value Parameter value
|
|
233
|
-
* @param arrayFormat Array format to array style or not to multiple fields
|
|
234
|
-
* @returns New URL
|
|
235
|
-
*/
|
|
236
|
-
export function addUrlParam(
|
|
237
|
-
url: string,
|
|
238
|
-
name: string,
|
|
239
|
-
value: DataTypes.Simple,
|
|
240
|
-
arrayFormat?: boolean | string
|
|
241
|
-
) {
|
|
242
|
-
return addUrlParams(url, { [name]: value }, arrayFormat);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Add parameters to URL
|
|
247
|
-
* @param url URL to add parameters
|
|
248
|
-
* @param data Parameters
|
|
249
|
-
* @param arrayFormat Array format to array style or not to multiple fields
|
|
250
|
-
* @returns New URL
|
|
251
|
-
*/
|
|
252
|
-
export function addUrlParams(
|
|
253
|
-
url: string,
|
|
254
|
-
data: DataTypes.SimpleObject,
|
|
255
|
-
arrayFormat?: boolean | string
|
|
256
|
-
) {
|
|
257
|
-
if (typeof URL === 'undefined') {
|
|
258
|
-
if (url.includes('?')) {
|
|
259
|
-
url += '&';
|
|
260
|
-
} else {
|
|
261
|
-
if (!url.endsWith('/')) url = url + '/';
|
|
262
|
-
url += '?';
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
url += Object.entries(data)
|
|
266
|
-
.map(([key, value]) => {
|
|
267
|
-
let v: string;
|
|
268
|
-
if (Array.isArray(value)) {
|
|
269
|
-
if (arrayFormat == null || arrayFormat === false) {
|
|
270
|
-
return value
|
|
271
|
-
.map(
|
|
272
|
-
(item) =>
|
|
273
|
-
`${key}=${encodeURIComponent(
|
|
274
|
-
`${item}`
|
|
275
|
-
)}`
|
|
276
|
-
)
|
|
277
|
-
.join('&');
|
|
278
|
-
} else {
|
|
279
|
-
v = value.join(arrayFormat ? ',' : arrayFormat);
|
|
280
|
-
}
|
|
281
|
-
} else if (value instanceof Date) {
|
|
282
|
-
v = value.toJSON();
|
|
283
|
-
} else {
|
|
284
|
-
v = value == null ? '' : `${value}`;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return `${key}=${encodeURIComponent(v)}`;
|
|
288
|
-
})
|
|
289
|
-
.join('&');
|
|
290
|
-
|
|
291
|
-
return url;
|
|
292
|
-
} else {
|
|
293
|
-
const urlObj = new URL(url);
|
|
294
|
-
Object.entries(data).forEach(([key, value]) => {
|
|
295
|
-
if (Array.isArray(value)) {
|
|
296
|
-
if (arrayFormat == null || arrayFormat === false) {
|
|
297
|
-
value.forEach((item) => {
|
|
298
|
-
urlObj.searchParams.append(key, `${item}`);
|
|
299
|
-
});
|
|
300
|
-
} else {
|
|
301
|
-
urlObj.searchParams.append(
|
|
302
|
-
key,
|
|
303
|
-
value.join(arrayFormat ? ',' : arrayFormat)
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
} else if (value instanceof Date) {
|
|
307
|
-
urlObj.searchParams.append(key, value.toJSON());
|
|
308
|
-
} else {
|
|
309
|
-
urlObj.searchParams.append(
|
|
310
|
-
key,
|
|
311
|
-
`${value == null ? '' : value}`
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
return urlObj.toString();
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
297
|
/**
|
|
320
298
|
* Base64 chars to number
|
|
321
299
|
* @param base64Chars Base64 chars
|