File tree Expand file tree Collapse file tree 1 file changed +24
-8
lines changed
src/templates/core/functions Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Original file line number Diff line number Diff line change 1
- function getQueryString(params: Record<string , any>): string {
2
- const qs: string[] = [];
1
+ const getQueryString = (params: Record<string , any>): string => {
2
+ const qs: string[] = [];
3
3
4
- const append = (key: string, value: any) => {
5
- qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
6
- };
4
+ const append = (key: string, value: any) => {
5
+ qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
6
+ };
7
+
8
+ const process = (key: string, value: any) => {
9
+ if (isDefined(value)) {
10
+ if (Array.isArray(value)) {
11
+ value.forEach(v => {
12
+ process(key, v);
13
+ });
14
+ } else if (typeof value === 'object') {
15
+ Object.entries(value).forEach(([k, v]) => {
16
+ process(`${key}[${k}]`, v);
17
+ });
18
+ } else {
19
+ append(key, value);
20
+ }
21
+ }
22
+ };
7
23
8
24
Object.entries(params)
9
25
.filter(([_, value]) => isDefined(value))
@@ -15,9 +31,9 @@ function getQueryString(params: Record<string, any>): string {
15
31
}
16
32
});
17
33
18
- if (qs.length > 0) {
19
- return `?${qs.join('& ')}`;
20
- }
34
+ if (qs.length > 0) {
35
+ return `?${qs.join('& ')}`;
36
+ }
21
37
22
38
return '';
23
39
}
You can’t perform that action at this time.
0 commit comments