@kevisual/router 0.0.12 → 0.0.14
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/router-browser.d.ts +16 -1
- package/dist/router-browser.js +46 -1
- package/dist/router.d.ts +3 -0
- package/dist/router.js +4938 -18
- package/package.json +1 -1
- package/src/browser.ts +2 -0
- package/src/route.ts +3 -0
- package/src/server/parse-body.ts +17 -0
package/package.json
CHANGED
package/src/browser.ts
CHANGED
package/src/route.ts
CHANGED
|
@@ -592,6 +592,9 @@ export class QueryRouter {
|
|
|
592
592
|
return pick(r, pickValue as any);
|
|
593
593
|
});
|
|
594
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* 获取handle函数, 这里会去执行parse函数
|
|
597
|
+
*/
|
|
595
598
|
getHandle<T = any>(router: QueryRouter, wrapperFn?: HandleFn<T>, ctx?: RouteContext) {
|
|
596
599
|
return async (msg: { path: string; key?: string; [key: string]: any }, handleContext?: RouteContext) => {
|
|
597
600
|
try {
|
package/src/server/parse-body.ts
CHANGED
|
@@ -22,3 +22,20 @@ export const parseSearch = (req: IncomingMessage) => {
|
|
|
22
22
|
const parsedUrl = url.parse(req.url, true);
|
|
23
23
|
return parsedUrl.query;
|
|
24
24
|
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 把url当个key 的 value 的字符串转成json
|
|
28
|
+
* @param value
|
|
29
|
+
*/
|
|
30
|
+
export const parseSearchValue = (value?: string, opts?: { decode?: boolean }) => {
|
|
31
|
+
if (!value) return {};
|
|
32
|
+
const decode = opts?.decode ?? false;
|
|
33
|
+
if (decode) {
|
|
34
|
+
value = decodeURIComponent(value);
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(value);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
};
|