@cabloy/utils 1.0.9 → 1.0.10
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 +1 -0
- package/dist/utils.js +14 -0
- package/package.json +1 -1
package/dist/utils.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export declare function createFunction(expression: string, scopeKeys?: string[])
|
|
|
9
9
|
export declare function evaluateSimple(expression: string): any;
|
|
10
10
|
export declare function getRandomInt(size: number, start?: number): number;
|
|
11
11
|
export declare function combineQueries(pagePath?: string, queries?: Record<string, any>): string;
|
|
12
|
+
export declare function defaultPathSerializer(pathName: string, pathParams?: Record<string, any>): string;
|
package/dist/utils.js
CHANGED
|
@@ -125,3 +125,17 @@ export function combineQueries(pagePath, queries) {
|
|
|
125
125
|
return `${pagePath}${str}`;
|
|
126
126
|
return `${pagePath}&${str}`;
|
|
127
127
|
}
|
|
128
|
+
const PATH_PARAM_RE = /\{([^{}/]+)\}/g;
|
|
129
|
+
export function defaultPathSerializer(pathName, pathParams) {
|
|
130
|
+
pathParams = pathParams ?? {};
|
|
131
|
+
return pathName.replace(PATH_PARAM_RE, (_, _part) => {
|
|
132
|
+
if (_part.includes('?'))
|
|
133
|
+
_part = _part.substring(0, _part.length - 1);
|
|
134
|
+
const value = pathParams?.[_part];
|
|
135
|
+
if (value === undefined || value === null)
|
|
136
|
+
return '';
|
|
137
|
+
if (typeof value === 'object')
|
|
138
|
+
return encodeURIComponent(JSON.stringify(value));
|
|
139
|
+
return encodeURIComponent(value);
|
|
140
|
+
});
|
|
141
|
+
}
|