@cabloy/utils 1.0.8 → 1.0.9

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/dist/utils.d.ts CHANGED
@@ -8,4 +8,4 @@ export declare function getPropertyObject<T>(obj: object, name: string, sep?: st
8
8
  export declare function createFunction(expression: string, scopeKeys?: string[]): Function;
9
9
  export declare function evaluateSimple(expression: string): any;
10
10
  export declare function getRandomInt(size: number, start?: number): number;
11
- export declare function combineQueries(url?: string, queries?: Record<string, any>): string;
11
+ export declare function combineQueries(pagePath?: string, queries?: Record<string, any>): string;
package/dist/utils.js CHANGED
@@ -90,27 +90,38 @@ export function evaluateSimple(expression) {
90
90
  export function getRandomInt(size, start = 0) {
91
91
  return Math.floor(Math.random() * size) + start;
92
92
  }
93
- export function combineQueries(url, queries) {
93
+ export function combineQueries(pagePath, queries) {
94
+ pagePath = pagePath ?? '/';
94
95
  //
95
96
  if (!queries)
96
- return url || '';
97
+ return pagePath;
97
98
  //
99
+ const query2 = [];
98
100
  const parts = [];
99
- for (const key of Object.keys(queries)) {
100
- parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(queries[key])}`);
101
+ if (queries) {
102
+ for (const key in queries) {
103
+ const value = queries[key];
104
+ if (value && typeof value === 'object') {
105
+ query2.push([key, value]);
106
+ }
107
+ else {
108
+ parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
109
+ }
110
+ }
111
+ }
112
+ // query2
113
+ for (const [key, value] of query2) {
114
+ parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value))}`);
101
115
  }
102
116
  if (parts.length === 0)
103
- return url || '';
117
+ return pagePath;
104
118
  //
105
119
  const str = parts.join('&');
106
120
  //
107
- if (!url)
108
- return `?${str}`;
109
- //
110
- const pos = url.indexOf('?');
121
+ const pos = pagePath.indexOf('?');
111
122
  if (pos === -1)
112
- return `${url}?${str}`;
113
- if (pos === url.length - 1)
114
- return `${url}${str}`;
115
- return `${url}&${str}`;
123
+ return `${pagePath}?${str}`;
124
+ if (pos === pagePath.length - 1)
125
+ return `${pagePath}${str}`;
126
+ return `${pagePath}&${str}`;
116
127
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cabloy/utils",
3
3
  "type": "module",
4
- "version": "1.0.8",
4
+ "version": "1.0.9",
5
5
  "description": "cabloy utils",
6
6
  "publishConfig": {
7
7
  "access": "public"