@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@kevisual/router",
4
- "version": "0.0.12",
4
+ "version": "0.0.14",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
package/src/browser.ts CHANGED
@@ -7,3 +7,5 @@ export type { RouteContext, RouteOpts } from './route.ts';
7
7
  export type { Run } from './route.ts';
8
8
 
9
9
  export { CustomError } from './result/error.ts';
10
+
11
+ export * from './server/parse-body.ts';
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 {
@@ -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
+ };